mini_racer_rs 1.0.5 → 1.0.6
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/COMPATIBILITY.md +7 -1
- data/Cargo.lock +4 -4
- data/Cargo.toml +1 -1
- data/README.md +1 -1
- data/ext/mini_racer_rs/src/decode.rs +29 -0
- data/ext/mini_racer_rs/src/encode.rs +6 -0
- data/ext/mini_racer_rs/src/errors.rs +9 -1
- data/ext/mini_racer_rs/src/gc_root.rs +5 -0
- data/ext/mini_racer_rs/src/host.rs +16 -2
- data/ext/mini_racer_rs/src/lib.rs +2 -0
- data/ext/mini_racer_rs/src/rb_raw.rs +11 -0
- data/lib/mini_racer_rs/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34cc61e0568863bc59e52837ee5366a5ee8c560d22ad81454ca29bdb55666c45
|
|
4
|
+
data.tar.gz: cc817e64000b31c6baa15daa84103b0eca1022c2ddde7f2ff949f1e8ab808588
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ed16776a34d4b948408c4ab73a9024357ed383b3b294a6384a702559765bf4d9e4d4e1a481b86457a833bf498c89e9dc4e5e6ed364fab8de4fa7c71fc428d72
|
|
7
|
+
data.tar.gz: 7dc43391ef4ef78d9a133c2646460648b849cf946417c958fdf8538a94c70eee24fc61f2cc00395f5e3e6aaa8b904e6af663e3c16ca2bd783538b0dd29397330
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.6](https://github.com/andymai/mini_racer_rs/compare/v1.0.5...v1.0.6) (2026-10-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **decode:** raise SystemStackError when a decode runs out of stack ([#95](https://github.com/andymai/mini_racer_rs/issues/95)) ([7d21103](https://github.com/andymai/mini_racer_rs/commit/7d2110338352c0259eef2e4f22f439a4875765eb))
|
|
9
|
+
|
|
3
10
|
## [1.0.5](https://github.com/andymai/mini_racer_rs/compare/v1.0.4...v1.0.5) (2026-10-19)
|
|
4
11
|
|
|
5
12
|
|
data/COMPATIBILITY.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
| Engine | Done | Planned | Deviation |
|
|
6
6
|
|---|---|---|---|
|
|
7
|
-
| CRuby | 54 | 0 |
|
|
7
|
+
| CRuby | 54 | 0 | 27 |
|
|
8
8
|
| TruffleRuby | 58 | 0 | 0 |
|
|
9
9
|
|
|
10
10
|
## Surface
|
|
@@ -192,6 +192,12 @@ mini_racer_rs returns the same filtered results from a snapshot-based context as
|
|
|
192
192
|
|
|
193
193
|
Approved 2026-10-16.
|
|
194
194
|
|
|
195
|
+
### `behavior:stack-exhaustion@ruby`
|
|
196
|
+
|
|
197
|
+
mini_racer_rs raises `SystemStackError` with `stack level too deep` when converting a JavaScript result on a Ruby fiber or thread with too little machine stack remaining for Ruby to call a C function. When converting arguments for an attached Ruby callable, mini_racer_rs does not call the callable and gives JavaScript an Error with `stack level too deep`; if uncaught, `eval` raises that `SystemStackError` in Ruby. In both cases, the context remains usable and can evaluate `1 + 1` to `2` and dispose. Across 736 runs on 128 KiB fiber and thread stacks, using release and debug builds with and without `GC.stress` and compaction, mini_racer_rs never hung or crashed. On the same stack sizes without `GC.stress`, across 120 runs per conversion kind, mini_racer 0.22.1 results returned 59 times, raised `SystemStackError` 49 times, and hung 12 times, all for values containing Latin-1 or two-byte strings. mini_racer 0.22.1 callbacks delivered `stack level too deep` to JavaScript 87 times, returned 7 times, crashed with a segmentation fault 10 times, hung 8 times, and left 8 contexts unable to dispose with `context dispose: Device or resource busy`; with `GC.stress` and compaction, many result and callback runs aborted with `[BUG] system stack overflow during GC`. The tradeoff is stack cost: in a release build, a 95-level object result needed about 30 KiB beyond Ruby's method-call limit with mini_racer_rs, versus about 10 KiB with mini_racer 0.22.1, so near the end of a stack mini_racer_rs refuses some results that mini_racer 0.22.1 returns. At Ruby 3.4's default machine stacks, 512 KiB for a fiber and 1 MiB for a thread, mini_racer_rs converts every kind of value nested 95 levels deep.
|
|
198
|
+
|
|
199
|
+
Approved 2026-10-18.
|
|
200
|
+
|
|
195
201
|
### `behavior:timeout-bounds-leftover-microtasks@ruby`
|
|
196
202
|
|
|
197
203
|
mini_racer_rs applies the context’s timeout once more while running microtasks left by a script that reached its own timeout. Both gems run leftover microtasks before returning, but mini_racer 0.22.1's watchdog has already fired for that call, so it runs them without a time limit. For example, with `timeout: 200`, evaluating `Promise.resolve().then(() => { while (true) {} }); while (true) {}` never returns in mini_racer. In mini_racer_rs it raises `MiniRacer::ScriptTerminatedError` after about 400 ms, and the context remains usable. This also means mini_racer_rs cuts short a finite leftover microtask that needs more than the second 200 ms, while mini_racer finishes it. Microtasks left by a script ended another way, such as by `stop`, a memory limit, or an interrupt, keep the original deadline in both gems. Without `timeout:`, both run leftover microtasks without a limit. mini_racer_rs differs because `timeout:` often bounds untrusted JavaScript, and an endless microtask should not remove that bound.
|
data/Cargo.lock
CHANGED
|
@@ -458,7 +458,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
|
458
458
|
|
|
459
459
|
[[package]]
|
|
460
460
|
name = "mini_racer_engine"
|
|
461
|
-
version = "1.0.
|
|
461
|
+
version = "1.0.6"
|
|
462
462
|
dependencies = [
|
|
463
463
|
"deno_core_icudata",
|
|
464
464
|
"libc",
|
|
@@ -470,7 +470,7 @@ dependencies = [
|
|
|
470
470
|
|
|
471
471
|
[[package]]
|
|
472
472
|
name = "mini_racer_rs"
|
|
473
|
-
version = "1.0.
|
|
473
|
+
version = "1.0.6"
|
|
474
474
|
dependencies = [
|
|
475
475
|
"magnus",
|
|
476
476
|
"mini_racer_engine",
|
|
@@ -481,7 +481,7 @@ dependencies = [
|
|
|
481
481
|
|
|
482
482
|
[[package]]
|
|
483
483
|
name = "mini_racer_sync"
|
|
484
|
-
version = "1.0.
|
|
484
|
+
version = "1.0.6"
|
|
485
485
|
dependencies = [
|
|
486
486
|
"loom",
|
|
487
487
|
"thiserror",
|
|
@@ -489,7 +489,7 @@ dependencies = [
|
|
|
489
489
|
|
|
490
490
|
[[package]]
|
|
491
491
|
name = "mini_racer_wire"
|
|
492
|
-
version = "1.0.
|
|
492
|
+
version = "1.0.6"
|
|
493
493
|
dependencies = [
|
|
494
494
|
"proptest",
|
|
495
495
|
"thiserror",
|
data/Cargo.toml
CHANGED
data/README.md
CHANGED
|
@@ -25,6 +25,12 @@ static JAVASCRIPT_FUNCTION: StaticRoot<RClass> = StaticRoot::new(|ruby| {
|
|
|
25
25
|
.expect("init defines MiniRacer::JavaScriptFunction")
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
+
// Resolved at load, as the error classes are, rather than first near the end
|
|
29
|
+
// of the stack, where its lookup could fail and panic.
|
|
30
|
+
pub fn init(ruby: &Ruby) {
|
|
31
|
+
JAVASCRIPT_FUNCTION.get(ruby);
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
29
35
|
enum Number {
|
|
30
36
|
Integer(i64),
|
|
@@ -273,6 +279,9 @@ struct RubyVisitor<'r> {
|
|
|
273
279
|
// Arrays and sets open around the current value.
|
|
274
280
|
arrays: u32,
|
|
275
281
|
scratch: Vec<u8>,
|
|
282
|
+
// The deepest stack address at which a container began with the room
|
|
283
|
+
// Ruby keeps for a C function still left.
|
|
284
|
+
roomy: usize,
|
|
276
285
|
}
|
|
277
286
|
|
|
278
287
|
impl RubyVisitor<'_> {
|
|
@@ -382,6 +391,24 @@ impl RubyVisitor<'_> {
|
|
|
382
391
|
rb_raw::hash_aset_pairs(ruby, hash, &[[key, value]])
|
|
383
392
|
}
|
|
384
393
|
|
|
394
|
+
// A machine stack that runs out under the decoder's recursion faults, and
|
|
395
|
+
// Ruby's handler then jumps over every Rust frame to raise. The decoder
|
|
396
|
+
// stops instead while Ruby's margin is left, so its error unwinds
|
|
397
|
+
// normally. Only a container deeper than any checked before asks Ruby,
|
|
398
|
+
// since the stack grows down on every supported platform.
|
|
399
|
+
fn check_stack(&mut self) -> Result<(), Error> {
|
|
400
|
+
let here = 0u8;
|
|
401
|
+
let at = std::ptr::from_ref(std::hint::black_box(&here)).addr();
|
|
402
|
+
if at >= self.roomy {
|
|
403
|
+
return Ok(());
|
|
404
|
+
}
|
|
405
|
+
if rb_raw::stack_exhausted(self.ruby) {
|
|
406
|
+
return Err(errors::stack_exhausted(self.ruby));
|
|
407
|
+
}
|
|
408
|
+
self.roomy = at;
|
|
409
|
+
Ok(())
|
|
410
|
+
}
|
|
411
|
+
|
|
385
412
|
fn bad_state<T>(&self) -> Result<T, Error> {
|
|
386
413
|
Err(errors::runtime(self.ruby, "bad state"))
|
|
387
414
|
}
|
|
@@ -559,6 +586,7 @@ impl Visitor for RubyVisitor<'_> {
|
|
|
559
586
|
}
|
|
560
587
|
|
|
561
588
|
fn begin(&mut self, container: Container) -> Result<Begun<Frame, Value>, Error> {
|
|
589
|
+
self.check_stack()?;
|
|
562
590
|
self.flush()?;
|
|
563
591
|
let ruby = self.ruby;
|
|
564
592
|
let frame = match container {
|
|
@@ -732,6 +760,7 @@ pub fn value(ruby: &Ruby, bytes: &[u8]) -> Result<Value, Error> {
|
|
|
732
760
|
keys: None,
|
|
733
761
|
arrays: 0,
|
|
734
762
|
scratch: Vec::new(),
|
|
763
|
+
roomy: usize::MAX,
|
|
735
764
|
};
|
|
736
765
|
decode_value(bytes, RESULT_LIMITS, &mut visitor).map_err(|e| match e {
|
|
737
766
|
DecodeError::Visitor(error) => error,
|
|
@@ -34,6 +34,12 @@ static BINARY: StaticRoot<RClass> = StaticRoot::new(|ruby| {
|
|
|
34
34
|
.expect("the vocabulary defines MiniRacer::Binary")
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
+
// Resolved at load, as the error classes are, rather than first near the end
|
|
38
|
+
// of the stack, where its lookup could fail and panic.
|
|
39
|
+
pub fn init(ruby: &Ruby) {
|
|
40
|
+
BINARY.get(ruby);
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
enum EncodeError {
|
|
38
44
|
// mini_racer's text for a value it cannot send, cut as it cuts it.
|
|
39
45
|
Unsupported(Vec<u8>),
|
|
@@ -38,8 +38,10 @@ macro_rules! roots {
|
|
|
38
38
|
StaticRoot::new(|ruby| resolved(ruby, $module, $name));
|
|
39
39
|
)*
|
|
40
40
|
|
|
41
|
+
// Resolved now, since a root resolved first near the end of the stack
|
|
42
|
+
// would panic on the SystemStackError its Ruby calls raise there.
|
|
41
43
|
pub fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
42
|
-
$( class(ruby, $module, $name)?; )*
|
|
44
|
+
$( class(ruby, $module, $name)?; $root.get(ruby); )*
|
|
43
45
|
SCRIPT.get(ruby).define_method("cause", export!(method cause, 0))?;
|
|
44
46
|
Ok(())
|
|
45
47
|
}
|
|
@@ -154,3 +156,9 @@ pub fn runtime(ruby: &Ruby, message: impl AsRef<[u8]>) -> Error {
|
|
|
154
156
|
pub fn internal(ruby: &Ruby, message: impl AsRef<[u8]>) -> Error {
|
|
155
157
|
raised(ruby, INTERNAL.get(ruby), message)
|
|
156
158
|
}
|
|
159
|
+
|
|
160
|
+
pub const STACK_EXHAUSTED: &str = "stack level too deep";
|
|
161
|
+
|
|
162
|
+
pub fn stack_exhausted(ruby: &Ruby) -> Error {
|
|
163
|
+
Error::new(ruby.exception_sys_stack_error(), STACK_EXHAUSTED)
|
|
164
|
+
}
|
|
@@ -173,10 +173,15 @@ impl Spill {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
// Each holder's class is looked up once, by a Ruby call whose failure panics;
|
|
177
|
+
// near the end of a fiber's stack Ruby fails it with SystemStackError, so it is
|
|
178
|
+
// looked up here instead, at load, with room to spare.
|
|
176
179
|
pub fn init(ruby: &Ruby, rs: RModule) -> Result<(), Error> {
|
|
177
180
|
for name in ["Pins", "Spill"] {
|
|
178
181
|
rs.define_class(name, ruby.class_object())?
|
|
179
182
|
.undef_default_alloc_func();
|
|
180
183
|
}
|
|
184
|
+
Pins::class(ruby);
|
|
185
|
+
Spill::class(ruby);
|
|
181
186
|
Ok(())
|
|
182
187
|
}
|
|
@@ -210,6 +210,12 @@ impl<'r> RubyHost<'r> {
|
|
|
210
210
|
fn run(&self, request: &[u8]) -> Result<Vec<u8>, Error> {
|
|
211
211
|
let ruby = self.ruby;
|
|
212
212
|
let bad = || errors::runtime(ruby, "bad callback id");
|
|
213
|
+
// An unoptimized build's frames from the eval to the decoder's first
|
|
214
|
+
// container take all of Ruby's margin, so a callback is refused here
|
|
215
|
+
// first; the callable would need the room anyway.
|
|
216
|
+
if rb_raw::stack_exhausted(ruby) {
|
|
217
|
+
return Err(errors::stack_exhausted(ruby));
|
|
218
|
+
}
|
|
213
219
|
let args = RArray::from_value(decode::value(ruby, request)?).ok_or_else(bad)?;
|
|
214
220
|
let id = Integer::from_value(args.pop::<Value>()?).ok_or_else(bad)?;
|
|
215
221
|
let id = isize::try_from(id.to_i64()?).map_err(|_| bad())?;
|
|
@@ -243,13 +249,21 @@ fn exception(ruby: &Ruby, error: &Error) -> Option<Exception> {
|
|
|
243
249
|
}
|
|
244
250
|
|
|
245
251
|
// What V8 throws for a raising callback: the exception's to_s, in its own
|
|
246
|
-
// encoding, or mini_racer's fallback text.
|
|
252
|
+
// encoding, or mini_racer's fallback text. A callback refused for want of
|
|
253
|
+
// stack has no room left to call to_s, so its text is the one Ruby raises
|
|
254
|
+
// SystemStackError with, as mini_racer's callbacks hand JavaScript.
|
|
247
255
|
fn message(ruby: &Ruby, exception: Exception) -> JsText {
|
|
248
256
|
exception
|
|
249
257
|
.funcall::<_, _, RString>("to_s", ())
|
|
250
258
|
.ok()
|
|
251
259
|
.and_then(|text| context::js_text(ruby, text).ok())
|
|
252
|
-
.unwrap_or_else(||
|
|
260
|
+
.unwrap_or_else(|| {
|
|
261
|
+
if exception.is_kind_of(ruby.exception_sys_stack_error()) {
|
|
262
|
+
JsText::from(errors::STACK_EXHAUSTED)
|
|
263
|
+
} else {
|
|
264
|
+
JsText::from("Ruby exception")
|
|
265
|
+
}
|
|
266
|
+
})
|
|
253
267
|
}
|
|
254
268
|
|
|
255
269
|
impl Host for RubyHost<'_> {
|
|
@@ -40,6 +40,8 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
40
40
|
racer.define_class("JavaScriptFunction", ruby.class_object())?;
|
|
41
41
|
gc_root::init(ruby, rs)?;
|
|
42
42
|
errors::init(ruby)?;
|
|
43
|
+
decode::init(ruby);
|
|
44
|
+
encode::init(ruby);
|
|
43
45
|
platform::init(ruby, racer)?;
|
|
44
46
|
context::init(ruby, racer)?;
|
|
45
47
|
snapshot::init(ruby, racer)?;
|
|
@@ -105,6 +105,17 @@ pub fn fiber_scheduler(_ruby: &Ruby) -> bool {
|
|
|
105
105
|
scheduler != rb_sys::Qnil as rb_sys::VALUE
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/// Whether the current thread's or fiber's machine stack has less room left
|
|
109
|
+
/// than Ruby keeps for a C function, where its own method calls raise
|
|
110
|
+
/// `SystemStackError`.
|
|
111
|
+
pub fn stack_exhausted(_ruby: &Ruby) -> bool {
|
|
112
|
+
// SAFETY: the `&Ruby` argument proves this thread holds the GVL, and
|
|
113
|
+
// ruby_stack_check only records the stack pointer, as Ruby's own checks do
|
|
114
|
+
// on every method call, and compares it with the bounds Ruby keeps for the
|
|
115
|
+
// current thread or fiber.
|
|
116
|
+
unsafe { rb_sys::ruby_stack_check() != 0 }
|
|
117
|
+
}
|
|
118
|
+
|
|
108
119
|
pub fn dbl2big(_ruby: &Ruby, n: f64) -> Value {
|
|
109
120
|
// SAFETY: rb_dbl2big allocates a Bignum and requires the GVL, which the
|
|
110
121
|
// `&Ruby` argument proves this thread holds.
|