mini_racer_rs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/AI-DISCLOSURE.md +13 -0
- data/CHANGELOG.md +45 -0
- data/COMPATIBILITY.md +235 -0
- data/Cargo.lock +1263 -0
- data/Cargo.toml +62 -0
- data/LICENSE +21 -0
- data/README.md +254 -0
- data/THIRD_PARTY_NOTICES.md +4501 -0
- data/crates/mini_racer_engine/Cargo.toml +25 -0
- data/crates/mini_racer_engine/build.rs +13 -0
- data/crates/mini_racer_engine/src/context.rs +802 -0
- data/crates/mini_racer_engine/src/control.rs +239 -0
- data/crates/mini_racer_engine/src/error.rs +88 -0
- data/crates/mini_racer_engine/src/fast_calls.rs +681 -0
- data/crates/mini_racer_engine/src/lib.rs +20 -0
- data/crates/mini_racer_engine/src/notify.rs +107 -0
- data/crates/mini_racer_engine/src/process/code_cache.rs +412 -0
- data/crates/mini_racer_engine/src/process/fork.rs +261 -0
- data/crates/mini_racer_engine/src/process/platform.rs +194 -0
- data/crates/mini_racer_engine/src/process/tasks.rs +96 -0
- data/crates/mini_racer_engine/src/process/watchdog.rs +185 -0
- data/crates/mini_racer_engine/src/process/workers.rs +165 -0
- data/crates/mini_racer_engine/src/process.rs +69 -0
- data/crates/mini_racer_engine/src/runner.rs +1560 -0
- data/crates/mini_racer_engine/src/serialize.rs +253 -0
- data/crates/mini_racer_engine/src/snapshot.rs +221 -0
- data/crates/mini_racer_engine/src/spin.rs +23 -0
- data/crates/mini_racer_engine/src/sys.rs +566 -0
- data/crates/mini_racer_sync/Cargo.toml +18 -0
- data/crates/mini_racer_sync/src/channel.rs +621 -0
- data/crates/mini_racer_sync/src/fork.rs +116 -0
- data/crates/mini_racer_sync/src/lib.rs +20 -0
- data/crates/mini_racer_sync/src/lock.rs +49 -0
- data/crates/mini_racer_sync/src/parker.rs +44 -0
- data/crates/mini_racer_sync/src/primitives.rs +10 -0
- data/crates/mini_racer_sync/src/tasks.rs +345 -0
- data/crates/mini_racer_sync/src/termination.rs +1234 -0
- data/crates/mini_racer_sync/src/workers.rs +283 -0
- data/crates/mini_racer_wire/Cargo.toml +18 -0
- data/crates/mini_racer_wire/src/decode.rs +926 -0
- data/crates/mini_racer_wire/src/lib.rs +67 -0
- data/crates/mini_racer_wire/src/marker.rs +43 -0
- data/crates/mini_racer_wire/src/text.rs +106 -0
- data/crates/mini_racer_wire/src/write.rs +187 -0
- data/ext/mini_racer_rs/Cargo.toml +26 -0
- data/ext/mini_racer_rs/build.rs +16 -0
- data/ext/mini_racer_rs/extconf.rb +78 -0
- data/ext/mini_racer_rs/src/context.rs +485 -0
- data/ext/mini_racer_rs/src/decode.rs +450 -0
- data/ext/mini_racer_rs/src/encode.rs +333 -0
- data/ext/mini_racer_rs/src/errors.rs +156 -0
- data/ext/mini_racer_rs/src/fork.rs +31 -0
- data/ext/mini_racer_rs/src/gc_root.rs +117 -0
- data/ext/mini_racer_rs/src/guard.rs +7 -0
- data/ext/mini_racer_rs/src/host.rs +339 -0
- data/ext/mini_racer_rs/src/lib.rs +44 -0
- data/ext/mini_racer_rs/src/options.rs +269 -0
- data/ext/mini_racer_rs/src/platform.rs +42 -0
- data/ext/mini_racer_rs/src/rb_raw.rs +368 -0
- data/ext/mini_racer_rs/src/snapshot.rs +149 -0
- data/ext/mini_racer_rs/v8-archives.sha256 +8 -0
- data/lib/mini_racer/shared.rb +420 -0
- data/lib/mini_racer/truffleruby.rb +439 -0
- data/lib/mini_racer/version.rb +6 -0
- data/lib/mini_racer.rb +3 -0
- data/lib/mini_racer_rs/internal_error.rb +7 -0
- data/lib/mini_racer_rs/version.rb +5 -0
- data/lib/mini_racer_rs/vocabulary.rb +105 -0
- data/lib/mini_racer_rs.rb +33 -0
- data/licenses/mini_racer.txt +21 -0
- data/licenses/rust/SOURCES.tsv +6 -0
- data/licenses/rust/std/COPYRIGHT +34 -0
- data/licenses/rust/std/COPYRIGHT-library.html +29357 -0
- data/licenses/rust/std/LICENSE-APACHE +176 -0
- data/licenses/rust/std/LICENSE-MIT +25 -0
- data/licenses/v8/SOURCES.tsv +20 -0
- data/licenses/v8/abseil-cpp/LICENSE +203 -0
- data/licenses/v8/chromium-build/LICENSE +27 -0
- data/licenses/v8/components.tsv +29 -0
- data/licenses/v8/dragonbox/LICENSE-Boost +23 -0
- data/licenses/v8/fast_float/LICENSE-MIT +27 -0
- data/licenses/v8/highway/LICENSE +371 -0
- data/licenses/v8/icu/LICENSE +568 -0
- data/licenses/v8/inspector_protocol/LICENSE +27 -0
- data/licenses/v8/libc++/LICENSE.TXT +311 -0
- data/licenses/v8/libc++abi/LICENSE.TXT +311 -0
- data/licenses/v8/llvm-libc/LICENSE.TXT +278 -0
- data/licenses/v8/rapidhash/LICENSE +34 -0
- data/licenses/v8/simdutf/LICENSE +18 -0
- data/licenses/v8/siphash/LICENSE +116 -0
- data/licenses/v8/utf8-decoder/LICENSE +19 -0
- data/licenses/v8/v8/LICENSE +61 -0
- data/licenses/v8/v8/LICENSE.fdlibm +6 -0
- data/licenses/v8/v8/LICENSE.strongtalk +29 -0
- data/licenses/v8/v8/LICENSE.v8 +26 -0
- metadata +156 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "shared"
|
|
4
|
+
|
|
5
|
+
module MiniRacer
|
|
6
|
+
class Context
|
|
7
|
+
class ExternalFunction
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def notify_v8
|
|
11
|
+
name = @name.encode(::Encoding::UTF_8)
|
|
12
|
+
wrapped =
|
|
13
|
+
lambda do |*args|
|
|
14
|
+
converted = @parent.send(:convert_js_to_ruby, args)
|
|
15
|
+
begin
|
|
16
|
+
result = @callback.call(*converted)
|
|
17
|
+
rescue Polyglot::ForeignException => e
|
|
18
|
+
e = RuntimeError.new(e.message)
|
|
19
|
+
e.set_backtrace(e.backtrace)
|
|
20
|
+
@parent.instance_variable_set(:@current_exception, e)
|
|
21
|
+
raise e
|
|
22
|
+
rescue => e
|
|
23
|
+
@parent.instance_variable_set(:@current_exception, e)
|
|
24
|
+
raise e
|
|
25
|
+
end
|
|
26
|
+
@parent.send(:convert_ruby_to_js, result)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
if @parent_object.nil?
|
|
30
|
+
# set global name to proc
|
|
31
|
+
result = @parent.eval_in_context("this")
|
|
32
|
+
result[name] = wrapped
|
|
33
|
+
else
|
|
34
|
+
parent_object_eval = @parent_object_eval.encode(::Encoding::UTF_8)
|
|
35
|
+
begin
|
|
36
|
+
result = @parent.eval_in_context(parent_object_eval)
|
|
37
|
+
rescue Polyglot::ForeignException, StandardError => e
|
|
38
|
+
raise ParseError,
|
|
39
|
+
"Was expecting #{@parent_object} to be an object",
|
|
40
|
+
e.backtrace
|
|
41
|
+
end
|
|
42
|
+
result[name] = wrapped
|
|
43
|
+
# set evaluated object results name to proc
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def heap_stats
|
|
49
|
+
raise ContextDisposedError if @disposed
|
|
50
|
+
{
|
|
51
|
+
total_physical_size: 0,
|
|
52
|
+
total_heap_size_executable: 0,
|
|
53
|
+
total_heap_size: 0,
|
|
54
|
+
used_heap_size: 0,
|
|
55
|
+
heap_size_limit: 0
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def stop
|
|
60
|
+
if @entered
|
|
61
|
+
@context.stop
|
|
62
|
+
@stopped = true
|
|
63
|
+
stop_attached
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def low_memory_notification
|
|
68
|
+
GC.start
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
@context_initialized = false
|
|
74
|
+
@use_strict = false
|
|
75
|
+
|
|
76
|
+
def init_unsafe(isolate, snapshot)
|
|
77
|
+
unless defined?(Polyglot::InnerContext)
|
|
78
|
+
raise "TruffleRuby #{RUBY_ENGINE_VERSION} does not have support for inner contexts, use a more recent version"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if TruffleRuby.native?
|
|
82
|
+
raise "You need the TruffleRuby JVM Standalone for mini_racer because it is not possible to install the js component in the the Native standalone"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
unless Polyglot.languages.include? "js"
|
|
86
|
+
raise "The language 'js' is not available, you need to install the 'js' component.\nSee https://github.com/oracle/truffleruby/blob/master/doc/user/polyglot.md#installing-other-languages"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
@context =
|
|
90
|
+
Polyglot::InnerContext.new(
|
|
91
|
+
on_cancelled: -> do
|
|
92
|
+
raise ScriptTerminatedError,
|
|
93
|
+
"JavaScript was terminated (either by timeout or explicitly)"
|
|
94
|
+
end
|
|
95
|
+
)
|
|
96
|
+
Context.instance_variable_set(:@context_initialized, true)
|
|
97
|
+
@js_object = @context.eval("js", "Object")
|
|
98
|
+
@isolate_mutex = Mutex.new
|
|
99
|
+
@stopped = false
|
|
100
|
+
@entered = false
|
|
101
|
+
@has_entered = false
|
|
102
|
+
@current_exception = nil
|
|
103
|
+
isolate.instance_variable_set(:@snapshot, snapshot) if isolate && snapshot
|
|
104
|
+
if snapshot
|
|
105
|
+
@snapshot = snapshot
|
|
106
|
+
elsif isolate
|
|
107
|
+
@snapshot = isolate.instance_variable_get(:@snapshot)
|
|
108
|
+
else
|
|
109
|
+
@snapshot = nil
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
@is_object_or_array_func =
|
|
113
|
+
eval_in_context "(x) => { return (x instanceof Object || x instanceof Array) && !(x instanceof Date) && !(x instanceof Function) }"
|
|
114
|
+
@is_map_func = eval_in_context "(x) => { return x instanceof Map }"
|
|
115
|
+
@is_map_iterator_func =
|
|
116
|
+
eval_in_context "(x) => { return x[Symbol.toStringTag] === 'Map Iterator' }"
|
|
117
|
+
@is_time_func = eval_in_context "(x) => { return x instanceof Date }"
|
|
118
|
+
@is_symbol_func =
|
|
119
|
+
eval_in_context "(x) => { return typeof x === 'symbol' }"
|
|
120
|
+
@is_uint8_array_func =
|
|
121
|
+
eval_in_context "(x) => { return x instanceof Uint8Array }"
|
|
122
|
+
|
|
123
|
+
@js_date_to_time_func = eval_in_context "(x) => { return x.getTime(x) }"
|
|
124
|
+
@js_symbol_to_symbol_func =
|
|
125
|
+
eval_in_context "(x) => { var r = x.description; return r === undefined ? 'undefined' : r }"
|
|
126
|
+
@js_new_date_func = eval_in_context "(x) => { return new Date(x) }"
|
|
127
|
+
@js_new_array_func = eval_in_context "(x) => { return new Array(x) }"
|
|
128
|
+
# looks up a (dotted) function name as properties from globalThis,
|
|
129
|
+
# instead of evaluating the name as source code, so that names with
|
|
130
|
+
# embedded NUL bytes or other invalid syntax resolve correctly
|
|
131
|
+
@js_lookup_call_target_func = eval_in_context <<~JS
|
|
132
|
+
(name) => {
|
|
133
|
+
let target = globalThis;
|
|
134
|
+
for (const key of name.split(".")) {
|
|
135
|
+
if (target == null) {
|
|
136
|
+
throw new ReferenceError(name + " is not defined");
|
|
137
|
+
}
|
|
138
|
+
target = target[key];
|
|
139
|
+
}
|
|
140
|
+
if (target === undefined) {
|
|
141
|
+
throw new ReferenceError(name + " is not defined");
|
|
142
|
+
}
|
|
143
|
+
return target;
|
|
144
|
+
}
|
|
145
|
+
JS
|
|
146
|
+
@js_new_uint8array_func =
|
|
147
|
+
eval_in_context "(x) => { return new Uint8Array(x) }"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def dispose_unsafe
|
|
151
|
+
@context.close
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def eval_unsafe(str, filename)
|
|
155
|
+
@entered = true
|
|
156
|
+
if !@has_entered && @snapshot
|
|
157
|
+
snapshot_src = encode(@snapshot.instance_variable_get(:@source))
|
|
158
|
+
begin
|
|
159
|
+
eval_in_context(snapshot_src, filename)
|
|
160
|
+
rescue Polyglot::ForeignException => e
|
|
161
|
+
raise RuntimeError, e.message, e.backtrace
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
@has_entered = true
|
|
165
|
+
if @stopped
|
|
166
|
+
raise RuntimeError, "TruffleRuby does not support eval after stop"
|
|
167
|
+
end
|
|
168
|
+
unless str.is_a?(String)
|
|
169
|
+
raise TypeError, "wrong type argument #{str.class} (should be a string)"
|
|
170
|
+
end
|
|
171
|
+
unless filename.nil? || filename.is_a?(String)
|
|
172
|
+
raise TypeError,
|
|
173
|
+
"wrong type argument #{filename.class} (should be a string)"
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
str = encode(str)
|
|
177
|
+
begin
|
|
178
|
+
translate { eval_in_context(str, filename) }
|
|
179
|
+
rescue Polyglot::ForeignException => e
|
|
180
|
+
raise RuntimeError, e.message, e.backtrace
|
|
181
|
+
rescue ::RuntimeError => e
|
|
182
|
+
if @current_exception
|
|
183
|
+
e = @current_exception
|
|
184
|
+
@current_exception = nil
|
|
185
|
+
raise e
|
|
186
|
+
else
|
|
187
|
+
raise e, e.message
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
ensure
|
|
191
|
+
@entered = false
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def call_unsafe(function_name, *arguments)
|
|
195
|
+
@entered = true
|
|
196
|
+
if !@has_entered && @snapshot
|
|
197
|
+
src = encode(@snapshot.instance_variable_get(:source))
|
|
198
|
+
begin
|
|
199
|
+
eval_in_context(src)
|
|
200
|
+
rescue Polyglot::ForeignException => e
|
|
201
|
+
raise RuntimeError, e.message, e.backtrace
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
@has_entered = true
|
|
205
|
+
if @stopped
|
|
206
|
+
raise RuntimeError, "TruffleRuby does not support call after stop"
|
|
207
|
+
end
|
|
208
|
+
begin
|
|
209
|
+
translate do
|
|
210
|
+
function =
|
|
211
|
+
@js_lookup_call_target_func.call(
|
|
212
|
+
convert_ruby_to_js(encode(function_name))
|
|
213
|
+
)
|
|
214
|
+
function.call(*convert_ruby_to_js(arguments))
|
|
215
|
+
end
|
|
216
|
+
rescue Polyglot::ForeignException => e
|
|
217
|
+
raise RuntimeError, e.message, e.backtrace
|
|
218
|
+
end
|
|
219
|
+
ensure
|
|
220
|
+
@entered = false
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def create_isolate_value
|
|
224
|
+
# Returning a dummy object since TruffleRuby does not have a 1-1 concept with isolate.
|
|
225
|
+
# However, code and ASTs are shared between contexts.
|
|
226
|
+
Isolate.new
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def isolate_mutex
|
|
230
|
+
@isolate_mutex
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def translate
|
|
234
|
+
convert_js_to_ruby yield
|
|
235
|
+
rescue Object => e
|
|
236
|
+
message = e.message
|
|
237
|
+
if @current_exception
|
|
238
|
+
raise @current_exception
|
|
239
|
+
elsif e.message && e.message.start_with?("SyntaxError:")
|
|
240
|
+
error_class = MiniRacer::ParseError
|
|
241
|
+
elsif e.is_a?(MiniRacer::ScriptTerminatedError)
|
|
242
|
+
error_class = MiniRacer::ScriptTerminatedError
|
|
243
|
+
else
|
|
244
|
+
error_class = MiniRacer::RuntimeError
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
if error_class == MiniRacer::RuntimeError
|
|
248
|
+
bls =
|
|
249
|
+
e.backtrace_locations&.select do |bl|
|
|
250
|
+
bl&.source_location&.language == "js"
|
|
251
|
+
end
|
|
252
|
+
if bls && !bls.empty?
|
|
253
|
+
if "(eval)" != bls[0].path
|
|
254
|
+
message =
|
|
255
|
+
"#{e.message}\n at #{bls[0]}\n" + bls[1..].map(&:to_s).join("\n")
|
|
256
|
+
else
|
|
257
|
+
message = "#{e.message}\n" + bls.map(&:to_s).join("\n")
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
raise error_class, message
|
|
261
|
+
else
|
|
262
|
+
raise error_class, message, e.backtrace
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def convert_js_to_ruby(value)
|
|
267
|
+
case value
|
|
268
|
+
when true, false, Integer
|
|
269
|
+
value
|
|
270
|
+
when Float
|
|
271
|
+
# match the C extension: integral doubles convert to Ruby Integers
|
|
272
|
+
value.finite? && value == value.truncate ? value.to_i : value
|
|
273
|
+
else
|
|
274
|
+
if value.nil?
|
|
275
|
+
nil
|
|
276
|
+
elsif value.respond_to?(:call)
|
|
277
|
+
MiniRacer::JavaScriptFunction.new
|
|
278
|
+
elsif value.respond_to?(:to_str)
|
|
279
|
+
value.to_str.dup
|
|
280
|
+
elsif value.respond_to?(:to_ary)
|
|
281
|
+
return value.to_a.pack("C*") if uint8_array?(value)
|
|
282
|
+
|
|
283
|
+
value.to_ary.map do |e|
|
|
284
|
+
e.respond_to?(:call) ? nil : convert_js_to_ruby(e)
|
|
285
|
+
end
|
|
286
|
+
elsif time?(value)
|
|
287
|
+
js_date_to_time(value)
|
|
288
|
+
elsif symbol?(value)
|
|
289
|
+
js_symbol_to_symbol(value)
|
|
290
|
+
elsif map?(value)
|
|
291
|
+
js_map_to_hash(value)
|
|
292
|
+
elsif map_iterator?(value)
|
|
293
|
+
value.map { |e| convert_js_to_ruby(e) }
|
|
294
|
+
elsif Polyglot::ForeignException === value
|
|
295
|
+
exc = MiniRacer::ScriptError.new(value.message)
|
|
296
|
+
exc.set_backtrace(value.backtrace)
|
|
297
|
+
exc
|
|
298
|
+
else
|
|
299
|
+
object = value
|
|
300
|
+
h = {}
|
|
301
|
+
object.instance_variables.each do |member|
|
|
302
|
+
v = object[member]
|
|
303
|
+
h[member.to_s] = convert_js_to_ruby(v) unless v.respond_to?(:call)
|
|
304
|
+
end
|
|
305
|
+
h
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def object_or_array?(val)
|
|
311
|
+
@is_object_or_array_func.call(val)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def map?(value)
|
|
315
|
+
@is_map_func.call(value)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def map_iterator?(value)
|
|
319
|
+
@is_map_iterator_func.call(value)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def time?(value)
|
|
323
|
+
@is_time_func.call(value)
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def symbol?(value)
|
|
327
|
+
@is_symbol_func.call(value)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def uint8_array?(value)
|
|
331
|
+
@is_uint8_array_func.call(value)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def js_date_to_time(value)
|
|
335
|
+
millis = @js_date_to_time_func.call(value)
|
|
336
|
+
Time.at(Rational(millis, 1000))
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def js_symbol_to_symbol(value)
|
|
340
|
+
@js_symbol_to_symbol_func.call(value).to_s.to_sym
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def js_map_to_hash(map)
|
|
344
|
+
map.to_a.to_h do |key, value|
|
|
345
|
+
[convert_js_to_ruby(key), convert_js_to_ruby(value)]
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def js_new_date(value)
|
|
350
|
+
@js_new_date_func.call(value)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
def js_new_array(size)
|
|
354
|
+
@js_new_array_func.call(size)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def convert_ruby_to_js(value)
|
|
358
|
+
case value
|
|
359
|
+
when nil, true, false, Integer, Float
|
|
360
|
+
value
|
|
361
|
+
when Array
|
|
362
|
+
ary = js_new_array(value.size)
|
|
363
|
+
value.each_with_index { |v, i| ary[i] = convert_ruby_to_js(v) }
|
|
364
|
+
ary
|
|
365
|
+
when Hash
|
|
366
|
+
h = @js_object.new
|
|
367
|
+
value.each_pair do |k, v|
|
|
368
|
+
h[convert_ruby_to_js(k.to_s)] = convert_ruby_to_js(v)
|
|
369
|
+
end
|
|
370
|
+
h
|
|
371
|
+
when String, Symbol
|
|
372
|
+
Truffle::Interop.as_truffle_string value
|
|
373
|
+
when Time
|
|
374
|
+
js_new_date(value.to_f * 1000)
|
|
375
|
+
when DateTime
|
|
376
|
+
js_new_date(value.to_time.to_f * 1000)
|
|
377
|
+
when MiniRacer::Binary
|
|
378
|
+
@js_new_uint8array_func.call(value.data.bytes)
|
|
379
|
+
else
|
|
380
|
+
"Undefined Conversion"
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def encode(string)
|
|
385
|
+
raise ArgumentError unless string
|
|
386
|
+
string.encode(::Encoding::UTF_8)
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
class_eval <<-'RUBY', "(mini_racer)", 1
|
|
390
|
+
def eval_in_context(code, file = nil); code = ('"use strict";' + code) if Context.instance_variable_get(:@use_strict); @context.eval('js', code, file || '(mini_racer)'); end
|
|
391
|
+
RUBY
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
class Isolate
|
|
395
|
+
def init_with_snapshot(snapshot)
|
|
396
|
+
# TruffleRuby does not have a 1-1 concept with isolate.
|
|
397
|
+
# However, isolate can hold a snapshot, and code and ASTs are shared between contexts.
|
|
398
|
+
@snapshot = snapshot
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
class Platform
|
|
403
|
+
def self.set_flag_as_str!(flag)
|
|
404
|
+
unless flag.is_a?(String)
|
|
405
|
+
raise TypeError,
|
|
406
|
+
"wrong type argument #{flag.class} (should be a string)"
|
|
407
|
+
end
|
|
408
|
+
raise ArgumentError, "flag contains NUL byte" if flag.include?("\0")
|
|
409
|
+
# the C extension normalizes flags into a 256 byte "--flag" buffer
|
|
410
|
+
normalized = flag.start_with?("--") ? flag : "--#{flag}"
|
|
411
|
+
raise ArgumentError, "flag too long" if normalized.bytesize >= 256
|
|
412
|
+
if Context.instance_variable_get(:@context_initialized)
|
|
413
|
+
raise MiniRacer::PlatformAlreadyInitialized,
|
|
414
|
+
"The platform is already initialized."
|
|
415
|
+
end
|
|
416
|
+
if "--use_strict" == flag
|
|
417
|
+
Context.instance_variable_set(:@use_strict, true)
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
class Snapshot
|
|
423
|
+
def load(str)
|
|
424
|
+
unless str.is_a?(String)
|
|
425
|
+
raise TypeError, "wrong type argument #{str.class} (should be a string)"
|
|
426
|
+
end
|
|
427
|
+
# Intentionally noop since TruffleRuby mocks the snapshot API
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def warmup_unsafe!(src)
|
|
431
|
+
unless src.is_a?(String)
|
|
432
|
+
raise TypeError, "wrong type argument #{src.class} (should be a string)"
|
|
433
|
+
end
|
|
434
|
+
# Intentionally noop since TruffleRuby mocks the snapshot API
|
|
435
|
+
# by replaying snapshot source before the first eval/call
|
|
436
|
+
self
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
end
|
data/lib/mini_racer.rb
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The classes below reproduce mini_racer's Ruby vocabulary
|
|
4
|
+
# (lib/mini_racer.rb, MIT, Copyright (c) 2016-2019 the mini_racer project authors).
|
|
5
|
+
|
|
6
|
+
require "pathname"
|
|
7
|
+
require "json"
|
|
8
|
+
require "io/wait"
|
|
9
|
+
require_relative "../mini_racer/version"
|
|
10
|
+
|
|
11
|
+
module MiniRacer
|
|
12
|
+
class Binary
|
|
13
|
+
attr_reader :data
|
|
14
|
+
|
|
15
|
+
def initialize(data)
|
|
16
|
+
raise TypeError, "wrong argument type #{data.class} (expected String)" unless data.is_a?(String)
|
|
17
|
+
|
|
18
|
+
@data = data
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Error < ::StandardError
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class ContextDisposedError < Error
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class PlatformAlreadyInitialized < Error
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class EvalError < Error
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class ParseError < EvalError
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class ScriptTerminatedError < EvalError
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class V8OutOfMemoryError < EvalError
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class RuntimeError < EvalError
|
|
44
|
+
def initialize(message)
|
|
45
|
+
message, *@frames = message.split("\n")
|
|
46
|
+
@frames.map! { "JavaScript #{_1.strip}" }
|
|
47
|
+
super(message)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def backtrace
|
|
51
|
+
frames = super
|
|
52
|
+
@frames + frames unless frames.nil?
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class ScriptError < EvalError
|
|
57
|
+
def initialize(message)
|
|
58
|
+
message, *@frames = message.split("\n")
|
|
59
|
+
@frames.map! { "JavaScript #{_1.strip}" }
|
|
60
|
+
super(message)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def backtrace
|
|
64
|
+
frames = super || []
|
|
65
|
+
@frames + frames
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class SnapshotError < Error
|
|
70
|
+
def initialize(message)
|
|
71
|
+
message, *@frames = message.split("\n")
|
|
72
|
+
@frames.map! { "JavaScript #{_1.strip}" }
|
|
73
|
+
super(message)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def backtrace
|
|
77
|
+
frames = super
|
|
78
|
+
@frames + frames unless frames.nil?
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class Context
|
|
83
|
+
def load(filename)
|
|
84
|
+
eval(File.read(filename))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def write_heap_snapshot(file_or_io)
|
|
88
|
+
f = nil
|
|
89
|
+
implicit = false
|
|
90
|
+
|
|
91
|
+
if file_or_io.is_a?(String)
|
|
92
|
+
f = File.open(file_or_io, "w")
|
|
93
|
+
implicit = true
|
|
94
|
+
else
|
|
95
|
+
f = file_or_io
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
raise ArgumentError, "file_or_io" unless f.is_a?(File)
|
|
99
|
+
|
|
100
|
+
f.write(heap_snapshot)
|
|
101
|
+
ensure
|
|
102
|
+
f.close if implicit
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
if (spec = Gem.loaded_specs["mini_racer"]) && spec.metadata["mini_racer_rs_shim"] != "true"
|
|
4
|
+
raise LoadError,
|
|
5
|
+
"mini_racer_rs and the mini_racer #{spec.version} gem are both active; " \
|
|
6
|
+
"remove mini_racer from the bundle, or use the shim gemspec from mini_racer_rs"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
upstream_ext = %r{/mini_racer_(?:extension|loader)\.#{Regexp.escape(RbConfig::CONFIG["DLEXT"])}\z}o
|
|
10
|
+
if $LOADED_FEATURES.any? { upstream_ext.match?(_1) }
|
|
11
|
+
raise LoadError, "the mini_racer gem's native extension is already loaded; mini_racer_rs cannot replace it"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
require_relative "mini_racer_rs/version"
|
|
15
|
+
require_relative "mini_racer_rs/vocabulary"
|
|
16
|
+
|
|
17
|
+
if RUBY_ENGINE == "truffleruby"
|
|
18
|
+
require_relative "mini_racer/truffleruby"
|
|
19
|
+
else
|
|
20
|
+
require_relative "mini_racer_rs/internal_error"
|
|
21
|
+
native = ["#{RUBY_VERSION[/\A\d+\.\d+/]}/mini_racer_rs", "mini_racer_rs"].find do |name|
|
|
22
|
+
File.file?(File.join(__dir__, "mini_racer_rs", "#{name}.#{RbConfig::CONFIG["DLEXT"]}"))
|
|
23
|
+
end
|
|
24
|
+
raise LoadError, "mini_racer_rs native extension not found; run `rake compile`" unless native
|
|
25
|
+
|
|
26
|
+
require_relative "mini_racer_rs/#{native}"
|
|
27
|
+
|
|
28
|
+
unless MiniRacerRs::NATIVE_VERSION == MiniRacerRs::VERSION
|
|
29
|
+
raise LoadError,
|
|
30
|
+
"mini_racer_rs native extension #{MiniRacerRs::NATIVE_VERSION} does not match " \
|
|
31
|
+
"the gem #{MiniRacerRs::VERSION}; run `rake compile`"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-2019, the mini_racer project authors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# rust 1.99.1
|
|
2
|
+
# component file source sha256
|
|
3
|
+
std COPYRIGHT https://raw.githubusercontent.com/rust-lang/rust/1.99.1/COPYRIGHT 172020dbfd5b53a226dfde77616190a48dcff519b0bc0e6deb91a8450782c4af
|
|
4
|
+
std LICENSE-APACHE https://raw.githubusercontent.com/rust-lang/rust/1.99.1/LICENSE-APACHE 62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a
|
|
5
|
+
std LICENSE-MIT https://raw.githubusercontent.com/rust-lang/rust/1.99.1/LICENSE-MIT b71bd43a069ca0641a9ecfe585ca7b3c53b5cc1608f8b68321168698e28b5ea1
|
|
6
|
+
std COPYRIGHT-library.html rustc 1.99.1: share/doc/rust/COPYRIGHT-library.html 5647be074c8edf7339fd863055923a8fc80bc5610a8d4661ec3b767b9d392c27
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Short version for non-lawyers:
|
|
2
|
+
|
|
3
|
+
The Rust Project is dual-licensed under Apache 2.0 and MIT
|
|
4
|
+
terms.
|
|
5
|
+
|
|
6
|
+
It is Copyright (c) The Rust Project Contributors.
|
|
7
|
+
|
|
8
|
+
Longer version:
|
|
9
|
+
|
|
10
|
+
Copyrights in the Rust project are retained by their contributors. No
|
|
11
|
+
copyright assignment is required to contribute to the Rust project.
|
|
12
|
+
|
|
13
|
+
Some files include explicit copyright notices and/or license notices.
|
|
14
|
+
For full authorship information, see the version control history or
|
|
15
|
+
<https://thanks.rust-lang.org>
|
|
16
|
+
|
|
17
|
+
Except as otherwise noted, Rust is licensed under the Apache License, Version
|
|
18
|
+
2.0 <LICENSE-APACHE> or <http://www.apache.org/licenses/LICENSE-2.0> or the MIT
|
|
19
|
+
license <LICENSE-MIT> or <http://opensource.org/licenses/MIT>, at your option.
|
|
20
|
+
|
|
21
|
+
We track licenses for third-party materials in two ways:
|
|
22
|
+
|
|
23
|
+
* We use [REUSE](https://reuse.software) to track license information for
|
|
24
|
+
in-tree source files - both those authored by the Rust project and those
|
|
25
|
+
authored by third parties. See `REUSE.toml`, and our cached output of the
|
|
26
|
+
`reuse` tool which is committed to `license-metadata.json`.
|
|
27
|
+
* We use `cargo` to track license information for out-of-tree dependencies.
|
|
28
|
+
|
|
29
|
+
These two sources of information are collected by the tool `generate-copyright`
|
|
30
|
+
into a file called `COPYRIGHT.html`, which is shipped with each binary release
|
|
31
|
+
of Rust. Please refer to that file for detailed information as to the components of
|
|
32
|
+
any given Rust release. We also produce a `COPYRIGHT-library.html` file which only
|
|
33
|
+
covers the subset of source code used in the Rust Standard Library, as opposed
|
|
34
|
+
to the toolchain as a whole.
|