Class: Johnson::SpiderMonkey::Runtime
- Inherits:
-
Object
- Object
- Johnson::SpiderMonkey::Runtime
- Defined in:
- lib/johnson/spidermonkey/runtime.rb
Overview
native
Constant Summary collapse
- CONTEXT_MAP_KEY =
:johnson_context_map
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#add_gcthing(thing) ⇒ Object
called from js_land_proxy.c:make_js_land_proxy.
-
#break(filename, linenum, &block) ⇒ Object
Yield to
blockinfilenameatlinenum. -
#compile(script, filename = nil, linenum = nil) ⇒ Object
Compile
scriptwithfilenameandlinenum. - #current_context ⇒ Object
-
#evaluate(script, filename = nil, linenum = nil) ⇒ Object
Evaluate
scriptwithfilenameandlinenum. -
#initialize(options = {}) ⇒ Runtime
constructor
A new instance of Runtime.
-
#remove_gcthing(object_id) ⇒ Object
called from js_land_proxy.c:finalize.
Constructor Details
#initialize(options = {}) ⇒ Runtime
Returns a new instance of Runtime.
6 7 8 9 10 11 12 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 6 def initialize(={}) @debugger = nil @compiled_scripts = {} @gcthings = {} initialize_native() self["Ruby"] = Object end |
Class Method Details
.raise_js_exception(jsex) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 63 def raise_js_exception(jsex) raise jsex if Exception === jsex raise Johnson::Error.new(jsex.to_s) unless Johnson::SpiderMonkey::RubyLandProxy === jsex stack = jsex.stack rescue nil = jsex['message'] || jsex.to_s at = "(#{jsex['fileName']}):#{jsex['lineNumber']}" ex = Johnson::Error.new("#{message} at #{at}") if stack js_caller = stack.split("\n").find_all { |x| x != '@:0' } ex.set_backtrace(js_caller + caller) else ex.set_backtrace(caller) end raise ex end |
Instance Method Details
#[](key) ⇒ Object
30 31 32 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 30 def [](key) global[key] end |
#[]=(key, value) ⇒ Object
34 35 36 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 34 def []=(key, value) global[key] = value end |
#add_gcthing(thing) ⇒ Object
called from js_land_proxy.c:make_js_land_proxy
15 16 17 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 15 def add_gcthing(thing) @gcthings[thing.object_id] = thing end |
#break(filename, linenum, &block) ⇒ Object
Yield to block in filename at linenum
55 56 57 58 59 60 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 55 def break(filename, linenum, &block) raise "#{filename} has not been compiled" unless @compiled_scripts.key?(filename) compiled_script = @compiled_scripts[filename] set_trap(compiled_script, linenum, block) end |
#compile(script, filename = nil, linenum = nil) ⇒ Object
Compile script with filename and linenum
47 48 49 50 51 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 47 def compile(script, filename=nil, linenum=nil) filename ||= 'none' linenum ||= 1 @compiled_scripts[filename] = native_compile(script, filename, linenum) end |
#current_context ⇒ Object
25 26 27 28 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 25 def current_context contexts = (Thread.current[CONTEXT_MAP_KEY] ||= {}) contexts[self.object_id] ||= Context.new(self) end |
#evaluate(script, filename = nil, linenum = nil) ⇒ Object
Evaluate script with filename and linenum
40 41 42 43 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 40 def evaluate(script, filename = nil, linenum = nil) compiled_script = compile(script, filename, linenum) evaluate_compiled_script(compiled_script) end |
#remove_gcthing(object_id) ⇒ Object
called from js_land_proxy.c:finalize
20 21 22 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 20 def remove_gcthing(object_id) @gcthings.delete(object_id) if defined? @gcthings end |