Class: Isomorfeus::Speednode::Runtime::Context
- Inherits:
-
ExecJS::Runtime::Context
- Object
- ExecJS::Runtime::Context
- Isomorfeus::Speednode::Runtime::Context
- Defined in:
- lib/isomorfeus/speednode/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.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 89 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
100 101 102 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 100 def self.finalize(runtime, uuid) proc { runtime.vm.delete_context(uuid) } end |
Instance Method Details
#call(identifier, *args) ⇒ Object
121 122 123 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 121 def call(identifier, *args) eval "#{identifier}.apply(this, #{::Oj.dump(args)})" end |
#eval(source, options = {}) ⇒ Object
104 105 106 107 108 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 104 def eval(source, = {}) if /\S/ =~ source raw_exec("(#{source})") end end |
#exec(source, options = {}) ⇒ Object
110 111 112 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 110 def exec(source, = {}) raw_exec("(function(){#{source}})()") end |
#raw_exec(source, options = {}) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 114 def raw_exec(source, = {}) source = encode(source) result = @runtime.vm.exec(@uuid, source) extract_result(result) end |