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 = "", options = {}) ⇒ Context
constructor
A new instance of Context.
- #unbox(value) ⇒ Object
Methods included from Encoding
Constructor Details
#initialize(runtime, source = "", options = {}) ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 6 def initialize(runtime, source = "", = {}) source = encode(source) lock do @v8_context = ::V8::Context.new begin @v8_context.eval(source) rescue ::V8::JSError => e raise wrap_error(e) end end end |
Instance Method Details
#call(properties, *args) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 42 def call(properties, *args) lock do begin unbox @v8_context.eval(properties).call(*args) rescue ::V8::JSError => e raise wrap_error(e) end end end |
#eval(source, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 28 def eval(source, = {}) source = encode(source) if /\S/ =~ source lock do begin unbox @v8_context.eval("(#{source})") rescue ::V8::JSError => e raise wrap_error(e) end end end end |
#exec(source, options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 20 def exec(source, = {}) source = encode(source) if /\S/ =~ source eval "(function(){#{source}})()", end end |
#unbox(value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/execjs/ruby_racer_runtime.rb', line 52 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 |