Class: Johnson::TraceMonkey::Runtime

Inherits:
Runtime
  • Object
show all
Defined in:
lib/johnson/tracemonkey/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

#[], #[]=, #current_stack, #delegate, #global, #load, new, #raise_js_exception, #require

Constructor Details

#initialize(options = {}) ⇒ Runtime

Returns a new instance of Runtime.



11
12
13
14
15
16
17
18
19
# File 'lib/johnson/tracemonkey/runtime.rb', line 11

def initialize(options={})
  @debugger = nil
  @gcthings = {}
  @traps = []
  size = (options[:size] || options["size"] || ENV["JOHNSON_HEAP_SIZE"] || 0x2000000).to_i
  options.delete(:size)
  initialize_native(size, options)
  super()
end

Instance Attribute Details

#trapsObject (readonly)

Returns the value of attribute traps.



10
11
12
# File 'lib/johnson/tracemonkey/runtime.rb', line 10

def traps
  @traps
end

Class Method Details

.parse_io(*args) ⇒ Object



66
67
68
# File 'lib/johnson/tracemonkey/runtime.rb', line 66

def parse_io *args
  Johnson::TraceMonkey::ImmutableNode.parse_io( *args )
end

Instance Method Details

#add_gcthing(thing) ⇒ Object

called from js_land_proxy.c:make_js_land_proxy



22
23
24
# File 'lib/johnson/tracemonkey/runtime.rb', line 22

def add_gcthing(thing)
  @gcthings[thing.object_id] = thing
end

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

Compile script with filename and linenum



58
59
60
61
62
# File 'lib/johnson/tracemonkey/runtime.rb', line 58

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

#current_contextObject

Raises:

  • (RuntimeError)


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

def current_context
  @thread_id ||= Thread.current.object_id
  raise RuntimeError, "Johnson is not thread safe" if @thread_id != Thread.current.object_id
  return @context ||= Context.new(self)
end

#debugger?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/johnson/tracemonkey/runtime.rb', line 31

def debugger?
  not @debugger.nil?
end

#evaluate(script, filename = nil, linenum = nil, global = nil, scope = nil) ⇒ Object



41
42
43
44
45
# File 'lib/johnson/tracemonkey/runtime.rb', line 41

def evaluate(script, filename = nil, linenum = nil, global=nil, scope=nil)
  return nil if script.nil?
  compiled_script = compile(script, filename, linenum, global)
  evaluate_compiled_script(compiled_script, scope)
end

#evaluate_compiled_script(script, scope = nil) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/johnson/tracemonkey/runtime.rb', line 48

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

#evaluate_compiled_script_without_clearing_trapsObject



47
# File 'lib/johnson/tracemonkey/runtime.rb', line 47

alias :evaluate_compiled_script_without_clearing_traps :evaluate_compiled_script

#remove_gcthing(object_id) ⇒ Object

called from js_land_proxy.c:finalize



27
28
29
# File 'lib/johnson/tracemonkey/runtime.rb', line 27

def remove_gcthing(object_id)
  @gcthings.delete(object_id) if defined? @gcthings
end

#versionObject



4
5
6
# File 'lib/johnson/tracemonkey/runtime.rb', line 4

def version
  TraceMonkey::VERSION
end