Class: ExecJS::MiniRacerRuntime::Context
- Inherits:
-
Runtime::Context
- Object
- Runtime::Context
- ExecJS::MiniRacerRuntime::Context
- Defined in:
- lib/execjs/mini_racer_runtime.rb
Instance Method Summary collapse
- #call(identifier, *args) ⇒ Object
- #eval(source, options = {}) ⇒ Object
- #exec(source, options = {}) ⇒ Object
-
#initialize(runtime, source = "", options = {}) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(runtime, source = "", options = {}) ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 12 13 |
# File 'lib/execjs/mini_racer_runtime.rb', line 6 def initialize(runtime, source = "", ={}) source = source.encode(Encoding::UTF_8) @context = ::MiniRacer::Context.new @context.eval("delete this.console"); translate do @context.eval(source) end end |
Instance Method Details
#call(identifier, *args) ⇒ Object
33 34 35 36 |
# File 'lib/execjs/mini_racer_runtime.rb', line 33 def call(identifier, *args) # TODO optimise generate eval "#{identifier}.apply(this, #{::JSON.generate(args)})" end |
#eval(source, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/execjs/mini_racer_runtime.rb', line 23 def eval(source, = {}) source = source.encode(Encoding::UTF_8) if /\S/ =~ source translate do @context.eval("(#{source})") end end end |
#exec(source, options = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/execjs/mini_racer_runtime.rb', line 15 def exec(source, = {}) source = source.encode(Encoding::UTF_8) if /\S/ =~ source eval "(function(){#{source}})()" end end |