Class: ExecJS::ExternalRuntime::Context
- Inherits:
-
Object
- Object
- 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.
Constructor Details
#initialize(runtime, source = "") ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 |
# File 'lib/execjs/external_runtime.rb', line 6 def initialize(runtime, source = "") source = source.encode('UTF-8') if source.respond_to?(:encode) @runtime = runtime @source = source end |
Instance Method Details
#call(identifier, *args) ⇒ Object
29 30 31 |
# File 'lib/execjs/external_runtime.rb', line 29 def call(identifier, *args) eval "#{identifier}.apply(this, #{MultiJson.encode(args)})" end |
#eval(source, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/execjs/external_runtime.rb', line 13 def eval(source, = {}) source = source.encode('UTF-8') if source.respond_to?(:encode) if /\S/ =~ source exec("return eval(#{MultiJson.encode("(#{source})")})") end end |
#exec(source, options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/execjs/external_runtime.rb', line 21 def exec(source, = {}) source = source.encode('UTF-8') if source.respond_to?(:encode) compile_to_tempfile([@source, source].join("\n")) do |file| extract_result(@runtime.send(:exec_runtime, file.path)) end end |