Class: ExecJS::RubyRacerRuntime::Context
- Inherits:
-
ExecJS::Runtime::Context
- Object
- ExecJS::Runtime::Context
- ExecJS::RubyRacerRuntime::Context
- Defined in:
- lib/execjs/ruby_racer_runtime.rb
Instance Method Summary collapse
- #call(properties, *args) ⇒ Object
- #eval(source, options = {}) ⇒ Object
- #exec(source, options = {}) ⇒ Object
-
#initialize(runtime, source = "") ⇒ Context
constructor
A new instance of Context.
- #unbox(value) ⇒ Object
Methods included from Encoding
Constructor Details
permalink #initialize(runtime, source = "") ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 12 13 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 6 def initialize(runtime, source = "") source = encode(source) lock do @v8_context = ::V8::Context.new @v8_context.eval(source) end end |
Instance Method Details
permalink #call(properties, *args) ⇒ Object
[View source]
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 41 def call(properties, *args) lock do begin unbox @v8_context.eval(properties).call(*args) rescue ::V8::JSError => e if e.value["name"] == "SyntaxError" raise RuntimeError, e.value.to_s else raise ProgramError, e.value.to_s end end end end |
permalink #eval(source, options = {}) ⇒ Object
[View source]
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 23 def eval(source, = {}) source = encode(source) if /\S/ =~ source lock do begin unbox @v8_context.eval("(#{source})") rescue ::V8::JSError => e if e.value["name"] == "SyntaxError" raise RuntimeError, e.value.to_s else raise ProgramError, e.value.to_s end end end end end |
permalink #exec(source, options = {}) ⇒ Object
[View source]
15 16 17 18 19 20 21 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 15 def exec(source, = {}) source = encode(source) if /\S/ =~ source eval "(function(){#{source}})()", end end |
permalink #unbox(value) ⇒ Object
[View source]
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 55 def unbox(value) case value when ::V8::Function nil when ::V8::Array value.map { |v| unbox(v) } when ::V8::Object value.inject({}) do |vs, (k, v)| vs[k] = unbox(v) unless v.is_a?(::V8::Function) vs end when String value.force_encoding('UTF-8') else value end end |