mini_racer_rs 1.0.5 → 1.1.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/COMPATIBILITY.md +13 -1
- data/Cargo.lock +40 -4
- data/Cargo.toml +6 -1
- data/README.md +4 -1
- data/THIRD_PARTY_NOTICES.md +60 -0
- data/crates/mini_racer_engine/Cargo.toml +1 -0
- data/crates/mini_racer_engine/src/error.rs +11 -0
- data/crates/mini_racer_engine/src/lib.rs +3 -1
- data/crates/mini_racer_engine/src/process/fork.rs +19 -5
- data/crates/mini_racer_engine/src/process/source_maps.rs +104 -0
- data/crates/mini_racer_engine/src/process.rs +1 -0
- data/crates/mini_racer_engine/src/runner.rs +114 -0
- data/crates/mini_racer_sourcemap/Cargo.toml +18 -0
- data/crates/mini_racer_sourcemap/src/lib.rs +13 -0
- data/crates/mini_racer_sourcemap/src/map.rs +1535 -0
- data/crates/mini_racer_sourcemap/src/rewrite.rs +624 -0
- data/crates/mini_racer_sourcemap/src/vlq.rs +168 -0
- 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 +4 -0
- data/ext/mini_racer_rs/src/rb_raw.rs +11 -0
- data/ext/mini_racer_rs/src/source_maps.rs +42 -0
- data/lib/mini_racer_rs/version.rb +1 -1
- metadata +8 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ed46336604ed832bdf22770d4c57d3ce98757187a901b1a762d8732bb4a8007
|
|
4
|
+
data.tar.gz: 8e7bd77bf38d9ac5e59663e26f7e56fb9dc8642ad5cd1bd2d85e014d015f5b3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad1576874e3a13acdcf373ebb7dfaa22254f1a3320c7774241c9ad830c033c12ad514c86164a24ff0a63ca495bc6f1bb57104fafd58b923929d76c8fae0a1725
|
|
7
|
+
data.tar.gz: c3b8ebccb0dc686242ee8b257712b11c81d4986e92b25470f33e8fb8505e34dd9fbc60e98869dde424b060e147474cefa7a210bc6a8496ffd66b9590a5a05c18
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.1.0](https://github.com/andymai/mini_racer_rs/compare/v1.0.6...v1.1.0) (2026-10-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **source-maps:** map runtime error frames back to original sources ([#97](https://github.com/andymai/mini_racer_rs/issues/97)) ([d92bb05](https://github.com/andymai/mini_racer_rs/commit/d92bb0505ecd02deb1a0b62aa952268a5bdfb689))
|
|
9
|
+
|
|
10
|
+
## [1.0.6](https://github.com/andymai/mini_racer_rs/compare/v1.0.5...v1.0.6) (2026-10-19)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **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))
|
|
16
|
+
|
|
3
17
|
## [1.0.5](https://github.com/andymai/mini_racer_rs/compare/v1.0.4...v1.0.5) (2026-10-19)
|
|
4
18
|
|
|
5
19
|
|
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 | 28 |
|
|
8
8
|
| TruffleRuby | 58 | 0 | 0 |
|
|
9
9
|
|
|
10
10
|
## Surface
|
|
@@ -192,6 +192,18 @@ 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:source-maps@ruby`
|
|
196
|
+
|
|
197
|
+
After a source map is registered with `MiniRacerRs.register_source_map(bundle, map)`, `MiniRacer::RuntimeError` backtraces for contexts that evaluate a UTF-8 source containing the bundle show the mapped original file, line, and column for covered frames inside that bundle, while preserving V8's function name. mini_racer 0.22.1 has no source map support, so its runtime backtraces always show V8 positions. mini_racer_rs keeps V8 positions for async frames, frames after the tenth, `eval` and `new Function` code, frames outside the bundle, uncovered positions, and every frame when the reported frames do not align with V8's stack trace. `MiniRacer::ParseError` and `MiniRacer::ScriptError` messages are unchanged, as are JavaScript-visible values such as `Error.prototype.stack`. Latin-1 and UTF-16 sources and bundles in startup snapshots do not match. With no registered map, behavior is exactly that of mini_racer 0.22.1. Maps are process wide and limited to eight bundles. Affected contexts collect detailed stacks, increasing the measured cost of a 20-frame `new Error` from about 0.8 to 1.5 microseconds and a caught `throw {}` 20 frames deep from about 0.2 to 1.2 microseconds; measured React and MUI server renders were unchanged.
|
|
198
|
+
|
|
199
|
+
Approved 2026-10-18.
|
|
200
|
+
|
|
201
|
+
### `behavior:stack-exhaustion@ruby`
|
|
202
|
+
|
|
203
|
+
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.
|
|
204
|
+
|
|
205
|
+
Approved 2026-10-18.
|
|
206
|
+
|
|
195
207
|
### `behavior:timeout-bounds-leftover-microtasks@ruby`
|
|
196
208
|
|
|
197
209
|
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
|
@@ -353,6 +353,12 @@ dependencies = [
|
|
|
353
353
|
"either",
|
|
354
354
|
]
|
|
355
355
|
|
|
356
|
+
[[package]]
|
|
357
|
+
name = "itoa"
|
|
358
|
+
version = "1.0.18"
|
|
359
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
360
|
+
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|
361
|
+
|
|
356
362
|
[[package]]
|
|
357
363
|
name = "ixdtf"
|
|
358
364
|
version = "0.6.6"
|
|
@@ -458,10 +464,11 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
|
458
464
|
|
|
459
465
|
[[package]]
|
|
460
466
|
name = "mini_racer_engine"
|
|
461
|
-
version = "1.0
|
|
467
|
+
version = "1.1.0"
|
|
462
468
|
dependencies = [
|
|
463
469
|
"deno_core_icudata",
|
|
464
470
|
"libc",
|
|
471
|
+
"mini_racer_sourcemap",
|
|
465
472
|
"mini_racer_sync",
|
|
466
473
|
"mini_racer_wire",
|
|
467
474
|
"thiserror",
|
|
@@ -470,7 +477,7 @@ dependencies = [
|
|
|
470
477
|
|
|
471
478
|
[[package]]
|
|
472
479
|
name = "mini_racer_rs"
|
|
473
|
-
version = "1.0
|
|
480
|
+
version = "1.1.0"
|
|
474
481
|
dependencies = [
|
|
475
482
|
"magnus",
|
|
476
483
|
"mini_racer_engine",
|
|
@@ -479,9 +486,19 @@ dependencies = [
|
|
|
479
486
|
"thiserror",
|
|
480
487
|
]
|
|
481
488
|
|
|
489
|
+
[[package]]
|
|
490
|
+
name = "mini_racer_sourcemap"
|
|
491
|
+
version = "1.1.0"
|
|
492
|
+
dependencies = [
|
|
493
|
+
"memchr",
|
|
494
|
+
"serde",
|
|
495
|
+
"serde_json",
|
|
496
|
+
"thiserror",
|
|
497
|
+
]
|
|
498
|
+
|
|
482
499
|
[[package]]
|
|
483
500
|
name = "mini_racer_sync"
|
|
484
|
-
version = "1.0
|
|
501
|
+
version = "1.1.0"
|
|
485
502
|
dependencies = [
|
|
486
503
|
"loom",
|
|
487
504
|
"thiserror",
|
|
@@ -489,7 +506,7 @@ dependencies = [
|
|
|
489
506
|
|
|
490
507
|
[[package]]
|
|
491
508
|
name = "mini_racer_wire"
|
|
492
|
-
version = "1.0
|
|
509
|
+
version = "1.1.0"
|
|
493
510
|
dependencies = [
|
|
494
511
|
"proptest",
|
|
495
512
|
"thiserror",
|
|
@@ -778,6 +795,19 @@ dependencies = [
|
|
|
778
795
|
"syn 3.0.9",
|
|
779
796
|
]
|
|
780
797
|
|
|
798
|
+
[[package]]
|
|
799
|
+
name = "serde_json"
|
|
800
|
+
version = "1.0.154"
|
|
801
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
802
|
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
|
803
|
+
dependencies = [
|
|
804
|
+
"itoa",
|
|
805
|
+
"memchr",
|
|
806
|
+
"serde",
|
|
807
|
+
"serde_core",
|
|
808
|
+
"zmij",
|
|
809
|
+
]
|
|
810
|
+
|
|
781
811
|
[[package]]
|
|
782
812
|
name = "sharded-slab"
|
|
783
813
|
version = "0.1.7"
|
|
@@ -1249,6 +1279,12 @@ dependencies = [
|
|
|
1249
1279
|
"syn 3.0.9",
|
|
1250
1280
|
]
|
|
1251
1281
|
|
|
1282
|
+
[[package]]
|
|
1283
|
+
name = "zmij"
|
|
1284
|
+
version = "1.0.23"
|
|
1285
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1286
|
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
|
1287
|
+
|
|
1252
1288
|
[[package]]
|
|
1253
1289
|
name = "zoneinfo64"
|
|
1254
1290
|
version = "0.3.0"
|
data/Cargo.toml
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
exclude = ["crates/mini_racer_wire/fuzz"]
|
|
3
3
|
members = [
|
|
4
4
|
"crates/mini_racer_engine",
|
|
5
|
+
"crates/mini_racer_sourcemap",
|
|
5
6
|
"crates/mini_racer_sync",
|
|
6
7
|
"crates/mini_racer_wire",
|
|
7
8
|
"ext/mini_racer_rs",
|
|
@@ -14,18 +15,22 @@ license = "MIT"
|
|
|
14
15
|
publish = false
|
|
15
16
|
repository = "https://github.com/andymai/mini_racer_rs"
|
|
16
17
|
rust-version = "1.91"
|
|
17
|
-
version = "1.0
|
|
18
|
+
version = "1.1.0"
|
|
18
19
|
|
|
19
20
|
[workspace.dependencies]
|
|
20
21
|
deno_core_icudata = "=0.78.0"
|
|
21
22
|
libc = "0.2"
|
|
22
23
|
loom = "0.7.2"
|
|
23
24
|
magnus = {version = "=0.9.2", features = ["rb-sys"]}
|
|
25
|
+
memchr = "2"
|
|
24
26
|
mini_racer_engine = {path = "crates/mini_racer_engine"}
|
|
27
|
+
mini_racer_sourcemap = {path = "crates/mini_racer_sourcemap"}
|
|
25
28
|
mini_racer_sync = {path = "crates/mini_racer_sync"}
|
|
26
29
|
mini_racer_wire = {path = "crates/mini_racer_wire"}
|
|
27
30
|
proptest = {version = "1", default-features = false, features = ["std"]}
|
|
28
31
|
rb-sys = "=0.9.130"
|
|
32
|
+
serde = {version = "1", default-features = false, features = ["alloc", "derive"]}
|
|
33
|
+
serde_json = {version = "1", default-features = false, features = ["alloc"]}
|
|
29
34
|
thiserror = "2"
|
|
30
35
|
v8 = "=152.2.0"
|
|
31
36
|
|
data/README.md
CHANGED
|
@@ -101,6 +101,7 @@ ExecJS.eval("[1, 2].map(x => x * 2)") # => [2, 4]
|
|
|
101
101
|
| `Context#pump_message_loop`, `#perform_microtask_checkpoint` | Runs pending V8 tasks and microtasks. |
|
|
102
102
|
| `Snapshot.new`, `#warmup!`, `#dump`, `Snapshot.load` | Creates, warms, serializes, and loads startup snapshots. |
|
|
103
103
|
| `Platform.set_flags!(*flags)` | Sets V8 flags before the first context. |
|
|
104
|
+
| `MiniRacerRs.register_source_map(bundle, map)` | Registers a source map for a bundle, so `MiniRacer::RuntimeError` backtraces show its original files and positions. |
|
|
104
105
|
|
|
105
106
|
`Context.new` accepts these options:
|
|
106
107
|
|
|
@@ -113,6 +114,8 @@ ExecJS.eval("[1, 2].map(x => x * 2)") # => [2, 4]
|
|
|
113
114
|
|
|
114
115
|
Errors are `MiniRacer::ParseError`, `MiniRacer::RuntimeError` with JavaScript frames in its backtrace, `MiniRacer::ScriptTerminatedError`, `MiniRacer::V8OutOfMemoryError`, `MiniRacer::ContextDisposedError`, `MiniRacer::SnapshotError`, and `MiniRacer::PlatformAlreadyInitialized`. All descend from `MiniRacer::Error`.
|
|
115
116
|
|
|
117
|
+
**Source maps.** The bundle must be a UTF-8 String of at least 1,024 bytes, and the map must be a JSON String in source map v3 format. When a context evaluates a UTF-8 source containing that bundle, `MiniRacer::RuntimeError` backtraces replace V8 positions inside it with mapped original file, line, and column positions while retaining V8 function names. Async frames, frames after the tenth, `eval` or `new Function` code, frames outside the bundle, positions the map does not cover, and stacks reformatted by JavaScript keep V8 positions. Detailed stack capture makes creating and throwing errors in affected contexts more expensive, while measured React and MUI server renders were unchanged. Registration is process wide and holds at most eight bundles, and a map cannot be removed; registering a bundle again replaces its map. Trust bundles and maps like application code because source names appear in Ruby backtraces.
|
|
118
|
+
|
|
116
119
|
## Switching from mini_racer
|
|
117
120
|
|
|
118
121
|
### What changes
|
|
@@ -189,7 +192,7 @@ bundle exec ruby bench/run.rb --cpus 0-7
|
|
|
189
192
|
|
|
190
193
|
| Engine | Done | Planned | Deviation |
|
|
191
194
|
|---|---|---|---|
|
|
192
|
-
| CRuby | 54 | 0 |
|
|
195
|
+
| CRuby | 54 | 0 | 28 |
|
|
193
196
|
| TruffleRuby | 58 | 0 | 0 |
|
|
194
197
|
|
|
195
198
|
See [COMPATIBILITY.md](COMPATIBILITY.md).
|
data/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1040,6 +1040,7 @@ limitations under the License.
|
|
|
1040
1040
|
|
|
1041
1041
|
### Apache License 2.0
|
|
1042
1042
|
|
|
1043
|
+
- `itoa`: David Tolnay <dtolnay@gmail.com>
|
|
1043
1044
|
- `libc`
|
|
1044
1045
|
- `paste`: David Tolnay <dtolnay@gmail.com>
|
|
1045
1046
|
- `proc-macro2`: David Tolnay <dtolnay@gmail.com>, Alex Crichton <alex@alexcrichton.com>
|
|
@@ -1048,6 +1049,7 @@ limitations under the License.
|
|
|
1048
1049
|
- `serde`: Erick Tryzelaar <erick.tryzelaar@gmail.com>, David Tolnay <dtolnay@gmail.com>
|
|
1049
1050
|
- `serde_core`: Erick Tryzelaar <erick.tryzelaar@gmail.com>, David Tolnay <dtolnay@gmail.com>
|
|
1050
1051
|
- `serde_derive`: Erick Tryzelaar <erick.tryzelaar@gmail.com>, David Tolnay <dtolnay@gmail.com>
|
|
1052
|
+
- `serde_json`
|
|
1051
1053
|
- `syn`: David Tolnay <dtolnay@gmail.com>
|
|
1052
1054
|
- `syn`: David Tolnay <dtolnay@gmail.com>
|
|
1053
1055
|
- `thiserror-impl`: David Tolnay <dtolnay@gmail.com>
|
|
@@ -1270,6 +1272,64 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
1270
1272
|
|
|
1271
1273
|
### MIT License
|
|
1272
1274
|
|
|
1275
|
+
- `zmij`: David Tolnay <dtolnay@gmail.com>
|
|
1276
|
+
```text
|
|
1277
|
+
Permission is hereby granted, free of charge, to any
|
|
1278
|
+
person obtaining a copy of this software and associated
|
|
1279
|
+
documentation files (the "Software"), to deal in the
|
|
1280
|
+
Software without restriction, including without
|
|
1281
|
+
limitation the rights to use, copy, modify, merge,
|
|
1282
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
1283
|
+
the Software, and to permit persons to whom the Software
|
|
1284
|
+
is furnished to do so, subject to the following
|
|
1285
|
+
conditions:
|
|
1286
|
+
|
|
1287
|
+
The above copyright notice and this permission notice
|
|
1288
|
+
shall be included in all copies or substantial portions
|
|
1289
|
+
of the Software.
|
|
1290
|
+
|
|
1291
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
1292
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
1293
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
1294
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
1295
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
1296
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
1297
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
1298
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
1299
|
+
DEALINGS IN THE SOFTWARE.
|
|
1300
|
+
|
|
1301
|
+
```
|
|
1302
|
+
|
|
1303
|
+
### MIT License
|
|
1304
|
+
|
|
1305
|
+
- `memchr`: Andrew Gallant <jamslam@gmail.com>, bluss
|
|
1306
|
+
```text
|
|
1307
|
+
The MIT License (MIT)
|
|
1308
|
+
|
|
1309
|
+
Copyright (c) 2015 Andrew Gallant
|
|
1310
|
+
|
|
1311
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1312
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1313
|
+
in the Software without restriction, including without limitation the rights
|
|
1314
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1315
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1316
|
+
furnished to do so, subject to the following conditions:
|
|
1317
|
+
|
|
1318
|
+
The above copyright notice and this permission notice shall be included in
|
|
1319
|
+
all copies or substantial portions of the Software.
|
|
1320
|
+
|
|
1321
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1322
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1323
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1324
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1325
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1326
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
1327
|
+
THE SOFTWARE.
|
|
1328
|
+
|
|
1329
|
+
```
|
|
1330
|
+
|
|
1331
|
+
### MIT License
|
|
1332
|
+
|
|
1273
1333
|
- `libm`: Alex Crichton <alex@alexcrichton.com>, Amanieu d'Antras <amanieu@gmail.com>, Jorge Aparicio <japaricious@gmail.com>, Trevor Gross <tg@trevorgross.com>
|
|
1274
1334
|
```text
|
|
1275
1335
|
rust-lang/libm as a whole is available for use under the MIT license:
|
|
@@ -24,6 +24,17 @@ pub enum InvalidSnapshot {
|
|
|
24
24
|
Empty,
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/// Why `SourceMaps::register` refused a map.
|
|
28
|
+
#[derive(Debug, thiserror::Error)]
|
|
29
|
+
pub enum SourceMapError {
|
|
30
|
+
#[error(transparent)]
|
|
31
|
+
Map(#[from] mini_racer_sourcemap::MapError),
|
|
32
|
+
#[error("at most {0} bundles can have a source map")]
|
|
33
|
+
Full(usize),
|
|
34
|
+
#[error("the bundle is shorter than {0} bytes")]
|
|
35
|
+
Short(usize),
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
28
39
|
pub enum JsErrorKind {
|
|
29
40
|
Parse,
|
|
@@ -18,6 +18,8 @@ mod text;
|
|
|
18
18
|
|
|
19
19
|
pub use context::{ContextHandle, Host, Unparker, WaitHandle, WaitOutcome};
|
|
20
20
|
pub use control::{CallRequest, CallbackReply, ContextConfig, JsText};
|
|
21
|
-
pub use error::{
|
|
21
|
+
pub use error::{
|
|
22
|
+
EngineError, FlagError, InvalidSnapshot, JsError, JsErrorKind, SourceMapError, TerminationCause,
|
|
23
|
+
};
|
|
22
24
|
pub use snapshot::{SnapshotBlob, WeakSnapshotBlob};
|
|
23
25
|
pub use text::{Decoded, Transcoder};
|
|
@@ -7,6 +7,7 @@ use mini_racer_sync::{ForkGate, Phase, lock};
|
|
|
7
7
|
|
|
8
8
|
use crate::control::ControlBlock;
|
|
9
9
|
use crate::process::code_cache::CodeCache;
|
|
10
|
+
use crate::process::source_maps::SourceMaps;
|
|
10
11
|
use crate::process::sources::Sources;
|
|
11
12
|
use crate::process::tasks::TaskRegistry;
|
|
12
13
|
use crate::process::watchdog::Watchdog;
|
|
@@ -53,13 +54,18 @@ pub struct Generation {
|
|
|
53
54
|
workers: Workers,
|
|
54
55
|
code_cache: CodeCache,
|
|
55
56
|
sources: Sources,
|
|
57
|
+
source_maps: SourceMaps,
|
|
56
58
|
next: OnceLock<Box<Self>>,
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
static ROOT: OnceLock<Generation> = OnceLock::new();
|
|
60
62
|
|
|
61
63
|
impl Generation {
|
|
62
|
-
fn new(
|
|
64
|
+
fn new(
|
|
65
|
+
epoch: u64,
|
|
66
|
+
quiesced: bool,
|
|
67
|
+
(code_cache, sources, source_maps): (CodeCache, Sources, SourceMaps),
|
|
68
|
+
) -> Self {
|
|
63
69
|
Self {
|
|
64
70
|
epoch,
|
|
65
71
|
quiesced,
|
|
@@ -72,6 +78,7 @@ impl Generation {
|
|
|
72
78
|
workers: Workers::default(),
|
|
73
79
|
code_cache,
|
|
74
80
|
sources,
|
|
81
|
+
source_maps,
|
|
75
82
|
next: OnceLock::new(),
|
|
76
83
|
}
|
|
77
84
|
}
|
|
@@ -102,6 +109,11 @@ impl Generation {
|
|
|
102
109
|
&self.sources
|
|
103
110
|
}
|
|
104
111
|
|
|
112
|
+
#[must_use]
|
|
113
|
+
pub const fn source_maps(&self) -> &SourceMaps {
|
|
114
|
+
&self.source_maps
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
pub fn register(&self, block: &Arc<ControlBlock>) {
|
|
106
118
|
let mut blocks = lock(&self.blocks);
|
|
107
119
|
blocks.retain(|block| block.strong_count() > 0);
|
|
@@ -123,8 +135,7 @@ impl Generation {
|
|
|
123
135
|
|
|
124
136
|
pub fn current() -> &'static Generation {
|
|
125
137
|
let epoch = epoch();
|
|
126
|
-
let mut generation =
|
|
127
|
-
ROOT.get_or_init(|| Generation::new(epoch, true, CodeCache::default(), Sources::default()));
|
|
138
|
+
let mut generation = ROOT.get_or_init(|| Generation::new(epoch, true, Default::default()));
|
|
128
139
|
while generation.epoch != epoch {
|
|
129
140
|
let quiesced = generation.quiesced && generation.prepared.load(Ordering::SeqCst);
|
|
130
141
|
let next = generation.epoch.saturating_add(1);
|
|
@@ -133,8 +144,11 @@ pub fn current() -> &'static Generation {
|
|
|
133
144
|
Box::new(Generation::new(
|
|
134
145
|
next,
|
|
135
146
|
quiesced,
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
(
|
|
148
|
+
parent.code_cache.inherited(),
|
|
149
|
+
parent.sources.inherited(),
|
|
150
|
+
parent.source_maps.inherited(),
|
|
151
|
+
),
|
|
138
152
|
))
|
|
139
153
|
});
|
|
140
154
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
2
|
+
use std::sync::{Arc, Mutex};
|
|
3
|
+
|
|
4
|
+
use mini_racer_sourcemap::{Placement, SourceMap};
|
|
5
|
+
use mini_racer_sync::lock;
|
|
6
|
+
|
|
7
|
+
use crate::error::SourceMapError;
|
|
8
|
+
|
|
9
|
+
/// Bundles with a source map, each parsed once.
|
|
10
|
+
pub const MAX_MAPS: usize = 8;
|
|
11
|
+
/// A bundle's fewest bytes. Shorter text could turn up inside unrelated
|
|
12
|
+
/// code, whose frames its map would then relocate; any real bundle is many
|
|
13
|
+
/// times longer, the smallest of the consumer bundles 90 KB.
|
|
14
|
+
pub const MIN_BUNDLE: usize = 1024;
|
|
15
|
+
|
|
16
|
+
/// Refuses a map too long to parse by its length alone, so a caller need not
|
|
17
|
+
/// copy it first.
|
|
18
|
+
pub fn check_length(length: usize) -> Result<(), SourceMapError> {
|
|
19
|
+
Ok(mini_racer_sourcemap::check_length(length)?)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// The source maps one process has registered, found by their bundle's
|
|
23
|
+
/// content: each kept once, parsed, and read by every context whose eval
|
|
24
|
+
/// holds its bundle.
|
|
25
|
+
#[derive(Default)]
|
|
26
|
+
pub struct SourceMaps {
|
|
27
|
+
maps: Mutex<Vec<Arc<SourceMap>>>,
|
|
28
|
+
// The shortest bundle's length, or 0 with none, so a source too short to
|
|
29
|
+
// hold any is passed over without the lock.
|
|
30
|
+
shortest: AtomicUsize,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
impl SourceMaps {
|
|
34
|
+
/// Parses `map` for `bundle` and keeps it, in place of the map an earlier
|
|
35
|
+
/// call gave the same bundle; past `MAX_MAPS` bundles, a new one is
|
|
36
|
+
/// refused.
|
|
37
|
+
#[expect(
|
|
38
|
+
clippy::significant_drop_tightening,
|
|
39
|
+
reason = "the shortest length is stored under the lock, so it never trails the list"
|
|
40
|
+
)]
|
|
41
|
+
pub fn register(&self, bundle: &str, map: &[u8]) -> Result<(), SourceMapError> {
|
|
42
|
+
if bundle.len() < MIN_BUNDLE {
|
|
43
|
+
return Err(SourceMapError::Short(MIN_BUNDLE));
|
|
44
|
+
}
|
|
45
|
+
let parsed = Arc::new(SourceMap::new(bundle, map)?);
|
|
46
|
+
// A child forked while this holds the lock starts with no maps, so it
|
|
47
|
+
// is held only to swap, and a map replaced is freed after.
|
|
48
|
+
let replaced = {
|
|
49
|
+
let mut maps = lock(&self.maps);
|
|
50
|
+
let replaced = if let Some(kept) = maps
|
|
51
|
+
.iter_mut()
|
|
52
|
+
.find(|kept| kept.bundle() == bundle.as_bytes())
|
|
53
|
+
{
|
|
54
|
+
Some(std::mem::replace(kept, parsed))
|
|
55
|
+
} else if maps.len() < MAX_MAPS {
|
|
56
|
+
maps.push(parsed);
|
|
57
|
+
None
|
|
58
|
+
} else {
|
|
59
|
+
return Err(SourceMapError::Full(MAX_MAPS));
|
|
60
|
+
};
|
|
61
|
+
let shortest = maps
|
|
62
|
+
.iter()
|
|
63
|
+
.map(|kept| kept.bundle().len())
|
|
64
|
+
.min()
|
|
65
|
+
.unwrap_or(0);
|
|
66
|
+
self.shortest.store(shortest, Ordering::Release);
|
|
67
|
+
replaced
|
|
68
|
+
};
|
|
69
|
+
drop(replaced);
|
|
70
|
+
Ok(())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// The registered map whose bundle `source` holds, the longest when it
|
|
74
|
+
/// holds several, as one bundle may hold another, and where it starts.
|
|
75
|
+
pub(crate) fn find(&self, source: &[u8]) -> Option<(Arc<SourceMap>, Placement)> {
|
|
76
|
+
let shortest = self.shortest.load(Ordering::Acquire);
|
|
77
|
+
if shortest == 0 || source.len() < shortest {
|
|
78
|
+
return None;
|
|
79
|
+
}
|
|
80
|
+
let mut maps = lock(&self.maps).clone();
|
|
81
|
+
maps.sort_by_key(|map| std::cmp::Reverse(map.bundle().len()));
|
|
82
|
+
maps.into_iter()
|
|
83
|
+
.find_map(|map| map.find(source).map(|placement| (map, placement)))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// A forked child's own list, from its parent's: try-locked, as a thread
|
|
87
|
+
// gone with the fork may have held it.
|
|
88
|
+
pub(crate) fn inherited(&self) -> Self {
|
|
89
|
+
let maps = self
|
|
90
|
+
.maps
|
|
91
|
+
.try_lock()
|
|
92
|
+
.map(|maps| maps.clone())
|
|
93
|
+
.unwrap_or_default();
|
|
94
|
+
let shortest = maps
|
|
95
|
+
.iter()
|
|
96
|
+
.map(|kept| kept.bundle().len())
|
|
97
|
+
.min()
|
|
98
|
+
.unwrap_or(0);
|
|
99
|
+
Self {
|
|
100
|
+
maps: Mutex::new(maps),
|
|
101
|
+
shortest: AtomicUsize::new(shortest),
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|