Class: Johnson::SpiderMonkey::Runtime

Inherits:
Runtime
  • Object
show all
Defined in:
lib/johnson/spidermonkey/runtime.rb

Overview

native

Constant Summary collapse

CONTEXT_MAP_KEY =
:johnson_context_map

Constants inherited from Runtime

Runtime::CORE, Runtime::CORE_PATH, Runtime::PRELUDE, Runtime::PRELUDE_PATH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runtime

#[], #[]=, #delegate, #evaluate, #global, #load, new, #require

Constructor Details

#initialize(options = {}) ⇒ Runtime

Returns a new instance of Runtime.



7
8
9
10
11
12
13
# File 'lib/johnson/spidermonkey/runtime.rb', line 7

def initialize(options={})
  @debugger = nil
  @gcthings = {}
  @traps = []
  initialize_native(options)
  super()
end

Instance Attribute Details

#trapsObject (readonly)

Returns the value of attribute traps.



6
7
8
# File 'lib/johnson/spidermonkey/runtime.rb', line 6

def traps
  @traps
end

Class Method Details

.raise_js_exception(jsex) ⇒ Object

Raises:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/johnson/spidermonkey/runtime.rb', line 52

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

  message = 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

#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

#compile(script, filename = nil, linenum = nil) ⇒ Object

Compile script with filename and linenum



45
46
47
48
49
# File 'lib/johnson/spidermonkey/runtime.rb', line 45

def compile(script, filename=nil, linenum=nil)
  filename ||= 'none'
  linenum  ||= 1
  native_compile(script, filename, linenum)
end

#current_contextObject



29
30
31
32
# File 'lib/johnson/spidermonkey/runtime.rb', line 29

def current_context
  contexts = (Thread.current[CONTEXT_MAP_KEY] ||= {})
  contexts[self.object_id] ||= Context.new(self)
end

#debugger?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/johnson/spidermonkey/runtime.rb', line 25

def debugger?
  not @debugger.nil?
end

#evaluate_compiled_script(script) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/johnson/spidermonkey/runtime.rb', line 35

def evaluate_compiled_script script
  evaluate_compiled_script_without_clearing_traps(script)
ensure
  @traps.each do |trap_tuple|
    clear_trap(*trap_tuple)
  end
end

#evaluate_compiled_script_without_clearing_trapsObject



34
# File 'lib/johnson/spidermonkey/runtime.rb', line 34

alias :evaluate_compiled_script_without_clearing_traps :evaluate_compiled_script

#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