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.
- #permissive? ⇒ Boolean
- #permissive_eval(source, options = {}) ⇒ Object
- #permissive_exec(source, options = {}) ⇒ Object
- #raw_exec(source) ⇒ Object
- #raw_execp(source) ⇒ Object
Constructor Details
#initialize(runtime, source = "", options = {}) ⇒ Context
Returns a new instance of Context.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 102 def initialize(runtime, source = "", = {}) @runtime = runtime @uuid = SecureRandom.uuid @permissive = !![:permissive] ObjectSpace.define_finalizer(self, self.class.finalize(@runtime, @uuid)) begin source = encode(source) rescue source = source.force_encoding('UTF-8') end @permissive ? raw_execp(source) : raw_exec(source) end |
Class Method Details
.finalize(runtime, uuid) ⇒ Object
118 119 120 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 118 def self.finalize(runtime, uuid) proc { runtime.vm.delete_context(uuid) } end |
Instance Method Details
#call(identifier, *args) ⇒ Object
122 123 124 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 122 def call(identifier, *args) eval "#{identifier}.apply(this, #{::Oj.dump(args)})" end |
#eval(source, options = {}) ⇒ Object
126 127 128 129 130 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 126 def eval(source, = {}) if /\S/ =~ source raw_exec("(#{source})") end end |
#exec(source, options = {}) ⇒ Object
132 133 134 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 132 def exec(source, = {}) raw_exec("(function(){#{source}})()") end |
#permissive? ⇒ Boolean
136 137 138 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 136 def permissive? @permissive end |
#permissive_eval(source, options = {}) ⇒ Object
140 141 142 143 144 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 140 def permissive_eval(source, = {}) if /\S/ =~ source raw_execp("(#{source})") end end |
#permissive_exec(source, options = {}) ⇒ Object
146 147 148 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 146 def permissive_exec(source, = {}) raw_execp("(function(){#{source}})()") end |
#raw_exec(source) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 150 def raw_exec(source) source = encode(source) result = @runtime.vm.exec(@uuid, source) extract_result(result) end |
#raw_execp(source) ⇒ Object
157 158 159 160 161 162 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 157 def raw_execp(source) source = encode(source) result = @runtime.vm.execp(@uuid, source) extract_result(result) end |