Class: ExecJS::ExternalRuntime::Context
- Inherits:
-
Runtime::Context
- Object
- Runtime::Context
- ExecJS::ExternalRuntime::Context
- Defined in:
- lib/execjs/external_runtime.rb
Instance Method Summary collapse
- #call(identifier, *args) ⇒ Object
- #eval(source, options = {}) ⇒ Object
- #exec(source, options = {}) ⇒ Object
-
#initialize(runtime, source = "") ⇒ Context
constructor
A new instance of Context.
Methods included from ExecJS::Encoding
Constructor Details
#initialize(runtime, source = "") ⇒ Context
Returns a new instance of Context.
7 8 9 10 11 12 |
# File 'lib/execjs/external_runtime.rb', line 7 def initialize(runtime, source = "") source = encode(source) @runtime = runtime @source = source end |
Instance Method Details
#call(identifier, *args) ⇒ Object
35 36 37 |
# File 'lib/execjs/external_runtime.rb', line 35 def call(identifier, *args) eval "#{identifier}.apply(this, #{::JSON.generate(args)})" end |
#eval(source, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/execjs/external_runtime.rb', line 14 def eval(source, = {}) source = encode(source) if /\S/ =~ source exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})") end end |
#exec(source, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/execjs/external_runtime.rb', line 22 def exec(source, = {}) source = encode(source) source = "#{@source}\n#{source}" if @source source = @runtime.compile_source(source) tmpfile = write_to_tempfile(source) begin extract_result(@runtime.exec_runtime(tmpfile.path)) ensure File.unlink(tmpfile) end end |