Class: ExecJS::FastNode::ExternalPipedRuntime::Context
- Inherits:
-
Runtime::Context
- Object
- Runtime::Context
- ExecJS::FastNode::ExternalPipedRuntime::Context
- Defined in:
- lib/execjs/fastnode/external_piped_runtime.rb
Class Method Summary collapse
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.
- #raw_exec(source, options = {}) ⇒ Object
Constructor Details
#initialize(runtime, source = "", options = {}) ⇒ Context
Returns a new instance of Context.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 62 def initialize(runtime, source = "", = {}) @runtime = runtime @uuid = SecureRandom.uuid ObjectSpace.define_finalizer(self, self.class.finalize(@runtime, @uuid)) source = encode(source) raw_exec(source) end |
Class Method Details
.finalize(runtime, uuid) ⇒ Object
73 74 75 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 73 def self.finalize(runtime, uuid) proc { runtime.vm.delete_context(uuid) } end |
Instance Method Details
#call(identifier, *args) ⇒ Object
94 95 96 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 94 def call(identifier, *args) eval "#{identifier}.apply(this, #{::JSON.generate(args)})" end |
#eval(source, options = {}) ⇒ Object
77 78 79 80 81 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 77 def eval(source, = {}) if /\S/ =~ source raw_exec("(#{source})") end end |
#exec(source, options = {}) ⇒ Object
83 84 85 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 83 def exec(source, = {}) raw_exec("(function(){#{source}})()") end |
#raw_exec(source, options = {}) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 87 def raw_exec(source, = {}) source = encode(source) result = @runtime.vm.exec(@uuid, source) extract_result(result) end |