Class: ExecJS::RubyRhinoRuntime::Context
- Inherits:
-
Object
- Object
- ExecJS::RubyRhinoRuntime::Context
- Defined in:
- lib/execjs/ruby_rhino_runtime.rb
Instance Method Summary collapse
- #call(properties, *args) ⇒ Object
- #eval(source, options = {}) ⇒ Object
- #exec(source, options = {}) ⇒ Object
-
#initialize(source = "") ⇒ Context
constructor
A new instance of Context.
- #unbox(value) ⇒ Object
Constructor Details
#initialize(source = "") ⇒ Context
Returns a new instance of Context.
4 5 6 7 |
# File 'lib/execjs/ruby_rhino_runtime.rb', line 4 def initialize(source = "") @rhino_context = ::Rhino::Context.new @rhino_context.eval(source) end |
Instance Method Details
#call(properties, *args) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/execjs/ruby_rhino_runtime.rb', line 27 def call(properties, *args) unbox @rhino_context.eval(properties).call(*args) rescue ::Rhino::JavascriptError => e if e. == "syntax error" raise RuntimeError, e else raise ProgramError, e end end |
#eval(source, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/execjs/ruby_rhino_runtime.rb', line 15 def eval(source, = {}) if /\S/ =~ source unbox @rhino_context.eval("(#{source})") end rescue ::Rhino::JavascriptError => e if e. == "syntax error" raise RuntimeError, e else raise ProgramError, e end end |
#exec(source, options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/execjs/ruby_rhino_runtime.rb', line 9 def exec(source, = {}) if /\S/ =~ source eval "(function(){#{source}})()", end end |
#unbox(value) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/execjs/ruby_rhino_runtime.rb', line 37 def unbox(value) case value when ::Rhino::NativeFunction nil when ::Rhino::NativeObject value.inject({}) do |vs, (k, v)| vs[k] = unbox(v) unless v.is_a?(::Rhino::NativeFunction) vs end else value end end |