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
block
infilename
atlinenum
. -
#compile(script, filename = nil, linenum = nil) ⇒ Object
Compile
script
withfilename
andlinenum
. - #current_context ⇒ Object
-
#evaluate(script, filename = nil, linenum = nil) ⇒ Object
Evaluate
script
withfilename
andlinenum
. - #evaluate_compiled(script) ⇒ Object
-
#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 13 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 6 def initialize(={}) @debugger = nil @compiled_scripts = {} @gcthings = {} @traps = [] initialize_native() self["Ruby"] = Object end |
Class Method Details
.raise_js_exception(jsex) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 72 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("#{} 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
31 32 33 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 31 def [](key) global[key] end |
#[]=(key, value) ⇒ Object
35 36 37 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 35 def []=(key, value) global[key] = value end |
#add_gcthing(thing) ⇒ Object
called from js_land_proxy.c:make_js_land_proxy
16 17 18 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 16 def add_gcthing(thing) @gcthings[thing.object_id] = thing end |
#break(filename, linenum, &block) ⇒ Object
Yield to block
in filename
at linenum
63 64 65 66 67 68 69 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 63 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) @traps << [compiled_script, linenum] end |
#compile(script, filename = nil, linenum = nil) ⇒ Object
Compile script
with filename
and linenum
55 56 57 58 59 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 55 def compile(script, filename=nil, linenum=nil) filename ||= 'none' linenum ||= 1 @compiled_scripts[filename] = native_compile(script, filename, linenum) end |
#current_context ⇒ Object
26 27 28 29 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 26 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
41 42 43 44 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 41 def evaluate(script, filename = nil, linenum = nil) compiled_script = compile(script, filename, linenum) evaluate_compiled_script(compiled_script) end |
#evaluate_compiled(script) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 46 def evaluate_compiled script evaluate_compiled_script(script) @traps.each do |trap_tuple| clear_trap(*trap_tuple) end end |
#remove_gcthing(object_id) ⇒ Object
called from js_land_proxy.c:finalize
21 22 23 |
# File 'lib/johnson/spidermonkey/runtime.rb', line 21 def remove_gcthing(object_id) @gcthings.delete(object_id) if defined? @gcthings end |