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.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 93 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
109 110 111 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 109 def self.finalize(runtime, uuid) proc { runtime.vm.delete_context(uuid) } end |
Instance Method Details
#call(identifier, *args) ⇒ Object
113 114 115 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 113 def call(identifier, *args) eval "#{identifier}.apply(this, #{::Oj.dump(args)})" end |
#eval(source, options = {}) ⇒ Object
117 118 119 120 121 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 117 def eval(source, = {}) if /\S/ =~ source raw_exec("(#{source})") end end |
#exec(source, options = {}) ⇒ Object
123 124 125 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 123 def exec(source, = {}) raw_exec("(function(){#{source}})()") end |
#permissive? ⇒ Boolean
127 128 129 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 127 def permissive? @permissive end |
#permissive_eval(source, options = {}) ⇒ Object
131 132 133 134 135 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 131 def permissive_eval(source, = {}) if /\S/ =~ source raw_execp("(#{source})") end end |
#permissive_exec(source, options = {}) ⇒ Object
137 138 139 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 137 def permissive_exec(source, = {}) raw_execp("(function(){#{source}})()") end |
#raw_exec(source) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 141 def raw_exec(source) source = encode(source) result = @runtime.vm.exec(@uuid, source) extract_result(result) end |
#raw_execp(source) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/isomorfeus/speednode/runtime.rb', line 148 def raw_execp(source) source = encode(source) result = @runtime.vm.execp(@uuid, source) extract_result(result) end |