mini_racer-csim 0.21.1.1 → 0.21.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8674864924ab7e282736f327fc6bda583750e6cd3e61df57d4dd09005966812b
4
- data.tar.gz: 6e98c37b07f580c5b9ad2d5af887ec0a420ec95b2c4f58f929eb8aae031ca5ac
3
+ metadata.gz: 876af5088db34f57853916faa39e0568268bfcce946d44078a263de4f9e45867
4
+ data.tar.gz: 887bf5d80fd136be29e5f6243bc5fd3185b1020eee67002ae5c03176e75f3a85
5
5
  SHA512:
6
- metadata.gz: 72b2991b309086e5e089a1bb9e3a07517a417c6435444e457d1b5ca42ab095290b2c13f1559ac0c8c384794b240acaf063ca0691724dc9bd3647677bb8c88261
7
- data.tar.gz: 4b7ffa6b04dcca1c2771ef3993095a36210638a120b341eddde6e3615d9bccd3845d98c92271f58cd3d9671ba364442689df0792179963c8efab9815046e30db
6
+ metadata.gz: 365acff79cbaca1871707ea32e50d1d91dc7f15c23002e260449c1e1a553cb50c211fdb2406bc54b5bb40aa4e5848e915064891943b68dc8b4ca3ac02589a728
7
+ data.tar.gz: 48dec93bf2a431bedc18c6c7d5b79890d833db748b525bc5f19c22a796adcd6a0e045acf43d5ac9226a5094dbacf4bc5a48a0214dab71983fd993f930d1ce465
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ - 0.21.1.2 - 07-06-2026
2
+ - **Breaking:** move off the `mini_racer` require path / `MiniRacer` namespace to a fork-specific identity so the gem never collides with — and loads deterministically alongside — upstream `mini_racer` in the same bundle
3
+ - require path: `require 'mini_racer_csim'` (was `require 'mini_racer'`); the `require 'mini_racer-csim'` autorequire shim now points here
4
+ - Ruby namespace: `MiniRacerCsim` (was `MiniRacer`) — e.g. `MiniRacerCsim::Context`, `MiniRacerCsim::Snapshot`, `MiniRacerCsim::VERSION`
5
+ - native extensions: `mini_racer_csim_extension` / `mini_racer_csim_loader` (distinct `Init_` symbols and `.so` names)
6
+ - the JS-side host-namespace brand (`globalThis.MiniRacer` by default) is unchanged — it is embedder-chosen and independent of the Ruby namespace
7
+
1
8
  - 0.21.1.1 - 07-06-2026
2
9
  - Drop the TruffleRuby backend: mini_racer-csim is now a hard fork targeting CRuby/V8 only (the GraalJS/TruffleRuby shims and their tests are removed)
3
10
  - Add per-frame realms via `Context#create_realm`, returning a `MiniRacer::Realm` (multiple V8 realms in one isolate, browser-iframe semantics) with `Realm#eval` / `call` / `attach` / `dispose` / `disposed?`
data/README.md CHANGED
@@ -14,14 +14,14 @@ MiniRacer has an adapter for [execjs](https://github.com/rails/execjs) so it can
14
14
 
15
15
  This is **`mini_racer-csim`**, a private fork of [`mini_racer`](https://github.com/rubyjs/mini_racer) maintained for [capybara-simulated](https://github.com/ursm/capybara-simulated). It adds browser-fidelity extensions (ES modules, realm reset, …) that capybara-simulated needs but most users do not — **if you are not using capybara-simulated, use upstream `mini_racer`.**
16
16
 
17
- It stays a **drop-in replacement**: the gem is still loaded with `require "mini_racer"` and exposes the `MiniRacer` module, so existing code keeps working. Only the gem name (`mini_racer-csim`) differs.
17
+ It has its **own require path and namespace** so it never collides with — and loads deterministically alongside — upstream `mini_racer` in the same bundle: load it with `require 'mini_racer_csim'` and use the `MiniRacerCsim` module (e.g. `MiniRacerCsim::Context`). The native extensions are `mini_racer_csim_extension` / `mini_racer_csim_loader`. (The JS-side host-namespace brand, `globalThis.MiniRacer` by default, is embedder-chosen and unrelated to the Ruby namespace.)
18
18
 
19
19
  ### Additions over upstream
20
20
 
21
21
  | Feature | API | Notes |
22
22
  | --- | --- | --- |
23
23
  | Bytecode cache | `Context#compile(src, cached_data:, produce_cache:)` → `Script`, `Script#run`, `Script#cache_rejected?` | Cross-process V8 bytecode caching to skip parsing; see [Bytecode cache for repeated script evaluation](#bytecode-cache-for-repeated-script-evaluation) below |
24
- | ES Module API | `Context#compile_module` → `MiniRacer::Module` (`#instantiate` / `#evaluate` / `#namespace` / `#status` / `#cached_data` / `#dispose`); `Context#dynamic_import_resolver=` | V8's ES module pipeline, `import.meta.url`, dynamic `import()` |
24
+ | ES Module API | `Context#compile_module` → `MiniRacerCsim::Module` (`#instantiate` / `#evaluate` / `#namespace` / `#status` / `#cached_data` / `#dispose`); `Context#dynamic_import_resolver=` | V8's ES module pipeline, `import.meta.url`, dynamic `import()` |
25
25
  | Batched module-graph loader | `Context#load_module_graph(resolve:, …)` | Loads an ESM graph in one batched, native (C++) pass; one `Module` per URL shared across every load path |
26
26
  | Realm reset | `Context#reset_realm` | Discards the user realm (`globalThis`) while keeping the warm isolate (browser per-navigation model); re-binds attached host functions and the host namespace |
27
27
  | Host namespace | `Context.new(host_namespace: "MiniRacer")` → `globalThis.MiniRacer.drainMicrotasks()` | Opt-in JS namespace exposing an inline, rendezvous-free microtask checkpoint |
@@ -55,7 +55,7 @@ If you have a problem installing MiniRacer, please consider the following steps:
55
55
  You can simply eval one or many JavaScript snippets in a shared context
56
56
 
57
57
  ```ruby
58
- context = MiniRacer::Context.new
58
+ context = MiniRacerCsim::Context.new
59
59
  context.eval("var adder = (a,b)=>a+b;")
60
60
  puts context.eval("adder(20,22)")
61
61
  # => 42
@@ -66,14 +66,14 @@ puts context.eval("adder(20,22)")
66
66
  You can attach one or many ruby proc that can be accessed via JavaScript
67
67
 
68
68
  ```ruby
69
- context = MiniRacer::Context.new
69
+ context = MiniRacerCsim::Context.new
70
70
  context.attach("math.adder", proc{|a,b| a+b})
71
71
  puts context.eval("math.adder(20,22)")
72
72
  # => 42
73
73
  ```
74
74
 
75
75
  ```ruby
76
- context = MiniRacer::Context.new
76
+ context = MiniRacerCsim::Context.new
77
77
  context.attach("array_and_hash", proc{{a: 1, b: [1, {a: 1}]}})
78
78
  puts context.eval("array_and_hash()")
79
79
  # => {"a" => 1, "b" => [1, {"a" => 1}]}
@@ -81,14 +81,14 @@ puts context.eval("array_and_hash()")
81
81
 
82
82
  ### Return binary data from Ruby to JavaScript
83
83
 
84
- Attached Ruby functions can return binary data as `Uint8Array` using `MiniRacer::Binary`:
84
+ Attached Ruby functions can return binary data as `Uint8Array` using `MiniRacerCsim::Binary`:
85
85
 
86
86
  ```ruby
87
87
  require "digest"
88
88
 
89
- context = MiniRacer::Context.new
89
+ context = MiniRacerCsim::Context.new
90
90
  context.attach("sha256_raw", ->(data) {
91
- MiniRacer::Binary.new(Digest::SHA256.digest(data))
91
+ MiniRacerCsim::Binary.new(Digest::SHA256.digest(data))
92
92
  })
93
93
 
94
94
  # Inside JavaScript the return value is a Uint8Array
@@ -96,14 +96,14 @@ context.eval("sha256_raw('hello') instanceof Uint8Array") # => true
96
96
  context.eval("sha256_raw('hello').length") # => 32
97
97
  ```
98
98
 
99
- This is useful when you need to pass raw bytes (e.g., cryptographic digests, compressed data, binary file contents) from Ruby to JavaScript. The `MiniRacer::Binary` wrapper tells the bridge to serialize the data as a `Uint8Array` on the JavaScript side rather than a string.
99
+ This is useful when you need to pass raw bytes (e.g., cryptographic digests, compressed data, binary file contents) from Ruby to JavaScript. The `MiniRacerCsim::Binary` wrapper tells the bridge to serialize the data as a `Uint8Array` on the JavaScript side rather than a string.
100
100
 
101
101
  ### GIL free JavaScript execution
102
102
 
103
103
  The Ruby Global interpreter lock is released when scripts are executing:
104
104
 
105
105
  ```ruby
106
- context = MiniRacer::Context.new
106
+ context = MiniRacerCsim::Context.new
107
107
  Thread.new do
108
108
  sleep 1
109
109
  context.stop
@@ -119,7 +119,7 @@ This allows you to execute multiple scripts in parallel.
119
119
  Contexts can specify a default timeout for scripts
120
120
 
121
121
  ```ruby
122
- context = MiniRacer::Context.new(timeout: 1000)
122
+ context = MiniRacerCsim::Context.new(timeout: 1000)
123
123
  context.eval("while(true){}")
124
124
  # => exception is raised after 1 second (1000 ms)
125
125
  ```
@@ -130,7 +130,7 @@ Contexts can specify a memory softlimit for scripts
130
130
 
131
131
  ```ruby
132
132
  # terminates script if heap usage exceeds 200mb after V8 garbage collection has run
133
- context = MiniRacer::Context.new(max_memory: 200_000_000)
133
+ context = MiniRacerCsim::Context.new(max_memory: 200_000_000)
134
134
  context.eval("var a = new Array(10000); while(true) {a = a.concat(new Array(10000)) }")
135
135
  # => V8OutOfMemoryError is raised
136
136
  ```
@@ -140,24 +140,24 @@ context.eval("var a = new Array(10000); while(true) {a = a.concat(new Array(1000
140
140
  You can provide `filename:` to `#eval` which will be used in stack traces produced by V8:
141
141
 
142
142
  ```ruby
143
- context = MiniRacer::Context.new
143
+ context = MiniRacerCsim::Context.new
144
144
  context.eval("var foo = function() {bar();}", filename: "a/foo.js")
145
145
  context.eval("bar()", filename: "a/bar.js")
146
146
 
147
- # JavaScript at a/bar.js:1:1: ReferenceError: bar is not defined (MiniRacer::RuntimeError)
147
+ # JavaScript at a/bar.js:1:1: ReferenceError: bar is not defined (MiniRacerCsim::RuntimeError)
148
148
  # …
149
149
  ```
150
150
 
151
151
  ### Bytecode cache for repeated script evaluation
152
152
 
153
- `Context#compile` returns a `MiniRacer::Script` handle you can run multiple times,
153
+ `Context#compile` returns a `MiniRacerCsim::Script` handle you can run multiple times,
154
154
  and exposes V8's bytecode cache so subsequent Contexts can skip the parse step.
155
155
 
156
156
  In a single process — e.g. warming a `Context` pool from one canonical compile:
157
157
 
158
158
  ```ruby
159
159
  # Warm the cache once — top-level compile, opt in with produce_cache: true.
160
- warm = MiniRacer::Context.new
160
+ warm = MiniRacerCsim::Context.new
161
161
  warmed = warm.compile(File.read("bundle.js"),
162
162
  filename: "bundle.js",
163
163
  produce_cache: true)
@@ -165,7 +165,7 @@ warmed.run
165
165
  blob = warmed.cached_data # ASCII-8BIT String, hold onto it in memory
166
166
 
167
167
  # Subsequent Contexts (e.g. a per-request pool) consume the blob and skip parsing.
168
- ctx = MiniRacer::Context.new
168
+ ctx = MiniRacerCsim::Context.new
169
169
  script = ctx.compile(File.read("bundle.js"),
170
170
  filename: "bundle.js",
171
171
  cached_data: blob)
@@ -180,12 +180,12 @@ blob. Use `Snapshot#dump` / `Snapshot.load` to share canonical bytes:
180
180
 
181
181
  ```ruby
182
182
  # Build the snapshot once, persist its bytes.
183
- snap_bytes = MiniRacer::Snapshot.new(snapshot_src).dump
183
+ snap_bytes = MiniRacerCsim::Snapshot.new(snapshot_src).dump
184
184
  File.binwrite("snapshot.bin", snap_bytes)
185
185
 
186
186
  # Every process loads the same bytes.
187
- snap = MiniRacer::Snapshot.load(File.binread("snapshot.bin"))
188
- ctx = MiniRacer::Context.new(snapshot: snap)
187
+ snap = MiniRacerCsim::Snapshot.load(File.binread("snapshot.bin"))
188
+ ctx = MiniRacerCsim::Context.new(snapshot: snap)
189
189
  script = ctx.compile(File.read("bundle.js"),
190
190
  filename: "bundle.js",
191
191
  cached_data: File.binread("bundle.js.cache"))
@@ -198,14 +198,14 @@ callers can skip a redundant copy. When V8 produces a fresh blob (initial compil
198
198
  with `produce_cache: true`, or a rejection while `produce_cache: true` was also
199
199
  set), it returns the new bytes.
200
200
 
201
- `MiniRacer::V8_CACHED_DATA_VERSION_TAG` exposes V8's
201
+ `MiniRacerCsim::V8_CACHED_DATA_VERSION_TAG` exposes V8's
202
202
  `ScriptCompiler::CachedDataVersionTag()` — mix it into your cache key alongside
203
203
  the source hash so a libv8-node version bump invalidates stale blobs automatically.
204
204
  The constant is populated on first `Context.new` (after `Platform.set_flags!`),
205
205
  so read it after constructing at least one Context.
206
206
 
207
207
  ```ruby
208
- key = "#{Digest::SHA256.hexdigest(source)}-#{MiniRacer::V8_CACHED_DATA_VERSION_TAG}"
208
+ key = "#{Digest::SHA256.hexdigest(source)}-#{MiniRacerCsim::V8_CACHED_DATA_VERSION_TAG}"
209
209
  ```
210
210
 
211
211
  Notes:
@@ -218,11 +218,11 @@ Notes:
218
218
  `Context#dispose` clears them.
219
219
  - `produce_cache: true` is only safe at the top level. From inside a host-fn
220
220
  callback (i.e., re-entrant compile while a JS → Ruby → JS frame is on the
221
- stack) it raises `MiniRacer::RuntimeError`, because V8's `CreateCodeCache`
221
+ stack) it raises `MiniRacerCsim::RuntimeError`, because V8's `CreateCodeCache`
222
222
  walks live isolate state and corrupts the parser when re-entered. Warm the
223
223
  cache from the top level once and pass it back via `cached_data:` from your
224
224
  callbacks.
225
- - Cross-process reuse is **incompatible with `MiniRacer::Platform.set_flags!(:single_threaded)`**.
225
+ - Cross-process reuse is **incompatible with `MiniRacerCsim::Platform.set_flags!(:single_threaded)`**.
226
226
  V8's single-threaded mode embeds process-local state in the cache blob, so
227
227
  every cached_data is rejected when consumed in a fresh process. Same-process
228
228
  reuse still works under `:single_threaded`. If you need both cross-process
@@ -233,13 +233,13 @@ Notes:
233
233
 
234
234
  Some Ruby web servers employ forking (for example unicorn or puma in clustered mode). V8 is not fork safe by default and sadly Ruby does not have support for fork notifications per [#5446](https://bugs.ruby-lang.org/issues/5446).
235
235
 
236
- Since 0.6.1 mini_racer does support V8 single threaded platform mode which should remove most forking related issues. To enable run this before using `MiniRacer::Context`, for example in a Rails initializer:
236
+ Since 0.6.1 mini_racer does support V8 single threaded platform mode which should remove most forking related issues. To enable run this before using `MiniRacerCsim::Context`, for example in a Rails initializer:
237
237
 
238
238
  ```ruby
239
- MiniRacer::Platform.set_flags!(:single_threaded)
239
+ MiniRacerCsim::Platform.set_flags!(:single_threaded)
240
240
  ```
241
241
 
242
- When using pre-fork `MiniRacer::Context` objects in `:single_threaded` mode,
242
+ When using pre-fork `MiniRacerCsim::Context` objects in `:single_threaded` mode,
243
243
  ensure the process only forks while MiniRacer is quiescent: no thread may be
244
244
  evaluating JavaScript, calling into a context, disposing/freeing a context,
245
245
  running a Ruby callback from JavaScript, or otherwise using MiniRacer at the
@@ -250,14 +250,14 @@ in an unusable state in the child process.
250
250
 
251
251
  If you want to ensure your application does not leak memory after fork either:
252
252
 
253
- 1. Ensure no `MiniRacer::Context` objects are created in the master process; or
254
- 2. Dispose manually of all `MiniRacer::Context` objects prior to forking
253
+ 1. Ensure no `MiniRacerCsim::Context` objects are created in the master process; or
254
+ 2. Dispose manually of all `MiniRacerCsim::Context` objects prior to forking
255
255
 
256
256
  ```ruby
257
257
  # before fork
258
258
 
259
259
  require "objspace"
260
- ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
260
+ ObjectSpace.each_object(MiniRacerCsim::Context){|c| c.dispose}
261
261
 
262
262
  # fork here
263
263
  ```
@@ -267,7 +267,7 @@ ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
267
267
  Context usage is threadsafe
268
268
 
269
269
  ```ruby
270
- context = MiniRacer::Context.new
270
+ context = MiniRacerCsim::Context.new
271
271
  context.eval("counter=0; plus=()=>counter++;")
272
272
 
273
273
  (1..10).map do
@@ -285,9 +285,9 @@ puts context.eval("counter")
285
285
  Contexts can be created with pre-loaded snapshots:
286
286
 
287
287
  ```ruby
288
- snapshot = MiniRacer::Snapshot.new("function hello() { return 'world!'; }")
288
+ snapshot = MiniRacerCsim::Snapshot.new("function hello() { return 'world!'; }")
289
289
 
290
- context = MiniRacer::Context.new(snapshot: snapshot)
290
+ context = MiniRacerCsim::Context.new(snapshot: snapshot)
291
291
 
292
292
  context.eval("hello()")
293
293
  # => "world!"
@@ -309,11 +309,11 @@ Snapshots can come in handy for example if you want your contexts to be pre-load
309
309
  Also note that snapshots can be warmed up, using the `warmup!` method, which allows you to call functions which are otherwise lazily compiled to get them to compile right away; any side effect of your warm up code being then dismissed. [More details on warming up here](https://github.com/electron/electron/issues/169#issuecomment-76783481), and a small example:
310
310
 
311
311
  ```ruby
312
- snapshot = MiniRacer::Snapshot.new("var counter = 0; function hello() { counter++; return 'world! '; }")
312
+ snapshot = MiniRacerCsim::Snapshot.new("var counter = 0; function hello() { counter++; return 'world! '; }")
313
313
 
314
314
  snapshot.warmup!("hello()")
315
315
 
316
- context = MiniRacer::Context.new(snapshot: snapshot)
316
+ context = MiniRacerCsim::Context.new(snapshot: snapshot)
317
317
 
318
318
  context.eval("hello()")
319
319
  # => "world! 1"
@@ -325,13 +325,13 @@ Snapshots can also be persisted to disk for faster startup:
325
325
 
326
326
  ```ruby
327
327
  # Save a snapshot to disk
328
- snapshot = MiniRacer::Snapshot.new('var foo = "bar";')
328
+ snapshot = MiniRacerCsim::Snapshot.new('var foo = "bar";')
329
329
  File.binwrite("snapshot.bin", snapshot.dump)
330
330
 
331
331
  # Load it back in a later process
332
332
  blob = File.binread("snapshot.bin")
333
- snapshot = MiniRacer::Snapshot.load(blob)
334
- context = MiniRacer::Context.new(snapshot: snapshot)
333
+ snapshot = MiniRacerCsim::Snapshot.load(blob)
334
+ context = MiniRacerCsim::Context.new(snapshot: snapshot)
335
335
  context.eval("foo")
336
336
  # => "bar"
337
337
  ```
@@ -342,26 +342,26 @@ Note that snapshots are architecture and V8-version specific. A snapshot created
342
342
 
343
343
  ### Garbage collection
344
344
 
345
- You can make the garbage collector more aggressive by defining the context with `MiniRacer::Context.new(ensure_gc_after_idle: 1000)`. Using this will ensure V8 will run a full GC using `context.low_memory_notification` 1 second after the last eval on the context. Low memory notifications ensure long living contexts use minimal amounts of memory.
345
+ You can make the garbage collector more aggressive by defining the context with `MiniRacerCsim::Context.new(ensure_gc_after_idle: 1000)`. Using this will ensure V8 will run a full GC using `context.low_memory_notification` 1 second after the last eval on the context. Low memory notifications ensure long living contexts use minimal amounts of memory.
346
346
 
347
347
  ### V8 Runtime flags
348
348
 
349
349
  It is possible to set V8 Runtime flags:
350
350
 
351
351
  ```ruby
352
- MiniRacer::Platform.set_flags! :noconcurrent_recompilation, max_inlining_levels: 10
352
+ MiniRacerCsim::Platform.set_flags! :noconcurrent_recompilation, max_inlining_levels: 10
353
353
  ```
354
354
 
355
355
  This can come in handy if you want to use MiniRacer with Unicorn, which doesn't seem to always appreciate V8's liberal use of threading:
356
356
 
357
357
  ```ruby
358
- MiniRacer::Platform.set_flags! :noconcurrent_recompilation, :noconcurrent_sweeping
358
+ MiniRacerCsim::Platform.set_flags! :noconcurrent_recompilation, :noconcurrent_sweeping
359
359
  ```
360
360
 
361
361
  Or else to unlock experimental features in V8, for example tail recursion optimization:
362
362
 
363
363
  ```ruby
364
- MiniRacer::Platform.set_flags! :harmony
364
+ MiniRacerCsim::Platform.set_flags! :harmony
365
365
 
366
366
  js = <<-JS
367
367
  'use strict';
@@ -375,13 +375,13 @@ var f = function f(n){
375
375
  f(1e6);
376
376
  JS
377
377
 
378
- context = MiniRacer::Context.new
378
+ context = MiniRacerCsim::Context.new
379
379
 
380
380
  context.eval js
381
381
  # => "foo"
382
382
  ```
383
383
 
384
- The same code without the harmony runtime flag results in a `MiniRacer::RuntimeError: RangeError: Maximum call stack size exceeded` exception.
384
+ The same code without the harmony runtime flag results in a `MiniRacerCsim::RuntimeError: RangeError: Maximum call stack size exceeded` exception.
385
385
  Please refer to http://node.green/ as a reference on other harmony features.
386
386
 
387
387
  A list of all V8 runtime flags can be found using `node --v8-options`, or else by perusing [the V8 source code for flags (make sure to use the right version of V8)](https://github.com/v8/v8/blob/master/src/flags/flag-definitions.h).
@@ -400,7 +400,7 @@ Flags:
400
400
  When hosting v8 you may want to keep track of memory usage, use `#heap_stats` to get memory usage:
401
401
 
402
402
  ```ruby
403
- context = MiniRacer::Context.new
403
+ context = MiniRacerCsim::Context.new
404
404
  # use context
405
405
  p context.heap_stats
406
406
  # {:total_physical_size=>1280640,
@@ -413,11 +413,11 @@ p context.heap_stats
413
413
  If you wish to dispose of a context before waiting on the GC use `#dispose`:
414
414
 
415
415
  ```ruby
416
- context = MiniRacer::Context.new
416
+ context = MiniRacerCsim::Context.new
417
417
  context.eval("let a='testing';")
418
418
  context.dispose
419
419
  context.eval("a = 2")
420
- # MiniRacer::ContextDisposedError
420
+ # MiniRacerCsim::ContextDisposedError
421
421
 
422
422
  # nothing works on the context from now on, it's a shell waiting to be disposed
423
423
  ```
@@ -425,7 +425,7 @@ context.eval("a = 2")
425
425
  A MiniRacer context can also be dumped in a heapsnapshot file using `#write_heap_snapshot(file_or_io)`
426
426
 
427
427
  ```ruby
428
- context = MiniRacer::Context.new
428
+ context = MiniRacerCsim::Context.new
429
429
  # use context
430
430
  context.write_heap_snapshot("test.heapsnapshot")
431
431
  ```
@@ -437,7 +437,7 @@ This file can then be loaded in the "memory" tab of the [Chrome DevTools](https:
437
437
  This calls the function passed as first argument:
438
438
 
439
439
  ```ruby
440
- context = MiniRacer::Context.new
440
+ context = MiniRacerCsim::Context.new
441
441
  context.eval("function hello(name) { return `Hello, ${name}!` }")
442
442
  context.call("hello", "George")
443
443
  # "Hello, George!"
@@ -453,7 +453,7 @@ Performance is slightly better than running `context.eval("hello('George')")` si
453
453
  V8 drains its microtask queue (e.g. callbacks queued via `Promise.resolve().then(...)`) automatically when script execution returns to the embedder, so most code "just works":
454
454
 
455
455
  ```ruby
456
- context = MiniRacer::Context.new
456
+ context = MiniRacerCsim::Context.new
457
457
  context.eval(<<~JS)
458
458
  let x = 0;
459
459
  Promise.resolve().then(() => x = 99);
@@ -465,7 +465,7 @@ context.eval("x")
465
465
  When JavaScript invokes a Ruby callback synchronously and you need queued microtasks to drain mid-execution — e.g. for spec-compliant ordering across a chain of synchronous `dispatchEvent` listeners — call `context.perform_microtask_checkpoint` from the callback:
466
466
 
467
467
  ```ruby
468
- context = MiniRacer::Context.new
468
+ context = MiniRacerCsim::Context.new
469
469
  context.attach("drain", -> { context.perform_microtask_checkpoint })
470
470
  context.eval(<<~JS)
471
471
  globalThis.log = [];
@@ -485,7 +485,7 @@ When the drain has to happen from within JavaScript itself — for example betwe
485
485
  It is exposed through an opt-in **host namespace** — a single object (in the spirit of Deno's `Deno` or Bun's `Bun`) that mini_racer hangs its non-standard helpers off. Pass `host_namespace:` to enable it; by default nothing is injected and the global stays clean:
486
486
 
487
487
  ```ruby
488
- context = MiniRacer::Context.new(host_namespace: "MiniRacer")
488
+ context = MiniRacerCsim::Context.new(host_namespace: "MiniRacer")
489
489
  context.eval(<<~JS)
490
490
  globalThis.log = [];
491
491
  Promise.resolve().then(() => log.push("microtask"));
@@ -507,7 +507,7 @@ syntax), modules can have static imports that resolve to other modules and
507
507
  expose named exports through a real Module Namespace Object.
508
508
 
509
509
  ```ruby
510
- context = MiniRacer::Context.new
510
+ context = MiniRacerCsim::Context.new
511
511
 
512
512
  dep = context.compile_module("export const base = 10", filename: "dep.js")
513
513
  main = context.compile_module(<<~JS, filename: "main.js")
@@ -523,18 +523,18 @@ main.namespace # => {"doubled" => 20}
523
523
  ```
524
524
 
525
525
  * `Context#compile_module(source, filename:)` — parses the source as a
526
- module; the returned `MiniRacer::Module` is bound to its Context. The
526
+ module; the returned `MiniRacerCsim::Module` is bound to its Context. The
527
527
  `filename` is also exposed to the module as `import.meta.url`.
528
528
  * `Module#instantiate { |specifier, referrer_url| ... }` — walks the static
529
529
  import graph. The resolver block is called once per import declaration
530
530
  with the raw specifier string and the importing module's filename, so
531
531
  relative specifiers (`./foo`, `../bar`) can be resolved against the
532
- referrer. It must return another `MiniRacer::Module` (typically from a
532
+ referrer. It must return another `MiniRacerCsim::Module` (typically from a
533
533
  per-Context cache). Imports can also be resolved lazily from inside the
534
534
  block via further `Context#compile_module` calls.
535
535
  * `Module#evaluate` — runs the module body. Returns the evaluation result
536
536
  (`nil` for the typical `export const …` shape). Modules with top-level
537
- `await` raise `MiniRacer::RuntimeError` for now.
537
+ `await` raise `MiniRacerCsim::RuntimeError` for now.
538
538
  * `Module#namespace` — returns the Module Namespace Object as a Hash
539
539
  (`{ "default" => …, "namedExport" => … }`). Available after
540
540
  `instantiate` succeeds; `evaluate` populates the values.
@@ -544,7 +544,7 @@ main.namespace # => {"doubled" => 20}
544
544
  the convention used elsewhere.
545
545
  * `Context#dynamic_import_resolver = proc { |specifier, referrer_url| ... }`
546
546
  — handler for JS `import(...)` expressions. The proc must return a
547
- `MiniRacer::Module` (already instantiated; `evaluate` is driven for you
547
+ `MiniRacerCsim::Module` (already instantiated; `evaluate` is driven for you
548
548
  if pending). Set to `nil` to reject all dynamic imports. Drain the
549
549
  microtask queue with `Context#perform_microtask_checkpoint` to see the
550
550
  result in a `.then` callback or after `await`.
@@ -1,9 +1,9 @@
1
1
  require 'mkmf'
2
2
 
3
- $srcs = ["mini_racer_extension.c", "mini_racer_v8.cc"]
3
+ $srcs = ["mini_racer_csim_extension.c", "mini_racer_v8.cc"]
4
4
 
5
- require_relative '../../lib/mini_racer/version'
6
- gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
5
+ require_relative '../../lib/mini_racer_csim/version'
6
+ gem 'libv8-node', MiniRacerCsim::LIBV8_NODE_VERSION
7
7
  require 'libv8-node'
8
8
 
9
9
  IS_DARWIN = RUBY_PLATFORM =~ /darwin/
@@ -67,4 +67,4 @@ if RUBY_ENGINE == 'ruby'
67
67
  $CPPFLAGS += ' -DENGINE_IS_CRUBY '
68
68
  end
69
69
 
70
- create_makefile 'mini_racer_extension'
70
+ create_makefile 'mini_racer_csim_extension'
@@ -1132,7 +1132,7 @@ static VALUE rendezvous_resolve_do(VALUE arg)
1132
1132
  rb_raise(runtime_error, "module resolver requested but no resolver block is active");
1133
1133
  ret = rb_funcall(c->resolve_block, rb_intern("call"), 2, specifier, referrer_url);
1134
1134
  if (!rb_obj_is_kind_of(ret, module_class))
1135
- rb_raise(runtime_error, "module resolver must return a MiniRacer::Module, got %s",
1135
+ rb_raise(runtime_error, "module resolver must return a MiniRacerCsim::Module, got %s",
1136
1136
  rb_obj_classname(ret));
1137
1137
  TypedData_Get_Struct(ret, Module, &module_type, m);
1138
1138
  if (m->disposed)
@@ -1214,7 +1214,7 @@ static VALUE rendezvous_dynamic_import_do(VALUE arg)
1214
1214
  specifier, referrer_url);
1215
1215
  if (!rb_obj_is_kind_of(ret, module_class))
1216
1216
  rb_raise(runtime_error,
1217
- "dynamic import resolver must return a MiniRacer::Module, got %s",
1217
+ "dynamic import resolver must return a MiniRacerCsim::Module, got %s",
1218
1218
  rb_obj_classname(ret));
1219
1219
  TypedData_Get_Struct(ret, Module, &module_type, m);
1220
1220
  if (m->disposed)
@@ -1289,7 +1289,7 @@ static VALUE rendezvous_graph_fetch_do(VALUE arg)
1289
1289
  VALUE ret = rb_funcall(c->graph_fetch_block, rb_intern("call"), 1, urls);
1290
1290
  // The cached_data element is an ASCII-8BIT String (same shape as
1291
1291
  // Module#cached_data / compile_module(cached_data:)). Wrap it as
1292
- // MiniRacer::Binary so it crosses to V8 as a Uint8Array — a bare String
1292
+ // MiniRacerCsim::Binary so it crosses to V8 as a Uint8Array — a bare String
1293
1293
  // would serialize as a JS string and the code cache would be silently
1294
1294
  // dropped (and binary bytes mangled by UTF-8). Build fresh rows rather than
1295
1295
  // mutating the array the caller's block returned.
@@ -1577,7 +1577,7 @@ static VALUE context_alloc(VALUE klass)
1577
1577
  date_time_class = rb_const_get(rb_cObject, rb_intern("DateTime"));
1578
1578
  }
1579
1579
  if (NIL_P(binary_class)) {
1580
- VALUE m = rb_const_get(rb_cObject, rb_intern("MiniRacer"));
1580
+ VALUE m = rb_const_get(rb_cObject, rb_intern("MiniRacerCsim"));
1581
1581
  if (Qtrue == rb_funcall(m, rb_intern("const_defined?"), 1, rb_str_new_cstr("Binary")))
1582
1582
  binary_class = rb_const_get(m, rb_intern("Binary"));
1583
1583
  }
@@ -1922,7 +1922,7 @@ static VALUE context_reset_realm(VALUE self)
1922
1922
  return Qnil;
1923
1923
  }
1924
1924
 
1925
- // -- MiniRacer::Realm (per-frame realm = extra v8::Context in this isolate) --
1925
+ // -- MiniRacerCsim::Realm (per-frame realm = extra v8::Context in this isolate) --
1926
1926
 
1927
1927
  static void realm_free(void *arg)
1928
1928
  {
@@ -1953,7 +1953,7 @@ static VALUE realm_alloc(VALUE klass)
1953
1953
  static VALUE realm_initialize(int argc, VALUE *argv, VALUE self)
1954
1954
  {
1955
1955
  (void)argc; (void)argv; (void)self;
1956
- rb_raise(runtime_error, "MiniRacer::Realm must be created via Context#create_realm");
1956
+ rb_raise(runtime_error, "MiniRacerCsim::Realm must be created via Context#create_realm");
1957
1957
  }
1958
1958
 
1959
1959
  // Resolve the parent Context, raising if the realm or its context is disposed.
@@ -2351,7 +2351,7 @@ init:
2351
2351
  {
2352
2352
  static int version_tag_defined;
2353
2353
  if (!version_tag_defined) {
2354
- VALUE m = rb_const_get(rb_cObject, rb_intern("MiniRacer"));
2354
+ VALUE m = rb_const_get(rb_cObject, rb_intern("MiniRacerCsim"));
2355
2355
  rb_define_const(m, "V8_CACHED_DATA_VERSION_TAG",
2356
2356
  UINT2NUM(v8_cached_data_version_tag()));
2357
2357
  version_tag_defined = 1;
@@ -2587,7 +2587,7 @@ static size_t script_size(const void *arg)
2587
2587
  static VALUE script_initialize(int argc, VALUE *argv, VALUE self)
2588
2588
  {
2589
2589
  (void)argc; (void)argv; (void)self;
2590
- rb_raise(runtime_error, "MiniRacer::Script must be created via Context#compile");
2590
+ rb_raise(runtime_error, "MiniRacerCsim::Script must be created via Context#compile");
2591
2591
  return Qnil;
2592
2592
  }
2593
2593
 
@@ -2764,7 +2764,7 @@ static size_t module_size(const void *arg)
2764
2764
  static VALUE module_initialize(int argc, VALUE *argv, VALUE self)
2765
2765
  {
2766
2766
  (void)argc; (void)argv; (void)self;
2767
- rb_raise(runtime_error, "MiniRacer::Module must be created via Context#compile_module");
2767
+ rb_raise(runtime_error, "MiniRacerCsim::Module must be created via Context#compile_module");
2768
2768
  return Qnil;
2769
2769
  }
2770
2770
 
@@ -3034,7 +3034,7 @@ static VALUE context_get_dynamic_import_resolver(VALUE self)
3034
3034
  }
3035
3035
 
3036
3036
  __attribute__((visibility("default")))
3037
- void Init_mini_racer_extension(void)
3037
+ void Init_mini_racer_csim_extension(void)
3038
3038
  {
3039
3039
  VALUE c, m;
3040
3040
 
@@ -3042,7 +3042,7 @@ void Init_mini_racer_extension(void)
3042
3042
  id_cached_data = rb_intern("cached_data");
3043
3043
  id_produce_cache = rb_intern("produce_cache");
3044
3044
 
3045
- m = rb_define_module("MiniRacer");
3045
+ m = rb_define_module("MiniRacerCsim");
3046
3046
  c = rb_define_class_under(m, "Error", rb_eStandardError);
3047
3047
  snapshot_error = rb_define_class_under(m, "SnapshotError", c);
3048
3048
  platform_init_error = rb_define_class_under(m, "PlatformAlreadyInitialized", c);
@@ -461,7 +461,7 @@ static bool module_trace_on()
461
461
  }
462
462
 
463
463
  // V8 calls this for every JS `import(...)` expression. We rendezvous to
464
- // Ruby (marker 'd'), expect a fully-instantiated MiniRacer::Module back,
464
+ // Ruby (marker 'd'), expect a fully-instantiated MiniRacerCsim::Module back,
465
465
  // evaluate it if still pending, then resolve the returned Promise with
466
466
  // its namespace. The contract requires the embedder to handle compile +
467
467
  // instantiate + evaluate; Ruby's resolver is responsible for the first
@@ -593,7 +593,7 @@ static v8::MaybeLocal<v8::Promise> host_import_module_dynamically_callback(
593
593
  }
594
594
  } else {
595
595
  // Legacy path: the embedder's dynamic_import_resolver returns a
596
- // fully-instantiated MiniRacer::Module (looked up by handle id).
596
+ // fully-instantiated MiniRacerCsim::Module (looked up by handle id).
597
597
  v8::Local<v8::Array> request;
598
598
  {
599
599
  v8::Context::Scope context_scope(st.safe_context);
@@ -18,13 +18,13 @@ enum
18
18
 
19
19
  static const uint16_t js_function_marker[] = {0xBFF,'J','a','v','a','S','c','r','i','p','t','F','u','n','c','t','i','o','n'};
20
20
 
21
- // defined in mini_racer_extension.c, opaque to mini_racer_v8.cc
21
+ // defined in mini_racer_csim_extension.c, opaque to mini_racer_v8.cc
22
22
  struct Context;
23
23
 
24
- // defined in mini_racer_v8.cc, opaque to mini_racer_extension.c
24
+ // defined in mini_racer_v8.cc, opaque to mini_racer_csim_extension.c
25
25
  struct State;
26
26
 
27
- // defined in mini_racer_extension.c
27
+ // defined in mini_racer_csim_extension.c
28
28
  extern int single_threaded;
29
29
  void v8_get_flags(char **p, size_t *n);
30
30
  void v8_thread_main(struct Context *c, struct State *pst);
@@ -1,6 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
- extension_name = 'mini_racer_loader'
3
+ extension_name = 'mini_racer_csim_loader'
4
4
  dir_config extension_name
5
5
 
6
6
  $CXXFLAGS += " -fvisibility=hidden "
@@ -8,7 +8,7 @@
8
8
  // a) hide symbols from other extensions (RTLD_LOCAL)
9
9
  // b) bind symbols tightly (RTLD_DEEPBIND, when available)
10
10
 
11
- void Init_mini_racer_loader(void);
11
+ void Init_mini_racer_csim_loader(void);
12
12
 
13
13
  static void *_dln_load(const char *file);
14
14
 
@@ -115,9 +115,9 @@ failed:
115
115
  rb_raise(rb_eLoadError, "%s", error);
116
116
  }
117
117
 
118
- __attribute__((visibility("default"))) void Init_mini_racer_loader(void)
118
+ __attribute__((visibility("default"))) void Init_mini_racer_csim_loader(void)
119
119
  {
120
- VALUE mMiniRacer = rb_define_module("MiniRacer");
120
+ VALUE mMiniRacer = rb_define_module("MiniRacerCsim");
121
121
  VALUE mLoader = rb_define_module_under(mMiniRacer, "Loader");
122
122
  rb_define_singleton_method(mLoader, "load", _load_shared_lib, 1);
123
123
  }
@@ -1,4 +1,5 @@
1
- # This gem is published as `mini_racer-csim`, but its implementation lives in
2
- # `mini_racer` (it is a drop-in fork). This shim lets `require 'mini_racer-csim'`
3
- # — e.g. Bundler's autorequire for the gem name — load the library.
4
- require 'mini_racer'
1
+ # This gem is published as `mini_racer-csim`; its implementation lives under the
2
+ # `mini_racer_csim` require path (and the `MiniRacerCsim` namespace). This shim
3
+ # lets `require 'mini_racer-csim'` — e.g. Bundler's autorequire for the gem name
4
+ # — load the library.
5
+ require 'mini_racer_csim'
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MiniRacer
3
+ module MiniRacerCsim
4
4
  # mini_racer-csim fork: upstream version + a fork revision segment.
5
5
  # 0.21.1.0 = first fork release on upstream 0.21.1; bump the 4th segment for
6
6
  # fork-only changes, reset it when rebasing onto a new upstream version.
7
- VERSION = "0.21.1.1"
7
+ VERSION = "0.21.1.2"
8
8
  LIBV8_NODE_VERSION = "~> 24.12.0.1"
9
9
  end
@@ -1,7 +1,7 @@
1
- require "mini_racer/version"
1
+ require "mini_racer_csim/version"
2
2
  require "pathname"
3
3
 
4
- module MiniRacer
4
+ module MiniRacerCsim
5
5
  class Binary
6
6
  attr_reader :data
7
7
 
@@ -12,16 +12,18 @@ module MiniRacer
12
12
  end
13
13
  end
14
14
 
15
- # mini_racer-csim is a hard fork: V8 (CRuby C extension) only. The TruffleRuby
16
- # backend was dropped see lib/mini_racer/truffleruby.rb in upstream history.
15
+ # mini_racer-csim is a hard fork of mini_racer with its own require path and
16
+ # `MiniRacerCsim` namespace (and `mini_racer_csim_*` C extensions), so it never
17
+ # collides with — and loads deterministically alongside — upstream mini_racer.
18
+ # V8 (CRuby C extension) only; the TruffleRuby backend was dropped.
17
19
  if ENV["LD_PRELOAD"].to_s.include?("malloc")
18
- require "mini_racer_extension"
20
+ require "mini_racer_csim_extension"
19
21
  else
20
- require "mini_racer_loader"
21
- ext_filename = "mini_racer_extension.#{RbConfig::CONFIG["DLEXT"]}"
22
- # This is the mini_racer-csim fork; fall back to the upstream name and then
23
- # to the default require_paths so the extension is found however we're loaded.
24
- spec = Gem.loaded_specs["mini_racer-csim"] || Gem.loaded_specs["mini_racer"]
22
+ require "mini_racer_csim_loader"
23
+ ext_filename = "mini_racer_csim_extension.#{RbConfig::CONFIG["DLEXT"]}"
24
+ # Resolve the extension from the gem's own require_paths, falling back to the
25
+ # default lib/ext layout so it is found however we're loaded.
26
+ spec = Gem.loaded_specs["mini_racer-csim"]
25
27
  ext_path =
26
28
  (spec ? spec.require_paths : %w[lib ext]).map do |p|
27
29
  (p = Pathname.new(p)).absolute? ? p : Pathname.new(__dir__).parent + p
@@ -32,14 +34,14 @@ else
32
34
  raise LoadError,
33
35
  "Could not find #{ext_filename} in #{ext_path.map(&:to_s)}"
34
36
  end
35
- MiniRacer::Loader.load(ext_found.to_s)
37
+ MiniRacerCsim::Loader.load(ext_found.to_s)
36
38
  end
37
39
 
38
40
  require "thread"
39
41
  require "json"
40
42
  require "io/wait"
41
43
 
42
- module MiniRacer
44
+ module MiniRacerCsim
43
45
  class Error < ::StandardError; end
44
46
 
45
47
  class ContextDisposedError < Error; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_racer-csim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.1.1
4
+ version: 0.21.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima
@@ -119,24 +119,24 @@ email:
119
119
  - ursm@ursm.jp
120
120
  executables: []
121
121
  extensions:
122
- - ext/mini_racer_loader/extconf.rb
123
- - ext/mini_racer_extension/extconf.rb
122
+ - ext/mini_racer_csim_loader/extconf.rb
123
+ - ext/mini_racer_csim_extension/extconf.rb
124
124
  extra_rdoc_files: []
125
125
  files:
126
126
  - CHANGELOG
127
127
  - CODE_OF_CONDUCT.md
128
128
  - LICENSE.txt
129
129
  - README.md
130
- - ext/mini_racer_extension/extconf.rb
131
- - ext/mini_racer_extension/mini_racer_extension.c
132
- - ext/mini_racer_extension/mini_racer_v8.cc
133
- - ext/mini_racer_extension/mini_racer_v8.h
134
- - ext/mini_racer_extension/serde.c
135
- - ext/mini_racer_loader/extconf.rb
136
- - ext/mini_racer_loader/mini_racer_loader.c
130
+ - ext/mini_racer_csim_extension/extconf.rb
131
+ - ext/mini_racer_csim_extension/mini_racer_csim_extension.c
132
+ - ext/mini_racer_csim_extension/mini_racer_v8.cc
133
+ - ext/mini_racer_csim_extension/mini_racer_v8.h
134
+ - ext/mini_racer_csim_extension/serde.c
135
+ - ext/mini_racer_csim_loader/extconf.rb
136
+ - ext/mini_racer_csim_loader/mini_racer_csim_loader.c
137
137
  - lib/mini_racer-csim.rb
138
- - lib/mini_racer.rb
139
- - lib/mini_racer/version.rb
138
+ - lib/mini_racer_csim.rb
139
+ - lib/mini_racer_csim/version.rb
140
140
  homepage: https://github.com/ursm/mini_racer
141
141
  licenses:
142
142
  - MIT