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.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 115 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
126 127 128 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 126 def self.finalize(runtime, uuid) proc { runtime.vm.delete_context(uuid) } end |
Instance Method Details
#call(identifier, *args) ⇒ Object
147 148 149 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 147 def call(identifier, *args) eval "#{identifier}.apply(this, #{::JSON.generate(args)})" end |
#eval(source, options = {}) ⇒ Object
130 131 132 133 134 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 130 def eval(source, = {}) if /\S/ =~ source raw_exec("(#{source})") end end |
#exec(source, options = {}) ⇒ Object
136 137 138 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 136 def exec(source, = {}) raw_exec("(function(){#{source}})()") end |
#raw_exec(source, options = {}) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/execjs/fastnode/external_piped_runtime.rb', line 140 def raw_exec(source, = {}) source = encode(source) result = @runtime.vm.exec(@uuid, source) extract_result(result) end |