@threadedstack/wmd-web 0.1.44 → 0.1.46

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.
package/README.md CHANGED
@@ -3022,6 +3022,6 @@ attributes the guest has seen across a cache drop (the page's `ck.dropNames()`),
3022
3022
 
3023
3023
  ## The Go compiler's Wasm twin (X6; off until a base url is set)
3024
3024
 
3025
- An embedder does nothing to get the twin: update the package and call `containerBundle` and `bootWmd` as before, with no line of twin code. `bootWmd` reads the pins (`src/gowasm/pins-data.js`, a JS module that ships in the package, no request), adds the stub mounts to the bundle's spec and sets the service's `gowasm` field from it; the image decides (an image with no Go compile, or a Go release with no pin, runs as before and downloads nothing). The twin's module (41 to 53 MB per Go release) is fetched by the twin's Worker on first use from an ordered list of sources (`GOWASM_SOURCES_DEFAULT` in `src/gowasm/setup.js`: the npm registry, then jsDelivr, then unpkg; `gowasm: false` turns the twin off): the first that gives the pinned sha256 and size wins, a source that fails, stalls, is too big, refuses the file or has a wrong hash is left for the next (jsDelivr refuses files over 50 MB, so for the largest twin the working sources are the registry tarball and unpkg: each release needs only one source that works), and when all fail the guest compiles, with one `gowasm-off` event that names each source. Source kinds: `{ kind: 'tgz', url }` (an npm registry tarball) and `{ kind: 'file', base }` (`<base>/<file>`); only the pins name the package. The module is kept in Cache Storage of the page's origin under a key that holds its hash (checked again at each boot). What a consumer may pass to `bootWmd`: `gowasm: false` (off), `gowasm: { sources: [...] }`, `gowasm: { base: 'https://.../gowasm' }` (the override for an app that serves its own copy of the files `compile-<go release>.wasm`), `gowasm: { limits }`. An app with no Content-Security-Policy has nothing to do. An app with a policy that has `connect-src` adds one origin, `https://registry.npmjs.org` (the first source; jsDelivr and unpkg are only fallbacks, so they need not be listed), or names a source of its own that the policy allows with `gowasm: { sources: [...] }`. A source the policy blocks is left for the next one without a request, and when all are blocked the guest compiles and the `gowasm-off` event says what blocked each (the directive and the origin to add; in Playwright's WebKit the page gets no violation event from the twin's Worker, so the reason is the browser's own text with a hint naming `connect-src`); knowing that all three are blocked took 21 to 25 ms in Chromium and 22 to 28 ms in Firefox (counted once, under shared load). Test page words: `gowasm=1`, `gowasm=auto` (only a table the page states by `gowasmtools=<url>` or `<meta name="wmd-gowasm-table" content="<url>">`), `gowasmbase=<url>`. A checkpoint keeps the twin choice it was taken with (a checkpoint taken with the twin always restores: with `gowasm: false` the stub mounts stay, no twin Worker starts, every compile runs in the guest, one `gowasm-off` event, rule `checkpoint-twin`; one taken without it restores without it). Headers, limits, the cache, the checkpoint rule and the images that carry a listed compile: `docs/gowasm-twin.md`.
3025
+ An embedder does nothing to get the twin: update the package and call `containerBundle` and `bootWmd` as before, with no line of twin code. `bootWmd` reads the pins (`src/gowasm/pins-data.js`, a JS module that ships in the package, no request), adds the stub mounts to the bundle's spec and sets the service's `gowasm` field from it; the image decides (an image with no Go compile, or a Go release with no pin, runs as before and downloads nothing). The twin's module (41 to 53 MB per Go release) is fetched by the twin's Worker on first use from an ordered list of sources (`GOWASM_SOURCES_DEFAULT` in `src/gowasm/setup.js`: the npm registry, then jsDelivr, then unpkg; `gowasm: false` turns the twin off): the first that gives the pinned sha256 and size wins, a source that fails, stalls, is too big, refuses the file or has a wrong hash is left for the next (jsDelivr refuses files over 50 MB, so for the largest twin the working sources are the registry tarball and unpkg: each release needs only one source that works), and when all fail the guest compiles, with one `gowasm-off` event that names each source. Source kinds: `{ kind: 'tgz', url }` (an npm registry tarball) and `{ kind: 'file', base }` (`<base>/<file>`); only the pins name the package. The module is kept in Cache Storage of the page's origin under a key that holds its hash (checked again at each boot). The twin is on in Chromium, Firefox and WebKit. (D-666 had it off in WebKit: a bundled embedder's machine never came up there with it. The cause was WebKit evaluating the channel service's Worker script a second time when the bundler's edge-go chunk imported it; the channel service now starts from `src/host/chan-service-entry.js`, which imports nothing, #86.) `GOWASM_ENGINES_OFF` in `src/gowasm/boot-setup.js` is the per-engine off switch (empty); `gowasm: { <engine>: true }` turns the twin on in an engine named there. What a consumer may pass to `bootWmd`: `gowasm: false` (off), `gowasm: { sources: [...] }`, `gowasm: { base: 'https://.../gowasm' }` (the override for an app that serves its own copy of the files `compile-<go release>.wasm`), `gowasm: { limits }`. An app with no Content-Security-Policy has nothing to do. An app with a policy that has `connect-src` adds one origin, `https://registry.npmjs.org` (the first source; jsDelivr and unpkg are only fallbacks, so they need not be listed), or names a source of its own that the policy allows with `gowasm: { sources: [...] }`. A source the policy blocks is left for the next one without a request, and when all are blocked the guest compiles and the `gowasm-off` event says what blocked each (the directive and the origin to add; in Playwright's WebKit the page gets no violation event from the twin's Worker, so the reason is the browser's own text with a hint naming `connect-src`); knowing that all three are blocked took 21 to 25 ms in Chromium and 22 to 28 ms in Firefox (counted once, under shared load). Test page words: `gowasm=1`, `gowasm=auto` (only a table the page states by `gowasmtools=<url>` or `<meta name="wmd-gowasm-table" content="<url>">`), `gowasmbase=<url>`. A checkpoint keeps the twin choice it was taken with (a checkpoint taken with the twin always restores: with `gowasm: false` the stub mounts stay, no twin Worker starts, every compile runs in the guest, one `gowasm-off` event, rule `checkpoint-twin`; one taken without it restores without it). Headers, limits, the cache, the checkpoint rule and the images that carry a listed compile: `docs/gowasm-twin.md`.
3026
3026
 
3027
3027
  Off is off: with `gowasm: false` (or no twin source and no table) there is no twin file requested, no twin Worker started, no stub mount in the container (the guest's `/proc/mounts` has none), and no event. What the page does load is four small library modules that main's page does not, because the checkpoint rule needs the twin's spec text even when the twin is off: `src/gowasm/boot-setup.js`, `src/gowasm/setup.js`, `src/gowasm/pins-data.js` and `src/host/gowasm-guard.js`, 4 requests and 39,808 bytes uncompressed (counted once in Chromium against a copy of `origin/main`'s `web/`: 228 requests against 225, 65 distinct paths against 61; `web/test/x6/fix10-count.spec.js`). Nothing else differs in what the page asks for.
package/RELEASE.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wmd-web",
3
3
  "version": "0.5.1",
4
- "commit": "46880b289f9eb86416d0561bbb4b1d9ba8b86056",
4
+ "commit": "2062620ce232ed2af82e1c1f4ad36a0b0adc176c",
5
5
  "previous": null,
6
6
  "decisions": [
7
7
  "D-388",
@@ -77,7 +77,8 @@
77
77
  "D-658",
78
78
  "D-659",
79
79
  "D-660",
80
- "D-661"
80
+ "D-661",
81
+ "D-666"
81
82
  ],
82
83
  "vmSources": "3ac7f939f52426df0f781492d3ebf09069e84d44",
83
84
  "guest": {
@@ -155,7 +156,7 @@
155
156
  }
156
157
  },
157
158
  "files": {
158
- "README.md": "9155fdbf01fcd60f0fd89d854d985a26682683294de7404bf0197fd22aa8fdfb",
159
+ "README.md": "b18b6bb6426b479098e02780feebedca613841da4c5da0eda0816761056db57a",
159
160
  "edge-site/own/HASHES.txt": "4d83edcb41399bb89eb7b1f89115886d739adac887bdde59a8d33e3a4602683a",
160
161
  "edge-site/own/NOTICES.txt": "8ceca5406ee5833737bd5fa4a41d434bf5e4d26eff6da1e42c693176ee113101",
161
162
  "edge-site/own/acorn/LICENSE": "76a876cf886ff9be2a8b5e2e86514fed06223c8c9f0c1e9ee9606e93841e00b7",
@@ -179,7 +180,7 @@
179
180
  "package.json": "7d43c05047d0a3ea56b4a7709f48a60de32e15c3bdf328d55435c46637981b40",
180
181
  "src/base.js": "982f8e46dbb727ec542a494ebdb884ccd19a31ff4e091425b2d1fc01b0d4754a",
181
182
  "src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
182
- "src/boot.js": "452c68ae107a2309cf32e4fd742e6e5b5ebf625b051937d5f08b664908cb413a",
183
+ "src/boot.js": "6da5caef172c7c7ce8798e360b2845511100850b118aa80a1545b8f057e3fdca",
183
184
  "src/build/builder.js": "c7794ec15b183213228776c8f4fb0950dec7e621f948358da7de8f90ef4f70ec",
184
185
  "src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
185
186
  "src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
@@ -271,7 +272,7 @@
271
272
  "src/fs/seed.js": "1cd2765e5d28e961bc4e81b41898f768a63e24feaf44e0aa42bd23e5cb910a74",
272
273
  "src/fs/svc-snapshot.js": "eae82a6e136f9430680197c617601028da35cbe8786df39d6cab28280a2f9a7c",
273
274
  "src/fs/upper-pack.js": "737a7e2bb5aac0ff774645db5789d699adfff263ca6f979e6687a9183a47f9dc",
274
- "src/gowasm/boot-setup.js": "7033465098fe5b70611bb89bc56f9ffda08de4a6699b5cfc087161de694a72ea",
275
+ "src/gowasm/boot-setup.js": "f0e265e93ed04f24310e693a45faeace9a1cb979ded7c746a2b797b3317c9bf5",
275
276
  "src/gowasm/fetch-twin.mjs": "de7c5f29c069dc3b009964b8b96084d567ef15d641238b1122a0d7f2c473f799",
276
277
  "src/gowasm/make-pins-module.mjs": "d13db3b38fdfe37e4db66f3b7d0433df15d590260433b295e2654af12feacd75",
277
278
  "src/gowasm/pins-data.js": "71fc2e21e2363de883823bccea5bb9ca3c46077e6fab56a04cfa511739563e19",
@@ -283,7 +284,8 @@
283
284
  "src/host/base-file.js": "edb47c1eeb6b1cec627fa5894512185336b15d3f5db96a7151a8a57b34b4a2e8",
284
285
  "src/host/base-io.js": "cdd049875dce9f1417f28b27efa2c6f494cbe2a49851249150d0c1ec871a8b59",
285
286
  "src/host/boot-events.js": "a6567c889fa1e95ad7e917107a2593f03d14cc921827616368b3417de96faad2",
286
- "src/host/chan-service.js": "65063feaf93c8604c61be1d05f9d873ec3f8629e18540400d10434cda1d5e86f",
287
+ "src/host/chan-service-entry.js": "18f602f9ad72323e930157cb0820568f3ef83ce49b9672443791b01551f0ffd3",
288
+ "src/host/chan-service.js": "71523df6b371e64fbf9c214e3c50f350b6444ac8f27e19e1230dd96043317504",
287
289
  "src/host/chan-services.js": "e7f52931b6ef76a8b97b793d0a1d86fb35d20dbca3dd333d18cc4ded0806c9f7",
288
290
  "src/host/chan.js": "bb9e76890b0efeee7cfbd8481b9fb4620b3b184459d96d62ff68ddcdc8a46f83",
289
291
  "src/host/ckpt-file.js": "da7938fa640a062e77bdfb59caad5b3b1fcbf6150e3220de3be23f253f4c4497",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadedstack/wmd-web",
3
- "version": "0.1.44",
3
+ "version": "0.1.46",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/threadedstack/wmd-releases",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "description": "Browser host for wmd's guest vm.wasm (Web Workers + shared memory + WASI preview1)",
11
11
  "wmd": {
12
- "tag": "v0.1.44",
13
- "commit": "46880b289f9eb86416d0561bbb4b1d9ba8b86056",
12
+ "tag": "v0.1.46",
13
+ "commit": "2062620ce232ed2af82e1c1f4ad36a0b0adc176c",
14
14
  "web": "0.5.1"
15
15
  },
16
16
  "type": "module",
package/src/boot.js CHANGED
@@ -1480,7 +1480,7 @@ async function bootMachine(o) {
1480
1480
  throw err // (no Worker exists yet)
1481
1481
  }
1482
1482
  const lockName = `wmd-chan-${Math.random().toString(36).slice(2)}-${Date.now()}`
1483
- chanSvc = new Worker(new URL('./host/chan-service.js', import.meta.url), { type: 'module', name: 'wmd-chan' })
1483
+ chanSvc = new Worker(new URL('./host/chan-service-entry.js', import.meta.url), { type: 'module', name: 'wmd-chan' })
1484
1484
  workerState('chan-service', 'chan-service', 'starting')
1485
1485
  chanSvc.onmessage = e => {
1486
1486
  const m = e.data
@@ -2,7 +2,7 @@
2
2
  // The files of node in the sandboxed frame: the path under a source (the option edge: { sources } of bootWmd), the role the frame gives the file, its
3
3
  // sha256 and its size. The page accepts a file only when it has exactly this sha256 and size. The notice files travel with the rest.
4
4
  // EDGE_PACKAGE is the package that holds these files, for the {name} {version} {file} of a registry source's url (null: none named).
5
- export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.44' }
5
+ export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.46' }
6
6
  export const EDGE_PINS = [
7
7
  { path: 'wmd_browser_bg.wasm', role: 'wasm', sha256: '1e3db7f2c5f4be0ee44e5f2c0205cf8ca11f906d9addd5512915fad4821661c2', size: 6334959 },
8
8
  { path: 'wmd_browser.js', role: 'glue', sha256: 'b389b072096881ba39b22cd705d3a230af02acc5409c61fb4f997d1081c4df6f', size: 75647 },
@@ -22,10 +22,17 @@
22
22
  // 'checkpoint-twin'. A header with no boot description, or whose spec text is neither, changes nothing.
23
23
  import { addEdgeToolMounts } from '../host/ctl.js'
24
24
  import { bootKeyForChoice, sampleKey, specChoice } from '../host/ckpt.js'
25
+ import { engineOf } from '../edge/sbx/cap.js'
25
26
  import { GOWASM_SOURCES_DEFAULT, planOf } from './setup.js'
26
27
 
27
28
  export { GOWASM_SOURCES_DEFAULT }
28
29
  const CONFIG = 'bundle/config/config.json'
30
+ /**
31
+ * The engines the twin is off in by default: none. D-666 turned it off in WebKit (an embedder's machine, wmr's, never came up there with it); the cause
32
+ * was the channel service evaluated twice in a bundled page (threadedstack/wmd#86, src/host/chan-service-entry.js), not the twin. An engine named here
33
+ * gets the twin off by default ({engine: reason}); `gowasm: { <engine>: true }` turns it on there.
34
+ */
35
+ export const GOWASM_ENGINES_OFF = {}
29
36
  // the spec text does not depend on the sources, so a boot that does not use the twin still makes the text a checkpoint with the twin would hold
30
37
  const TEXT_ONLY = [{ kind: 'file', base: 'https://twin.invalid/' }]
31
38
  const textOf = raw => {
@@ -50,9 +57,11 @@ export async function twinForBoot(o) {
50
57
  const services = o && o.channels && Array.isArray(o.channels.services) ? o.channels.services : []
51
58
  const mine = services.map((s, i) => [s, i]).filter(([s]) => s && (s.kind === '9p' || s.kind === 1) && s.files && typeof s.files === 'object' && !s.gowasm && s.files[CONFIG] !== undefined)
52
59
  if (!mine.length) return res(o)
53
- const consumerOff = opt === false || !sources
60
+ const engine = engineOf(globalThis.navigator?.userAgent || '')
61
+ const engineWhy = opt === false || given[engine] === true ? '' : GOWASM_ENGINES_OFF[engine] || ''
62
+ const consumerOff = opt === false || !sources || !!engineWhy
54
63
  const plan = planOf({ sources: consumerOff ? TEXT_ONLY : sources, pins: given.pins, packages: given.packages, limits: given.limits || {} })
55
- const consumerWhy = opt === false ? 'gowasm: false' : 'no source'
64
+ const consumerWhy = opt === false ? 'gowasm: false' : engineWhy || 'no source'
56
65
  // the text of the spec with the stub mounts is decided by the tools alone, not by the sources or the limits: when this boot does not use the twin (the consumer's
57
66
  // choice, or a setup that is not usable) it is made from the caller's pins and, when those are not usable, from the package's own, so a checkpoint taken with
58
67
  // the twin can still be told apart and restored (part 6)
@@ -93,6 +102,7 @@ export async function twinForBoot(o) {
93
102
  const built = build(plan, f => f)
94
103
  if (built.bad) return consumerOff ? goOff(consumerWhy, false) : (events.push({ t: 'gowasm-off', why: built.bad }), res(o, { off: built.bad }))
95
104
  if (consumerOff) {
105
+ if (engineWhy) return res(o, { texts: built.texts, off: engineWhy, offO: offOf(engineWhy, built) })
96
106
  if (opt === undefined) return res(o, { texts: built.texts, off: 'no source', offO: offOf('no source', built) })
97
107
  if (opt === false) return res(o, { texts: built.texts, off: 'gowasm: false', offO: offOf('gowasm: false', built) })
98
108
  events.push({ t: 'gowasm-off', why: 'no source of the twin is named: no sources and no default, so none is asked for' })
@@ -0,0 +1,21 @@
1
+ // The channel service Worker's entry (threadedstack/wmd#86, X6WK). It imports nothing statically: it keeps the messages that come first,
2
+ // loads chan-service.js with a dynamic import and hands them to it in order. WebKit evaluates a module Worker's entry script a second time
3
+ // when a chunk the Worker imports dynamically imports that entry again, and a bundler (Vite, Rolldown) puts the code chan-service.js shares
4
+ // with edge-go.js, edge-host.js, service-port.js, fs-route.js and service-host.js in the entry chunk. The second instance installed its own
5
+ // onmessage, without the machine, and took every later message of the page: an embedder's machine never ran in WebKit with the Go twin on.
6
+ // A chunk that imports nothing gets no shared code, so those chunks import chan-service.js's chunk, which every browser evaluates once.
7
+ const early = []
8
+ self.onmessage = e => early.push(e)
9
+ import('./chan-service.js').then(
10
+ () => {
11
+ // chan-service.js installed its handler on load; the messages that came first go to it now, before any later one (a later message is a
12
+ // task of its own, after this one)
13
+ for (const e of early.splice(0)) self.onmessage?.(e)
14
+ },
15
+ err => {
16
+ // the module could not be loaded: an error event on the page's Worker object (boot.js marks the channel service failed)
17
+ setTimeout(() => {
18
+ throw err
19
+ })
20
+ },
21
+ )
@@ -76,7 +76,7 @@ let goPort = null // ... and its port to the twin Worker
76
76
 
77
77
  const nowMs = () => performance.now()
78
78
 
79
- self.onmessage = e => {
79
+ const onMessage = e => {
80
80
  const m = e.data
81
81
  try {
82
82
  switch (m.t) {
@@ -204,6 +204,15 @@ self.onmessage = e => {
204
204
  fail(err)
205
205
  }
206
206
  }
207
+ // X6WK (#86): one channel service per Worker. WebKit evaluates a module Worker's entry script again when a chunk it imports dynamically imports
208
+ // it (a bundler's shared-code chunk); a second evaluation of this module installs no handler, so the instance that gets `init` gets every
209
+ // message after it. The Worker starts from chan-service-entry.js, which makes that second evaluation unlikely; this is the defence for a page
210
+ // that starts chan-service.js itself.
211
+ const ONE = Symbol.for('wmd.chan-service.instance')
212
+ if (!self[ONE]) {
213
+ self[ONE] = true
214
+ self.onmessage = onMessage
215
+ }
207
216
 
208
217
  /** Control events for the page (data bytes transferred). */
209
218
  function postCtl() {
package/wmdpack.wasm CHANGED
Binary file