rusty_racer 0.2.8 → 0.2.9

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: 6eedc8d154897325a2990e5ed6999a368b7c81c64528d5d406ed469e5d808fc4
4
- data.tar.gz: f0c356c5b22a4574323e7efe73c56bd07267d5428438d22dadf2c4a08953b468
3
+ metadata.gz: f657d7e0bf40a9fcdfc7971e504af9b531d59113c5fff89276e54fba10649c08
4
+ data.tar.gz: 8ba306b2a46d0e0d497a2d7aa599368461ae8da2f5980261512cb2eda48312a3
5
5
  SHA512:
6
- metadata.gz: 02acd6e295f14544a9f146f0b916ac1ac585b63634bb12c353d39059dc7ffef50337e76cd81c318463060c2e8f901a19667f384cbd1967ed776290dfd1d7c0cb
7
- data.tar.gz: bc2513ed51e0a7ed2c45bc4c8cc85a051a7d83f9d1cdc56675cc2e1a3fcfd915c7b77bede14f91ac10e475d877e43563cea38c734d5cab36a2be6b806200312c
6
+ metadata.gz: 496393f627fd387d9c32fd994a857abc24fcd732e8457fc991446f036cce01a26b7e05925b5d55384c59577de2364c8308b142ddd163170fd0534f7df6bb18c2
7
+ data.tar.gz: 72ee79e9052d1fd6c0608dff42b978d5511b782af1ac17f250f8543be7a3dcd3c0f3364e5bc1ae917640d89794411bba0e5f0b72820bd68416d192cce23d9fb8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.9
4
+
5
+ ### Added
6
+
7
+ - **The host answers `import()`, now or later.** `Isolate#dynamic_import_handler=`
8
+ takes a proc handed a `RustyRacer::DynamicImport` per `import()` — its
9
+ `specifier`, `attributes` (the `with` options' import attributes),
10
+ `referrer`, `host_defined` and `context` — whose promise waits until the host
11
+ settles it, inside the handler or on any later turn: `#resolve(module)` links
12
+ the module (by the block it is given, as `Module#instantiate`'s) and evaluates
13
+ it, `#reject(value)` rejects with a marshalled value, and
14
+ `#reject_with(path, *args)` with what a function of the realm makes — an error
15
+ of the host's own kind, from an `@` path no page reaches. Each answers whether
16
+ the import was still waiting; one whose realm was reset or disposed is not.
17
+ - **Import attributes** reach the resolve block of `Module#instantiate` (a third
18
+ argument, `{"type" => "json"}`), and `Module#requests` lists a module's
19
+ requests with theirs without linking it.
20
+ - **`Module#script_id`**: the id V8's stack frames name the module's code by
21
+ (nil for a synthetic or errored module), so an embedder walking the stack
22
+ (an embedder linking rusty_racer reads `StackFrame::GetScriptId`) can tell
23
+ which module script is running — HTML's active script, say. **`Script#script_id`**
24
+ is a classic script's. Modules or scripts V8's compilation cache shares (one
25
+ source under one filename) share the id.
26
+ - **Synthetic modules:** `Context#synthetic_module(value)`, `(json: text)` —
27
+ ECMA-262's JSON module, parsed by the realm's own `JSON.parse` whatever a page
28
+ made of the global — and `(call: [path, *args])` make a module exporting
29
+ `default` alone.
30
+ - **`host_defined:`** on `Context#compile` and `#compile_module`: a primitive the
31
+ script's origin carries, handed to the `import()`s it makes
32
+ (`DynamicImport#host_defined`) and to its realm's import-meta handler.
33
+ - **`NS.setImportMetaHandler(fn)`**: the realm's `fn(meta, url, hostDefined)`
34
+ fills a module's `import.meta` beyond `url` as it is first read —
35
+ `import.meta.resolve`, for one.
36
+
37
+ ### Changed
38
+
39
+ - `Isolate#dynamic_import_resolver=` is a `dynamic_import_handler` that resolves
40
+ each `import()` at once. A resolver that returns `nil` rejects the import with
41
+ an `Error` naming its specifier, an import made outside any named script hands
42
+ it `""` as its referrer, and `nil` clears it. An `import()` called by a
43
+ function of a realm reset or disposed since rejects, rather than resolving in
44
+ the realm that took its id.
45
+ - A two-parameter lambda as a resolve block is still handed two arguments, one
46
+ with an optional or rest parameter as many as it takes.
47
+ - A resolver that raises rejects the `import()` with an `Error` of its own
48
+ message (it was a generic "import() was not resolved to a module").
49
+ - The attributes a resolve block is handed (and `Module#requests` lists) are
50
+ frozen Hashes.
51
+ - `host_defined:` refuses a Symbol (`ArgumentError`), as it refuses any value
52
+ that is no Integer, Float, String, true or false.
53
+ - A `Context` wrapper of an extra realm reads `disposed?` once that realm is
54
+ disposed through any wrapper — `DynamicImport#context`'s too — and refuses
55
+ operations as a disposed one does.
56
+
3
57
  ## 0.2.8
4
58
 
5
59
  ### Added
data/README.md CHANGED
@@ -242,6 +242,53 @@ exception"), at once for a throw and as it settles for an `await`:
242
242
 
243
243
  Classic `<script>`s work the same way: `ctx.compile("1 + 1").run` # => 2.
244
244
 
245
+ The resolve block is handed each request's import attributes too —
246
+ `{ |specifier, referrer, attributes| … }`, `{"type" => "json"}` for
247
+ `import x from "./x.json" with { type: "json" }` — and `app.requests` lists them
248
+ without linking: `[["./dep.js", {}]]`.
249
+
250
+ A module whose value the host makes — HTML's JSON, CSS and text module scripts —
251
+ is a *synthetic* module exporting `default` alone:
252
+
253
+ ```ruby
254
+ ctx.synthetic_module("some text", filename: "/a.txt") # a Ruby value
255
+ ctx.synthetic_module(json: '{"a": 1}', filename: "/a.json") # %JSON.parse% (ParseError if it is no JSON)
256
+ ctx.synthetic_module(call: ["@makeSheet", css], filename: "/a.css") # what a function returns
257
+ ```
258
+
259
+ `import()` is the host's to answer, now or later: the isolate's
260
+ `dynamic_import_handler` is handed a `RustyRacer::DynamicImport` per call —
261
+ `specifier`, `attributes`, `referrer` (the calling script's filename),
262
+ `host_defined` (the value that script was compiled with: `compile` /
263
+ `compile_module` take `host_defined:`, a primitive, to tell scripts of one name
264
+ apart) and `context` (the realm it was called in) — and its promise waits until
265
+ the host settles it, on whatever later turn its fetch lands:
266
+
267
+ ```ruby
268
+ iso.dynamic_import_handler = ->(import) { pending << import } # start a fetch, return
269
+ # … later:
270
+ import.resolve(mod) { |specifier, referrer, attributes| dep } # linked (by the block) and evaluated
271
+ import.reject_with("@steps.typeError", "no such module") # rejected with what a function makes
272
+ import.reject(42) # … or with a value
273
+ ```
274
+
275
+ Whatever leaves the handler other than by returning — an exception, an
276
+ `Interrupt` or a `Timeout` too — rejects the `import()` with its message (unless
277
+ the handler settled it first) and goes no further. A module still evaluating
278
+ (an `import()` of itself settled from inside its handler) rejects as busy:
279
+ settle such a one on a later turn. An evaluation that is terminated raises
280
+ `ScriptTerminatedError` from `resolve` and leaves the promise pending. Code an
281
+ `eval` / `new Function` compiles carries its script's `host_defined:` value, but
282
+ V8 caches it by source, so another script's identical source may keep the first
283
+ one's.
284
+
285
+ `dynamic_import_resolver = ->(specifier, referrer, context) { module }` remains,
286
+ answering each `import()` at once. A realm's `import.meta` gets its `url`; a
287
+ namespace's `setImportMetaHandler(fn)` adds whatever else the host makes —
288
+ `fn(meta, url, hostDefined)` is called as a module of that realm first reads it,
289
+ `import.meta.resolve` for one.
290
+
291
+
245
292
  ### Resource limits
246
293
 
247
294
  An isolate can cap untrusted code on both axes. Each limit terminates the
@@ -335,7 +382,7 @@ Also available:
335
382
  never fires. It drains every pending task without blocking, then a microtask
336
383
  checkpoint; with nothing pending it is a no-op. The callbacks are ordinary JS,
337
384
  so the pump is capped by `timeout_ms` like an `eval`.
338
- - **`Isolate#terminate`**, **`Isolate#dynamic_import_resolver=`**,
385
+ - **`Isolate#terminate`**, **`Isolate#dynamic_import_handler=`** / **`#dynamic_import_resolver=`**,
339
386
  **`Context#reset`** (below), and **`Platform.set_flags!`**.
340
387
 
341
388
  ### `Context#reset`
@@ -5,7 +5,7 @@
5
5
  # links and loads with no custom archive.
6
6
  [package]
7
7
  name = "rusty_racer"
8
- version = "0.2.8"
8
+ version = "0.2.9"
9
9
  edition = "2024"
10
10
  publish = false
11
11