Class: Johnson::Runtime

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate = Johnson::SpiderMonkey::Runtime) ⇒ Runtime

Returns a new instance of Runtime.



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

def initialize(delegate=Johnson::SpiderMonkey::Runtime)
  @delegate = delegate.is_a?(Class) ? delegate.new : delegate
  evaluate(Johnson::PRELUDE, "Johnson::PRELUDE", 1)
  global.Johnson.runtime = self
end

Instance Attribute Details

#delegateObject (readonly)

Returns the value of attribute delegate.



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

def delegate
  @delegate
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  delegate[key.to_s]
end

#[]=(key, value) ⇒ Object



15
16
17
# File 'lib/johnson/runtime.rb', line 15

def []=(key, value)
  delegate[key.to_s] = value
end

#break(filename, linenum, &block) ⇒ Object

Yield to block in filename at linenum



48
49
50
# File 'lib/johnson/runtime.rb', line 48

def break(filename, linenum, &block)
  delegate.break(filename, linenum, &block)
end

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

Compile script with filename and linenum



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

def compile(script, filename=nil, linenum=nil)
  delegate.compile(script, filename, linenum)
end

#evaluate(expression, filename = nil, linenum = nil) ⇒ Object



19
20
21
22
# File 'lib/johnson/runtime.rb', line 19

def evaluate(expression, filename=nil, linenum=nil)
  return nil if expression.nil?
  delegate.evaluate(expression, filename, linenum)
end

#evaluate_compiled_script(script) ⇒ Object



52
53
54
# File 'lib/johnson/runtime.rb', line 52

def evaluate_compiled_script(script)
  delegate.evaluate_compiled(script)
end

#globalObject



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

def global
  delegate.global
end

#load(*files) ⇒ Object



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

def load(*files)
  files.map { |f| delegate.evaluate(File.read(f).gsub(/\A#!.*$/, ''), f, 1) }.last
end

#require(*files) ⇒ Object

Johnson.require on each file in files



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

def require(*files)
  files.each do |file|
    evaluate("Johnson.require('#{file}');")
  end
end