wasm-mcp 0.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +108 -0
  4. package/build/wasm-proposals-main.json +1 -0
  5. package/build/wasm-sections-js-api-main.json +1 -0
  6. package/build/wasm-sections-web-api-main.json +1 -0
  7. package/build/wasm-spec-core-main.json +1 -0
  8. package/dist/mcp/_args.d.ts +22 -0
  9. package/dist/mcp/_args.js +25 -0
  10. package/dist/mcp/instructions.d.ts +1 -0
  11. package/dist/mcp/instructions.js +67 -0
  12. package/dist/mcp/server.d.ts +2 -0
  13. package/dist/mcp/server.js +63 -0
  14. package/dist/mcp/tool_meta.d.ts +32 -0
  15. package/dist/mcp/tool_meta.js +100 -0
  16. package/dist/mcp/tools/instruction_get.d.ts +32 -0
  17. package/dist/mcp/tools/instruction_get.js +39 -0
  18. package/dist/mcp/tools/instruction_list.d.ts +67 -0
  19. package/dist/mcp/tools/instruction_list.js +52 -0
  20. package/dist/mcp/tools/instruction_search.d.ts +28 -0
  21. package/dist/mcp/tools/instruction_search.js +33 -0
  22. package/dist/mcp/tools/proposal_list.d.ts +51 -0
  23. package/dist/mcp/tools/proposal_list.js +44 -0
  24. package/dist/mcp/tools/section_get.d.ts +29 -0
  25. package/dist/mcp/tools/section_get.js +32 -0
  26. package/dist/mcp/tools/section_list.d.ts +49 -0
  27. package/dist/mcp/tools/section_list.js +56 -0
  28. package/dist/mcp/tools/spec_search.d.ts +35 -0
  29. package/dist/mcp/tools/spec_search.js +34 -0
  30. package/dist/mcp/tools/spec_version.d.ts +28 -0
  31. package/dist/mcp/tools/spec_version.js +30 -0
  32. package/dist/mcp/tools/type_get.d.ts +22 -0
  33. package/dist/mcp/tools/type_get.js +31 -0
  34. package/dist/parser/bikeshed.d.ts +8 -0
  35. package/dist/parser/bikeshed.js +106 -0
  36. package/dist/parser/instructions.d.ts +171 -0
  37. package/dist/parser/instructions.js +241 -0
  38. package/dist/parser/proposals.d.ts +30 -0
  39. package/dist/parser/proposals.js +188 -0
  40. package/dist/parser/sections.d.ts +27 -0
  41. package/dist/parser/sections.js +213 -0
  42. package/dist/parser/types.d.ts +37 -0
  43. package/dist/parser/types.js +116 -0
  44. package/dist/parser/upstream.d.ts +7 -0
  45. package/dist/parser/upstream.js +230 -0
  46. package/dist/paths.d.ts +3 -0
  47. package/dist/paths.js +12 -0
  48. package/dist/spec/catalog.d.ts +10 -0
  49. package/dist/spec/catalog.js +20 -0
  50. package/dist/spec/instructions_query.d.ts +46 -0
  51. package/dist/spec/instructions_query.js +120 -0
  52. package/dist/spec/pin.d.ts +13 -0
  53. package/dist/spec/pin.js +39 -0
  54. package/dist/spec/proposals_query.d.ts +15 -0
  55. package/dist/spec/proposals_query.js +23 -0
  56. package/dist/spec/sections_query.d.ts +43 -0
  57. package/dist/spec/sections_query.js +89 -0
  58. package/dist/spec/spec_data.d.ts +46 -0
  59. package/dist/spec/spec_data.js +92 -0
  60. package/dist/spec/tool_inventory.d.ts +5 -0
  61. package/dist/spec/tool_inventory.js +17 -0
  62. package/dist/versions.d.ts +12 -0
  63. package/dist/versions.js +22 -0
  64. package/package.json +76 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to `wasm-mcp` are recorded here. Versions follow
4
+ [Semantic Versioning](https://semver.org/): tool-schema or behavior
5
+ changes that aren't backward-compatible bump the major; new tools or
6
+ optional schema fields bump the minor; internal fixes bump the patch.
7
+
8
+ ## A note on data-refresh versions
9
+
10
+ This file records **code changes** — new tools, schema tweaks,
11
+ internal fixes. Spec-data freshness rides a separate track: an
12
+ auto-refresh workflow SHA-diffs the upstream `WebAssembly/spec` and
13
+ `WebAssembly/proposals` repositories and ships a PATCH release when
14
+ the pinned commit moves, re-baking the indexed JSON. Those data-only
15
+ PATCH releases are noted here briefly; the pinned SHAs live in
16
+ [`vendor/PINNED.txt`](vendor/PINNED.txt) and are reported by the
17
+ `spec_version` tool.
18
+
19
+ ## 0.1.0 — initial release
20
+
21
+ ### Added
22
+
23
+ - A read-only MCP server over the WebAssembly specification,
24
+ SHA-pinned and deterministic, distributed as both an npm stdio
25
+ package and a hosted Cloudflare Worker.
26
+ - Tools: `spec_version`, `instruction_get`, `instruction_list`,
27
+ `instruction_search`, `type_get`, `section_get`, `section_list`,
28
+ `spec_search`, `proposal_list`.
29
+ - `section_get`, `section_list`, and `spec_search` span all three
30
+ specs in the `WebAssembly/spec` repo via a `spec` argument: `core`
31
+ (default), `js-api` (JavaScript embedding), and `web-api` (Web
32
+ integration). Instruction and type tools are `core`-only.
33
+ - Build pipeline: clones `WebAssembly/spec` at the pinned SHA,
34
+ extracts the structured instruction index + macro table from the
35
+ upstream sources, parses the reStructuredText (core) and Bikeshed
36
+ (js-api / web-api) sections into anchor-addressable clauses, derives
37
+ a type catalog, and indexes the `WebAssembly/proposals` Markdown
38
+ tables — all baked into JSON at build time so the running server
39
+ does pure local lookups.
40
+ - Tool definitions live in a single registry (`src/mcp/tool_meta.ts`)
41
+ shared by the server and the docs generator, so the published tool
42
+ docs can't drift from the server.
43
+ - A VitePress documentation site, served as the hosted Worker's static
44
+ assets, with an auto-generated tool reference and snapshots page.
45
+ - Pinned at `WebAssembly/spec@7a366e15` and
46
+ `WebAssembly/proposals@e007b5c9`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xyzzylabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # wasm-mcp
2
+
3
+ Unofficial Model Context Protocol server for the
4
+ [WebAssembly core specification](https://webassembly.github.io/spec/core/).
5
+ SHA-pinned, read-only, deterministic — safe to host as a public
6
+ unauthenticated endpoint.
7
+
8
+ > Not affiliated with, endorsed by, or sponsored by the W3C
9
+ > WebAssembly Community Group or Working Group.
10
+
11
+ ## What it gives you
12
+
13
+ - `spec_version` — the pinned upstream commit and package version.
14
+ - `instruction_get` — opcode bytes, category, introducing version,
15
+ stack type signature, and validation + execution prose anchors /
16
+ URLs, by mnemonic (`i32.add`) or binary opcode (`0x6a`).
17
+ - `instruction_list` — enumerate, filterable by category (numeric,
18
+ vector, reference, parametric, variable, table, memory, control,
19
+ ref, i31, struct, array, extern), introducing version, or prefix.
20
+ - `instruction_search` — ranked free-text search across mnemonics,
21
+ categories, and opcodes.
22
+ - `type_get` — value types (number / vector / reference) and type
23
+ forms (`functype`, `limits`, `memtype`, …) with defining prose.
24
+ - `section_get` — one spec clause by id / anchor (structure,
25
+ validation, execution, binary, text), with prose, cross-references,
26
+ SpecTec formal-rule references, and the rendered URL.
27
+ - `section_list` — navigate the clause tree by area or anchor prefix.
28
+ - `spec_search` — full-text search across anchors, titles, and prose.
29
+ - `proposal_list` — WebAssembly proposals and their phases (from the
30
+ pinned `WebAssembly/proposals` repo), filterable by status, phase,
31
+ champion, or affected spec.
32
+
33
+ `section_get`, `section_list`, and `spec_search` take a `spec`
34
+ argument covering all three specs in the `WebAssembly/spec` repo:
35
+ `core` (default), `js-api` (the JavaScript embedding API), and
36
+ `web-api` (Web-platform integration). The instruction and type tools
37
+ are `core`-only.
38
+
39
+ ## Contract
40
+
41
+ Every tool is:
42
+
43
+ - **Read-only.** No state mutation, no writes outside an optional
44
+ local cache.
45
+ - **Deterministic.** Same input → same output, over the pinned spec
46
+ commit recorded in [`vendor/PINNED.txt`](vendor/PINNED.txt).
47
+ - **No execution.** Never compiles, validates-by-running,
48
+ instantiates, or runs any WebAssembly or arbitrary code. Validation
49
+ and reduction rules are returned as data.
50
+ - **No auth, no secrets, no PII.** Usable anonymously.
51
+ - **No network at request time.** All spec data is fetched and
52
+ indexed at build time and baked into the package.
53
+
54
+ ## Install (stdio, local)
55
+
56
+ ```bash
57
+ npx wasm-mcp
58
+ ```
59
+
60
+ Wire into Claude Code by adding to your project's `.mcp.json`:
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "wasm": {
66
+ "type": "stdio",
67
+ "command": "npx",
68
+ "args": ["wasm-mcp"]
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ## Hosted Worker
75
+
76
+ The Cloudflare Worker in [`worker/`](worker/) exposes the same tool
77
+ surface as the stdio package over streamable HTTP at a single
78
+ unauthenticated endpoint, rate-limited per source IP (30 req / 60 s):
79
+
80
+ ```
81
+ https://wasm-mcp.chicoxyzzy.workers.dev/mcp
82
+ ```
83
+
84
+ `GET /health` reports status and the pinned SHAs; `GET /privacy`
85
+ states the anonymous, no-storage posture. All spec data is bundled
86
+ into the Worker, so it does pure in-memory lookups — no storage, no
87
+ network at request time.
88
+
89
+ ## Releases & data refresh
90
+
91
+ The pinned commits live in [`vendor/PINNED.txt`](vendor/PINNED.txt)
92
+ and are reported by `spec_version`. A scheduled GitHub Actions
93
+ workflow ([`refresh.yml`](.github/workflows/refresh.yml)) SHA-diffs
94
+ the upstream repos daily; when a pin moves it re-pins, bumps the patch
95
+ version, and tags a release, which publishes the npm package
96
+ ([`release.yml`](.github/workflows/release.yml)) and redeploys the
97
+ Worker ([`deploy-worker.yml`](.github/workflows/deploy-worker.yml)).
98
+
99
+ Maintainers: these workflows need the repository secrets `NPM_TOKEN`
100
+ (release) and `CLOUDFLARE_API_TOKEN` + `CLOUDFLARE_ACCOUNT_ID`
101
+ (deploy). For the refresh workflow's tag push to trigger release +
102
+ deploy, also add a `RELEASE_TOKEN` PAT (`repo` + `workflow` scopes) —
103
+ without it, refresh still re-pins and tags, but you run release /
104
+ deploy manually.
105
+
106
+ ## License
107
+
108
+ MIT — see [`LICENSE`](LICENSE).
@@ -0,0 +1 @@
1
+ {"pin":{"key":"proposals/main","sha":"e007b5c9f2e510573869985cbc635c7f4fc0b566","repo":"proposals","version":"main"},"proposals":[{"name":"Branch Hinting","status":"finished","phase":4,"champion":"Yuri Iozzelli","url":"https://github.com/WebAssembly/branch-hinting","affected_specs":["core"],"spec_version":"3.0"},{"name":"Bulk memory operations","status":"finished","phase":4,"champion":"Ben Smith","url":"https://github.com/WebAssembly/bulk-memory-operations","affected_specs":["core"],"spec_version":"2.0"},{"name":"Call Tags","status":"inactive","phase":null,"champion":"Ross Tate","url":"https://github.com/WebAssembly/call-tags","affected_specs":[],"spec_version":null},{"name":"Compact Import Section","status":"phase-3","phase":3,"champion":"Ryan Hunt","url":"https://github.com/WebAssembly/compact-import-section","affected_specs":[],"spec_version":null},{"name":"Compilation Hints","status":"phase-2","phase":2,"champion":"Emanuel Ziegler","url":"https://github.com/WebAssembly/compilation-hints","affected_specs":[],"spec_version":null},{"name":"Component Model","status":"phase-1","phase":1,"champion":"Luke Wagner","url":"https://github.com/WebAssembly/component-model","affected_specs":[],"spec_version":null},{"name":"Conditional sections","status":"inactive","phase":null,"champion":"Thomas Lively","url":"https://github.com/WebAssembly/conditional-sections","affected_specs":[],"spec_version":null},{"name":"Constant Time","status":"inactive","phase":null,"champion":"Sunjay Cauligi, Garrett Gu, John Renner, Hovav Shacham, Deian Stefan, Conrad Watt","url":"https://github.com/WebAssembly/constant-time","affected_specs":[],"spec_version":null},{"name":"Custom Annotation Syntax in the Text Format","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/annotations","affected_specs":["core"],"spec_version":"3.0"},{"name":"Custom Descriptors and JS Interop","status":"phase-3","phase":3,"champion":"Thomas Lively","url":"https://github.com/WebAssembly/custom-descriptors","affected_specs":[],"spec_version":null},{"name":"Custom Page Sizes","status":"phase-3","phase":3,"champion":"Nick Fitzgerald","url":"https://github.com/WebAssembly/custom-page-sizes","affected_specs":[],"spec_version":null},{"name":"ESM Integration","status":"phase-3","phase":3,"champion":"Asumu Takikawa, Ms2ger & Guy Bedford","url":"https://github.com/WebAssembly/esm-integration","affected_specs":[],"spec_version":null},{"name":"Exception handling","status":"finished","phase":4,"champion":"Heejin Ahn & Ben Titzer","url":"https://github.com/WebAssembly/exception-handling","affected_specs":["core","js-api"],"spec_version":"3.0"},{"name":"Extended Constant Expressions","status":"finished","phase":4,"champion":"Sam Clegg","url":"https://github.com/WebAssembly/extended-const","affected_specs":["core"],"spec_version":"3.0"},{"name":"Extended Name Section","status":"phase-2","phase":2,"champion":"Ben Visness","url":"https://github.com/WebAssembly/extended-name-section","affected_specs":[],"spec_version":null},{"name":"Feature Detection","status":"inactive","phase":null,"champion":"Thomas Lively","url":"https://github.com/WebAssembly/feature-detection","affected_specs":[],"spec_version":null},{"name":"Fixed-width SIMD","status":"finished","phase":4,"champion":"Deepti Gandluri and Arun Purushan","url":"https://github.com/webassembly/simd","affected_specs":["core","js-api"],"spec_version":"2.0"},{"name":"Flexible Vectors","status":"phase-1","phase":1,"champion":"Petr Penzin & Tal Garfinkel","url":"https://github.com/WebAssembly/flexible-vectors","affected_specs":[],"spec_version":null},{"name":"Frozen Values","status":"phase-1","phase":1,"champion":"Léo Andrès and Pierre Chambart","url":"https://github.com/WebAssembly/frozen-values","affected_specs":[],"spec_version":null},{"name":"Funclets: Flexible Intraprocedural Control Flow","status":"inactive","phase":null,"champion":"Dan Gohman","url":"https://github.com/WebAssembly/funclets","affected_specs":[],"spec_version":null},{"name":"Garbage collection","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/gc","affected_specs":["core","js-api"],"spec_version":"3.0"},{"name":"Half Precision","status":"phase-1","phase":1,"champion":"Ilya Rezvov","url":"https://github.com/WebAssembly/half-precision","affected_specs":[],"spec_version":null},{"name":"Import/Export of Mutable Globals","status":"finished","phase":4,"champion":"Ben Smith","url":"https://github.com/WebAssembly/mutable-global","affected_specs":["core","js-api"],"spec_version":"1.0"},{"name":"Instrument and Tracing Technology","status":"inactive","phase":null,"champion":"Richard Winterton","url":"https://github.com/WebAssembly/instrument-tracing","affected_specs":[],"spec_version":null},{"name":"Interface Types","status":"inactive","phase":null,"champion":"Luke Wagner and Francis McCabe","url":"https://github.com/WebAssembly/interface-types","affected_specs":[],"spec_version":null},{"name":"JavaScript BigInt to WebAssembly i64 integration","status":"finished","phase":4,"champion":"Dan Ehrenberg & Sven Sauleau","url":"https://github.com/WebAssembly/JS-BigInt-integration","affected_specs":["js-api"],"spec_version":"2.0"},{"name":"JIT Interface","status":"phase-1","phase":1,"champion":"Ben Titzer","url":"https://github.com/WebAssembly/jit-interface","affected_specs":[],"spec_version":null},{"name":"JS Customization for GC Objects","status":"inactive","phase":null,"champion":"Asumu Takikawa","url":"https://github.com/WebAssembly/gc-js-customization","affected_specs":[],"spec_version":null},{"name":"JS Primitive Builtins","status":"phase-2","phase":2,"champion":"Sébastien Doeraene","url":"https://github.com/WebAssembly/js-primitive-builtins","affected_specs":[],"spec_version":null},{"name":"JS Promise Integration","status":"phase-4","phase":4,"champion":"Francis McCabe","url":"https://github.com/WebAssembly/js-promise-integration","affected_specs":[],"spec_version":null},{"name":"JS String Builtins","status":"finished","phase":4,"champion":"Ryan Hunt","url":"https://github.com/WebAssembly/js-string-builtins","affected_specs":["core","js-api"],"spec_version":"3.0"},{"name":"JS Text Encoding Builtins","status":"phase-1","phase":1,"champion":"Daxpedda","url":"https://github.com/WebAssembly/js-text-encoding-builtins","affected_specs":[],"spec_version":null},{"name":"Memory control","status":"phase-1","phase":1,"champion":"Deepti Gandluri & Ben Visness","url":"https://github.com/WebAssembly/memory-control","affected_specs":[],"spec_version":null},{"name":"Memory64","status":"finished","phase":4,"champion":"Sam Clegg","url":"https://github.com/WebAssembly/memory64","affected_specs":["core"],"spec_version":"3.0"},{"name":"Module Linking","status":"inactive","phase":null,"champion":"Luke Wagner and Andreas Rossberg","url":"https://github.com/WebAssembly/module-linking","affected_specs":[],"spec_version":null},{"name":"More Array Constructors","status":"phase-1","phase":1,"champion":"Nick Fitzgerald","url":"https://github.com/WebAssembly/more-array-constructors/","affected_specs":[],"spec_version":null},{"name":"Multi-value","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/multi-value","affected_specs":["core","js-api"],"spec_version":"2.0"},{"name":"Multibyte Array Access","status":"phase-1","phase":1,"champion":"Brendan Dahl","url":"https://github.com/WebAssembly/multibyte-array-access","affected_specs":[],"spec_version":null},{"name":"Multiple memories","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/multi-memory","affected_specs":["core","js-api"],"spec_version":"3.0"},{"name":"MVP","status":"finished","phase":4,"champion":"The Wasm CG","url":"https://github.com/WebAssembly/design/blob/main/MVP.md","affected_specs":["core","js-api","web-api"],"spec_version":"1.0"},{"name":"Non-trapping float-to-int conversions","status":"finished","phase":4,"champion":"Dan Gohman","url":"https://github.com/WebAssembly/nontrapping-float-to-int-conversions","affected_specs":["core"],"spec_version":"2.0"},{"name":"Numeric Values in WAT Data Segments","status":"phase-2","phase":2,"champion":"Ezzat Chamudi","url":"https://github.com/WebAssembly/wat-numeric-values","affected_specs":[],"spec_version":null},{"name":"Profiles","status":"phase-1","phase":1,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/profiles","affected_specs":[],"spec_version":null},{"name":"Reference Types","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/reference-types","affected_specs":["core","js-api"],"spec_version":"2.0"},{"name":"Reference-Typed Strings","status":"phase-1","phase":1,"champion":"Andy Wingo","url":"https://github.com/WebAssembly/stringref","affected_specs":[],"spec_version":null},{"name":"Relaxed Atomics","status":"phase-2","phase":2,"champion":"Conrad Watt & Rezvan Mahdavi Hezaveh","url":"https://github.com/WebAssembly/relaxed-atomics","affected_specs":[],"spec_version":null},{"name":"Relaxed dead code validation","status":"phase-2","phase":2,"champion":"Conrad Watt and Ross Tate","url":"https://github.com/WebAssembly/relaxed-dead-code-validation","affected_specs":[],"spec_version":null},{"name":"Relaxed SIMD","status":"finished","phase":4,"champion":"Marat Dukhan & Zhi An Ng","url":"https://github.com/WebAssembly/relaxed-simd","affected_specs":["core"],"spec_version":"3.0"},{"name":"Rounding Variants","status":"phase-2","phase":2,"champion":"Kloud Koder","url":"https://github.com/WebAssembly/rounding-mode-control","affected_specs":[],"spec_version":null},{"name":"Shared-Everything Threads","status":"phase-1","phase":1,"champion":"Andrew Brown, Conrad Watt, and Thomas Lively","url":"https://github.com/WebAssembly/shared-everything-threads","affected_specs":[],"spec_version":null},{"name":"Sign-extension operators","status":"finished","phase":4,"champion":"Ben Smith","url":"https://github.com/WebAssembly/sign-extension-ops","affected_specs":["core"],"spec_version":"2.0"},{"name":"Stack Switching","status":"phase-3","phase":3,"champion":"Francis McCabe & Sam Lindley","url":"https://github.com/WebAssembly/stack-switching","affected_specs":[],"spec_version":null},{"name":"Tail call","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/tail-call","affected_specs":["core"],"spec_version":"3.0"},{"name":"Threads","status":"phase-4","phase":4,"champion":"Conrad Watt","url":"https://github.com/webassembly/threads","affected_specs":[],"spec_version":null},{"name":"Type Imports","status":"phase-1","phase":1,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/proposal-type-imports","affected_specs":[],"spec_version":null},{"name":"Type Reflection for WebAssembly JavaScript API","status":"phase-1","phase":1,"champion":"Ilya Rezvov","url":"https://github.com/WebAssembly/js-types","affected_specs":[],"spec_version":null},{"name":"Typed Function References","status":"finished","phase":4,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/function-references","affected_specs":["core","js-api"],"spec_version":"3.0"},{"name":"Unmanaged closures","status":"inactive","phase":null,"champion":"Mark Miller","url":"https://github.com/WebAssembly/proposals/issues/6","affected_specs":[],"spec_version":null},{"name":"Web Content Security Policy","status":"phase-4","phase":4,"champion":"Francis McCabe","url":"https://github.com/WebAssembly/content-security-policy","affected_specs":[],"spec_version":null},{"name":"WebAssembly C and C++ API","status":"phase-1","phase":1,"champion":"Andreas Rossberg","url":"https://github.com/WebAssembly/wasm-c-api","affected_specs":[],"spec_version":null},{"name":"Wide Arithmetic","status":"phase-3","phase":3,"champion":"Alex Crichton and Jamey Sharp","url":"https://github.com/WebAssembly/wide-arithmetic","affected_specs":[],"spec_version":null}]}
@@ -0,0 +1 @@
1
+ {"pin":{"key":"spec/main","sha":"7a366e1531e6aab089c9a07ae5608909e187bb13","spec":"js-api","version":"main"},"sections":[{"id":"intro","anchors":["intro"],"title":"Introduction","level":2,"path":"js-api","prose":"By design, the scope of the WebAssembly core specification WEBASSEMBLY does not include a description of how WebAssembly programs interact with their surrounding execution environment.\nInstead it defines an abstract embedding interface between WebAssembly and its environment, (called the embedder).\nIt is only through this interface that an embedder interacts with the semantics of WebAssembly, and the embedder implements the connection between its host environment and the embedding API.\nThis document describes the embedding of WebAssembly into JavaScript ECMASCRIPT environments, including how WebAssembly modules can be constructed and instantiated, how imported and exported functions are called, how data is exchanged, and how errors are handled.\nWhen the JavaScript environment is itself embedded in a Web browser, the Web API spec WASMWEB describes additional behavior relevant to the Web environment.","crossrefs":["scope","embedding interface"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#intro"},{"id":"sample","anchors":["sample"],"title":"Sample API Usage","level":2,"path":"js-api","prose":"This section is non-normative.\n\nGiven demo.wat (encoded to demo.wasm):\n\n \n\nand the following JavaScript, run in a browser:","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#sample"},{"id":"notation","anchors":["notation"],"title":"Notation","level":2,"path":"js-api","prose":"This specification depends on the Infra Standard. INFRA\n\nThe WebAssembly sequence type is equivalent to the list type defined there; values of one\nare treated as values of the other transparently.","crossrefs":["sequence","list"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#notation"},{"id":"webassembly-storage","anchors":["webassembly-storage"],"title":"Internal storage","level":2,"path":"js-api","prose":"","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#webassembly-storage"},{"id":"store","anchors":["store"],"title":"Interaction of the WebAssembly Store with JavaScript","level":3,"path":"js-api","prose":"Note: WebAssembly semantics are defined in terms of an abstract store, representing the state of the WebAssembly abstract machine. WebAssembly operations take a store and return an updated store.\n\nEach agent has an associated store. When a new agent is created, its associated store is set to the result of store_init().\n\nNote: In this specification, no WebAssembly-related objects, memory or addresses can be shared among agents in an agent cluster. In a future version of WebAssembly, this may change.\n\nElements of the WebAssembly store may be identified with JavaScript values. In particular, each WebAssembly memory instance with a corresponding Memory object is identified with a JavaScript Data Block; modifications to this Data Block are identified to updating the agent's store to a store which reflects those changes, and vice versa.","crossrefs":["store","agent","store_init","agent cluster","memory instance","Data Block","Memory"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#store"},{"id":"object-caches","anchors":["object-caches"],"title":"WebAssembly JS Object Caches","level":3,"path":"js-api","prose":"Note: There are several WebAssembly objects that may have a corresponding JavaScript object. The correspondence is stored in a per-agent mapping from WebAssembly addresses to JavaScript objects.\nThis mapping is used to ensure that, for a given agent, there exists at most one JavaScript object for a particular WebAssembly address. However, this property does not hold for shared objects.\n\nEach agent is associated with the following ordered maps:\n The Memory object cache, mapping memory addresses to Memory objects.\n The Table object cache, mapping table addresses to Table objects.\n The Exported Function cache, mapping function addresses to Exported Function objects.\n The Exported GC Object cache, mapping struct addresses and array addresses to Exported GC Object objects.\n The Global object cache, mapping global addresses to Global objects.\n The Tag object cache, mapping tag addresses to Tag objects.\n The Exception object cache, mapping exception addresses to Exception objects.\n The Host value cache, mapping host addresses to values.","crossrefs":["address","agent","ordered map","memory address","table address","function address","Exported Function","struct address","array address","Exported GC Object","global address","tag address","exception address","host address","Memory","Table","Global","Tag","Exception"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#object-caches"},{"id":"webassembly-namespace","anchors":["webassembly-namespace"],"title":"The WebAssembly Namespace","level":2,"path":"js-api","prose":"To compile a WebAssembly module from source bytes bytes, perform the following steps:\n 1. Let module be module_decode(bytes). If module is error, return error.\n 1. If module_validate(module) is error, return error.\n 1. Return module.\n\nTo validate builtins and imported string for a WebAssembly module from module module, enabled builtins builtinSetNames, and importedStringModule, perform the following steps:\n1. If validating builtin set names for builtinSetNames is false, return false.\n1. For each import of module_imports(module),\n 1. If importedStringModule is not null and import[0] equals importedStringModule,\n 1. Let importExternType be import[2].\n 1. Let stringExternType be global const (ref extern).\n 1. If match_externtype(stringExternType, importExternType) is false, return false\n 1. Else,\n 1. If validating an import for builtins with import and builtinSetNames is false, return false.\n1. Return true.\n\n The validate(bytes, options) method, when invoked, performs the following steps:\n 1. Let stableBytes be a copy of the bytes held by the buffer bytes.\n 1. Compile stableBytes as a WebAssembly module and store the results as module.\n 1. If module is error, return false.\n 1. Let builtinSetNames be options[\"builtins\"].\n 1. Let importedStringModule be options[\"importedStringConstants\"].\n 1. If validating builtins and imported strings for module with builtinSetNames and importedStringModule returns false, return false.\n 1. Return true.\n\nA Module object represents a single WebAssembly module. Each Module object has the following internal slots:\n\n \\[[Module]] : a WebAssembly /module\n \\[[Bytes]] : the source bytes of \\[[Module]].\n \\[[BuiltinSets]] : an ordered set of names of builtin sets\n \\[[ImportedStringModule]] : an optional module specifier string where any string constant can be imported from.\n\n To construct a WebAssembly module object from a module module, source bytes bytes, enabled builtins builtinSetNames, and importedStringModule, perform the following steps:\n\n 1. Let moduleObject be a /new Module.\n 1. Set moduleObject.\\[[Module]] to module.\n 1. Set moduleObject.\\[[Bytes]] to bytes.\n 1. Set moduleObject.\\[[BuiltinSets]] to builtinSetNames.\n 1. Set moduleObject.\\[[ImportedStringModule]] to importedStringModule.\n 1. Return moduleObject.\n\n To asynchronously compile a WebAssembly module from source bytes bytes and WebAssemblyCompileOptions options using optional task source taskSource, perform the following steps:\n\n 1. Let promise be a new promise.\n 1. Run the following steps in parallel:\n 1. Compile the WebAssembly module bytes and store the result as module.\n 1. Queue a task on taskSource, if provided, to perform the following steps:\n 1. If module is error, reject promise with a CompileError exception and return.\n 1. Let builtinSetNames be options[\"builtins\"].\n 1. Let importedStringModule be options[\"importedStringConstants\"].\n 1. If validating builtins and imported strings for module with builtinSetNames and importedStringModule is false, reject promise with a CompileError exception.\n 1. Otherwise,\n 1. Construct a WebAssembly module object from module, bytes, builtinSetNames, importedStringModule, and let moduleObject be the result.\n 1. Resolve promise with moduleObject.\n 1. Return promise.\n\n The compile(bytes, options) method, when invoked, performs the following steps:\n 1. Let stableBytes be a copy of the bytes held by the buffer bytes.\n 1. Asynchronously compile a WebAssembly module from stableBytes using options and return the result.\n\nTo instantiate imported strings with module module and importedStringModule, perform the following steps:\n\n1. Assert: importedStringModule is not null.\n1. Let exportsObject be ! [$OrdinaryObjectCreate$](null).\n1. For each (moduleName, componentName, externtype) of module_imports(module),\n 1. If moduleName does not equal importedStringModule, then iteration/continue.\n 1. Let stringConstant be componentName.\n 1. Let status be ! [$CreateDataProperty$](exportsObject, stringConstant, stringConstant).\n 1. Assert: status is true.\n1. Return exportsObject.\n\n To read the imports from a WebAssembly module module from imports object importObject, enabled builtins builtinSetNames, and importedStringModule, perform the following steps:\n 1. If module.imports is not empty, and importObject is undefined, throw a TypeError exception.\n 1. Let builtinOrStringImports be the ordered map « ».\n 1. For each builtinSetName of builtinSetNames,\n 1. Let builtinSetQualifiedName be builtinSetName prefixed with \"wasm:\"\n 1. Assert: builtinOrStringImports does not contain builtinSetQualifiedName\n 1. If builtinSetName does not refer to a builtin set, then iteration/continue.\n 1. Let exportsObject be the result of instantiate a builtin set with builtinSetName\n 1. Set builtinOrStringImports[builtinSetQualifiedName] to exportsObject\n 1. If importedStringModule is not null,\n 1. Let exportsObject be the result of instantiate imported strings with module and importedStringModule\n 1. Set builtinOrStringImports[importedStringModule] to exportsObject\n 1. Let imports be « ».\n 1. For each (moduleName, componentName, externtype) of module_imports(module),\n 1. If builtinOrStringImports contains moduleName,\n 1. Let o be builtinOrStringImports[moduleName].\n 1. If o is not an Object or if [$HasProperty$](o, componentName) is false,\n 1. Set o to ? [$Get$](importObject, moduleName).\n 1. Else,\n 1. Let o be ? [$Get$](importObject, moduleName).\n 1. If o is not an Object, throw a TypeError exception.\n 1. Let v be ? [$Get$](o, componentName).\n 1. If externtype is of the form external-type/func functype,\n 1. If [$IsCallable$](v) is false, throw a LinkError exception.\n 1. If v has a \\[[FunctionAddress]] internal slot, and therefore is an Exported Function,\n 1. Let funcaddr be the value of v's \\[[FunctionAddress]] internal slot.\n 1. Otherwise,\n 1. Create a host function from v and functype, and let funcaddr be the result.\n 1. Let index be the number of external functions in imports. This value index is known as the index of the host function funcaddr.\n 1. Let externfunc be the external value func funcaddr.\n 1. list/Append externfunc to imports.\n 1. If externtype is of the form external-type/global mut valtype,\n 1. If v implements Global,\n 1. Let globaladdr be v.\\[[Global]].\n 1. Otherwise,\n 1. If valtype is i64 and v is not a BigInt,\n 1. Throw a LinkError exception.\n 1. If valtype is one of i32, f32 or f64 and v is not a Number,\n 1. Throw a LinkError exception.\n 1. If valtype is v128,\n 1. Throw a LinkError exception.\n 1. Let value be ToWebAssemblyValue(v, valtype). If this operation throws a TypeError, catch it, and throw a LinkError exception.\n 1. Let store be the surrounding agent's associated store.\n 1. Let (store, globaladdr) be global_alloc(store, const valtype, value).\n 1. Set the surrounding agent's associated store to store.\n 1. Let externglobal be global globaladdr.\n 1. list/Append externglobal to imports.\n 1. If externtype is of the form external-type/mem memtype,\n 1. If v does not implement Memory, throw a LinkError exception.\n 1. Let externmem be the external value mem v.\\[[Memory]].\n 1. list/Append externmem to imports.\n 1. If externtype is of the form external-type/table tabletype,\n 1. If v does not implement Table, throw a LinkError exception.\n 1. Let tableaddr be v.\\[[Table]].\n 1. Let externtable be the external value table tableaddr.\n 1. list/Append externtable to imports.\n 1. If externtype is of the form external-type/tag attribute functype,\n 1. Assert: attribute is tagtype/attribute/exception.\n 1. If v does not implement Tag, throw a LinkError exception.\n 1. Let tagaddr be v.\\[[Address]].\n 1. Let externtag be the external value external value/tag tagaddr.\n 1. list/Append externtag to imports.\n 1. Return imports.\n\nNote: This algorithm only verifies the right kind of JavaScript values are passed.\nThe verification of WebAssembly type requirements is deferred to the\n\"instantiate the core of a WebAssembly module\" algorithm.\n\n To create an exports object from a WebAssembly module module and instance instance, perform the following steps:\n 1. Let exportsObject be ! [$OrdinaryObjectCreate$](null).\n 1. For each (name, externtype) of module_exports(module),\n 1. Let externval be instance_export(instance, name).\n 1. Assert: externval is not error.\n 1. If externtype is of the form external-type/func functype,\n 1. Assert: externval is of the form func funcaddr.\n 1. Let func funcaddr be externval.\n 1. Let func be the result of creating a new Exported Function from funcaddr.\n 1. Let value be func.\n 1. If externtype is of the form external-type/global mut globaltype,\n 1. Assert: externval is of the form global globaladdr.\n 1. Let global globaladdr be externval.\n 1. Let global be a new Global object created from globaladdr.\n 1. Let value be global.\n 1. If externtype is of the form external-type/mem memtype,\n 1. Assert: externval is of the form mem memaddr.\n 1. Let mem memaddr be externval.\n 1. Let memory be a new Memory object created from memaddr.\n 1. Let value be memory.\n 1. If externtype is of the form external-type/table tabletype,\n 1. Assert: externval is of the form table tableaddr.\n 1. Let table tableaddr be externval.\n 1. Let table be a new Table object created from tableaddr.\n 1. Let value be table.\n 1. If externtype is of the form external-type/tag attribute functype,\n 1. Assert: attribute is tagtype/attribute/exception.\n 1. Assert: externval is of the form external value/tag tagaddr.\n 1. Let external value/tag tagaddr be externval.\n 1. Let tag be a new Tag object created from tagaddr.\n 1. Let value be tag.\n 1. Let status be ! [$CreateDataProperty$](exportsObject, name, value).\n 1. Assert: status is true.\n\n Note: the validity and uniqueness checks performed during WebAssembly module validation ensure that each property name is valid and no properties are defined twice.\n 1. Perform ! [$SetIntegrityLevel$](exportsObject, \"frozen\").\n 1. Return exportsObject.\n\n To initialize an instance object instanceObject from a WebAssembly module module and instance instance, perform the following steps:\n\n 1. Create an exports object from module and instance and let exportsObject be the result.\n 1. Set instanceObject.\\[[Instance]] to instance.\n 1. Set instanceObject.\\[[Exports]] to exportsObject.\n\n To instantiate the core of a WebAssembly module from a module module and imports imports, perform the following steps:\n 1. Let store be the surrounding agent's associated store.\n 1. Let result be module_instantiate(store, module, imports).\n 1. If result is error, throw an appropriate exception type:\n A LinkError exception for most cases which occur during linking.\n If the error came when running the start function, throw a RuntimeError for most errors which occur from WebAssembly, or the error object propagated from inner ECMAScript code.\n Another error type if appropriate, for example an out-of-memory exception, as documented in the WebAssembly error mapping.\n 1. Let (store, instance) be result.\n 1. Set the surrounding agent's associated store to store.\n 1. Return instance.\n\n To asynchronously instantiate a WebAssembly module from a Module moduleObject and imports importObject, perform the following steps:\n 1. Let promise be a new promise.\n 1. Let module be moduleObject.\\[[Module]].\n 1. Let builtinSetNames be moduleObject.\\[[BuiltinSets]].\n 1. Let importedStringModule be moduleObject.\\[[ImportedStringModule]].\n 1. Read the imports of module with imports importObject, builtinSetNames and importedStringModule, and let imports be the result.\n If this operation throws an exception, catch it, reject promise with the exception, and return promise.\n 1. Run the following steps in parallel:\n 1. Queue a task to perform the following steps:\n Note: Implementation-specific work may be performed here.\n 1. Instantiate the core of a WebAssembly module module with imports, and let instance be the result.\n If this throws an exception, catch it, reject promise with the exception, and terminate these substeps.\n 1. Let instanceObject be a /new Instance.\n 1. Initialize instanceObject from module and instance.\n If this throws an exception, catch it, reject promise with the exception, and terminate these substeps.\n 1. Resolve promise with instanceObject.\n 1. Return promise.\n\n To instantiate a promise of a module promiseOfModule with imports importObject, perform the following steps:\n\n 1. Let promise be a new promise.\n 1. React to promiseOfModule:\n If promiseOfModule was fulfilled with value module:\n 1. Instantiate the WebAssembly module module importing importObject, and let innerPromise be the result.\n 1. React to innerPromise:\n If innerPromise was fulfilled with value instance.\n 1. Let result be the WebAssemblyInstantiatedSource value «[ \"WebAssemblyInstantiatedSource\" → module, \"WebAssemblyInstantiatedSource\" → instance ]».\n 1. Resolve promise with result.\n If innerPromise was rejected with reason reason:\n 1. Reject promise with reason.\n * If promiseOfModule was rejected with reason reason:\n 1. Reject promise with reason.\n 1. Return promise.\n\n The instantiate(bytes, importObject, options) method, when invoked, performs the following steps:\n 1. Let stableBytes be a copy of the bytes held by the buffer bytes.\n 1. Asynchronously compile a WebAssembly module from stableBytes using options and let promiseOfModule be the result.\n 1. Instantiate promiseOfModule with imports importObject and return the result.\n\n The instantiate(moduleObject, importObject) method, when invoked, performs the following steps:\n 1. Asynchronously instantiate the WebAssembly module moduleObject importing importObject, and return the result.\n\nNote: A follow-on streaming API is documented in the WebAssembly Web API.\n\nThe getter of the JSTag attribute of the WebAssembly Namespace, when invoked, performs the following steps:\n 1. Let JSTagAddr be the result of getting the JavaScript exception tag.\n 1. Let JSTagObject be the result of creating a Tag object from JSTagAddr.\n 1. Return JSTagObject.","crossrefs":["module_decode","error","module_validate","validate builtin set names","list/iterate","module_imports","match_externtype","validate an import for builtins","get a copy of the buffer source","Compile a WebAssembly module","validate builtins and imported string for a WebAssembly module","/module","/new","task source","a new promise","in parallel","compile a WebAssembly module","Queue a task","Construct a WebAssembly module object","Resolve","Asynchronously compile a WebAssembly module","!","iteration/continue","imports","list/is empty","instantiate a builtin set","map/set","instantiate imported strings","map/exist","is not an Object","?","external-type/func","Exported Function","Create a host function","external value","list/Append","external-type/global","implements","i64","is not a BigInt","i32","f32","f64","is not a Number","v128","ToWebAssemblyValue","surrounding agent","associated store","global_alloc","const","external-type/mem","implement","external-type/table","external-type/tag","tagtype/attribute/exception","external value/tag","instantiate the core of a WebAssembly module","module_exports","instance_export","a new Exported Function","create a global object","create a memory object","create a Table object","create a Tag object","WebAssembly module validation","Create an exports object","module_instantiate","Read the imports","reject","Instantiate the core of a WebAssembly module","initialize an instance object","React","asynchronously instantiate a WebAssembly module","Reject","Instantiate a promise of a module","get the JavaScript exception tag","Module","WebAssemblyCompileOptions","CompileError","TypeError","LinkError","Global","Memory","Table","Tag","RuntimeError","Instance","WebAssemblyInstantiatedSource","WebAssembly"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#webassembly-namespace"},{"id":"modules","anchors":["modules"],"title":"Modules","level":3,"path":"js-api","prose":"The string value of the extern type type is\n \"function\" if type is of the form external-type/func functype\n \"table\" if type is of the form external-type/table tabletype\n \"memory\" if type is of the form external-type/mem memtype\n \"global\" if type is of the form external-type/global globaltype\n * \"tag\" if type is of the form external-type/tag tag\n\n The exports(moduleObject) method, when invoked, performs the following steps:\n 1. Let module be moduleObject.\\[[Module]].\n 1. Let exports be « ».\n 1. For each (name, type) of module_exports(module),\n 1. Let kind be the string value of the extern type type.\n 1. Let obj be «[ \"ModuleExportDescriptor\" → name, \"ModuleExportDescriptor\" → kind ]».\n 1. list/Append obj to exports.\n 1. Return exports.\n\n The imports(moduleObject) method, when invoked, performs the following steps:\n 1. Let module be moduleObject.\\[[Module]].\n 1. Let builtinSetNames be moduleObject.\\[[BuiltinSets]].\n 1. Let importedStringModule be moduleObject.\\[[ImportedStringModule]].\n 1. Let imports be « ».\n 1. For each (moduleName, name, type) of module_imports(module),\n 1. If find a builtin for (moduleName, name, type) and builtinSetNames is not null, then iteration/continue.\n 1. If importedStringModule is not null and moduleName equals importedStringModule, then iteration/continue.\n 1. Let kind be the string value of the extern type type.\n 1. Let obj be «[ \"ModuleImportDescriptor\" → moduleName, \"ModuleImportDescriptor\" → name, \"ModuleImportDescriptor\" → kind ]».\n 1. list/Append obj to imports.\n 1. Return imports.\n\n The customSections(moduleObject, sectionName) method, when invoked, performs the following steps:\n 1. Let bytes be moduleObject.\\[[Bytes]].\n 1. Let customSections be « ».\n 1. For each custom section customSection of bytes, interpreted according to the module grammar,\n 1. Let name be the name of customSection, decoded as UTF-8.\n 1. Assert: name is not failure (moduleObject.\\[[Module]] is valid).\n 1. If name equals sectionName as string values,\n 1. list/Append a new ArrayBuffer containing a copy of the bytes in bytes for the range matched by this customsec production to customSections.\n 1. Return customSections.\n\n The Module(bytes, options) constructor, when invoked, performs the following steps:\n\n 1. Let stableBytes be a copy of the bytes held by the buffer bytes.\n 1. Compile the WebAssembly module stableBytes and store the result as module.\n 1. If module is error, throw a CompileError exception.\n 1. Let builtinSetNames be options[\"builtins\"].\n 1. Let importedStringModule be options[\"importedStringConstants\"].\n 1. If validating builtins and imported strings for module with builtinSetNames and importedStringModule returns false, throw a CompileError exception.\n 1. Set this.\\[[Module]] to module.\n 1. Set this.\\[[Bytes]] to stableBytes.\n 1. Set this.\\[[BuiltinSets]] to builtinSetNames.\n 1. Set this.\\[[ImportedStringModule]] to importedStringModule.\n\nNote: Some implementations enforce a size limitation on bytes. Use of this API is discouraged, in favor of asynchronous APIs.","crossrefs":["external-type/func","external-type/table","external-type/mem","external-type/global","external-type/tag","list/iterate","module_exports","string value of the extern type","list/Append","module_imports","find a builtin","iteration/continue","custom section","module grammar","UTF-8 decode without BOM or fail","valid","customsec","get a copy of the buffer source","Compile a WebAssembly module","error","validate builtins and imported string for a WebAssembly module","ModuleExportDescriptor","ModuleImportDescriptor","ArrayBuffer","CompileError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#modules"},{"id":"instances","anchors":["instances"],"title":"Instances","level":3,"path":"js-api","prose":"The Instance(moduleObject, importObject) constructor, when invoked, runs the following steps:\n 1. Let builtinSetNames be moduleObject.\\[[BuiltinSets]].\n 1. Let importedStringModule be moduleObject.\\[[ImportedStringModule]].\n 1. Let module be moduleObject.\\[[Module]].\n 1. Read the imports of module with imports importObject, builtinSetNames, and importedStringModule, and let imports be the result.\n 1. Instantiate the core of a WebAssembly module module with imports, and let instance be the result.\n 1. Initialize this from module and instance.\n\nNote: The use of this synchronous API is discouraged, as some implementations sometimes do long-running compilation work when instantiating.\n\n The getter of the exports attribute of Instance returns this.\\[[Exports]].","crossrefs":["Read the imports","Instantiate the core of a WebAssembly module","initialize an instance object","Instance"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#instances"},{"id":"memories","anchors":["memories"],"title":"Memories","level":3,"path":"js-api","prose":"A Memory object represents a single memory instance\nwhich can be simultaneously referenced by multiple Instance objects. Each\nMemory object has the following internal slots:\n\n \\[[Memory]] : a memory address\n \\[[BufferObject]] : an ArrayBuffer whose Data Block is identified with the above memory address\n\n To create a fixed length memory buffer from a memory address memaddr, perform the following steps:\n\n 1. Let block be a Data Block which is identified with the underlying memory of memaddr.\n 1. Let buffer be a new ArrayBuffer with the internal slots \\[[ArrayBufferData]], \\[[ArrayBufferByteLength]], and \\[[ArrayBufferDetachKey]].\n 1. Set buffer.\\[[ArrayBufferData]] to block.\n 1. Set buffer.\\[[ArrayBufferByteLength]] to the length of block.\n 1. Set buffer.\\[[ArrayBufferDetachKey]] to \"WebAssembly.Memory\".\n 1. Return buffer.\n\n To create a resizable memory buffer from a memory address memaddr and a maxsize, perform the following steps:\n\n 1. Let block be a Data Block which is identified with the underlying memory of memaddr.\n 1. Let length be the length of block.\n 1. Let buffer be a new ArrayBuffer with the internal slots \\[[ArrayBufferData]], \\[[ArrayBufferByteLength]], \\[[ArrayBufferMaxByteLength]], and \\[[ArrayBufferDetachKey]].\n 1. Set buffer.\\[[ArrayBufferData]] to block.\n 1. Set buffer.\\[[ArrayBufferByteLength]] to length.\n 1. Set buffer.\\[[ArrayBufferMaxByteLength]] to maxsize.\n 1. Set buffer.\\[[ArrayBufferDetachKey]] to \"WebAssembly.Memory\".\n 1. Return buffer.\n\n To initialize a memory object memory from a memory address memaddr, perform the following steps:\n 1. Let map be the surrounding agent's associated Memory object cache.\n 1. Assert: map[memaddr] doesn't map/exist.\n 1. Let buffer be the result of creating a fixed length memory buffer from memaddr.\n 1. Set memory.\\[[Memory]] to memaddr.\n 1. Set memory.\\[[BufferObject]] to buffer.\n 1. map/Set map[memaddr] to memory.\n\n To create a memory object from a memory address memaddr, perform the following steps:\n\n 1. Let map be the surrounding agent's associated Memory object cache.\n 1. If map[memaddr] map/exists,\n 1. Return map[memaddr].\n 1. Let memory be a /new Memory.\n 1. Initialize memory from memaddr.\n 1. Return memory.\n\n The Memory(descriptor) constructor, when invoked, performs the following steps:\n 1. If descriptor[\"address\"] map/exists, let addrtype be descriptor[\"address\"]; otherwise, let addrtype be \"i32\".\n 1. Let initial be ? AddressValueToU64(descriptor[\"initial\"], addrtype).\n 1. If descriptor[\"maximum\"] map/exists, let maximum be ? AddressValueToU64(descriptor[\"maximum\"], addrtype); otherwise, let maximum be empty.\n 1. Let memtype be memory type addrtype { min initial, max maximum }.\n 1. If memtype is not valid, throw a RangeError exception.\n 1. Let store be the surrounding agent's associated store.\n 1. Let (store, memaddr) be mem_alloc(store, memtype). If allocation fails, throw a RangeError exception.\n 1. Set the surrounding agent's associated store to store.\n 1. Initialize this from memaddr.\n\n To refresh the Memory buffer of memaddr, perform the following steps:\n\n 1. Let map be the surrounding agent's associated Memory object cache.\n 1. Assert: map[memaddr] map/exists.\n 1. Let memory be map[memaddr].\n 1. Let buffer be memory.\\[[BufferObject]].\n 1. If IsFixedLengthArrayBuffer(buffer) is true,\n 1. Perform ! [$DetachArrayBuffer$](buffer, \"WebAssembly.Memory\").\n 1. Let buffer be the result of creating a fixed length memory buffer from memaddr.\n 1. Set memory.\\[[BufferObject]] to buffer.\n 1. Otherwise,\n 1. Let block be a Data Block which is identified with the underlying memory of memaddr.\n 1. Set buffer.\\[[ArrayBufferData]] to block.\n 1. Set buffer.\\[[ArrayBufferByteLength]] to the length of block.\n\n To grow the memory buffer associated with a memory address memaddr by delta, perform the following steps:\n\n 1. Let store be the surrounding agent's associated store.\n 1. Let ret be the mem_size(store, memaddr).\n 1. Let store be mem_grow(store, memaddr, delta).\n 1. If store is error, throw a RangeError exception.\n 1. Set the surrounding agent's associated store to store.\n 1. Refresh the memory buffer of memaddr.\n 1. Return ret.\n\n The grow(delta) method, when invoked, performs the following steps:\n 1. Let memaddr be this.\\[[Memory]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let addrtype be the address type in mem_type(store, memaddr).\n 1. Let delta64 be ? AddressValueToU64(delta, addrtype).\n 1. Let ret be the result of growing the memory buffer associated with memaddr by delta64.\n 1. Return U64ToAddressValue(ret, addrtype).\n\nImmediately after a WebAssembly memory.grow x instruction executes, perform the following steps:\n\n 1. If the top of the stack is not i32.const (−1) and the top of the stack is not i64.const (−1),\n 1. Let frame be the current frame.\n 1. Assert: due to validation, frame.frame/module.moduleinst/memaddrs[x] exists.\n 1. Let memaddr be the memory address frame.frame/module.moduleinst/memaddrs[x].\n 1. Refresh the memory buffer of memaddr.\n\n The toFixedLengthBuffer() method, when invoked, performs the following steps:\n 1. Let buffer be this.\\[[BufferObject]].\n 1. If IsFixedLengthArrayBuffer(buffer) is true, return buffer.\n 1. Let memaddr be this.\\[[Memory]].\n 1. Let fixedBuffer be the result of creating a fixed length memory buffer from memaddr.\n 1. Perform ! [$DetachArrayBuffer$](buffer, \"WebAssembly.Memory\").\n 1. Set this.\\[[BufferObject]] to fixedBuffer.\n 1. Return fixedBuffer.\n\n The toResizableBuffer() method, when invoked, performs the following steps:\n 1. Let memaddr be this.\\[[Memory]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let memtype be mem_type(store, memaddr).\n 1. If memtype does not have a max,\n 1. Throw a TypeError exception.\n 1. Let buffer be this.\\[[BufferObject]].\n 1. If IsFixedLengthArrayBuffer(buffer) is false, return buffer.\n 1. Assert: memtype has a max.\n 1. Let maxsize be the max value in memtype * 65536.\n 1. Let resizableBuffer be the result of creating a resizable memory buffer from memaddr and maxsize.\n 1. Perform ! [$DetachArrayBuffer$](buffer, \"WebAssembly.Memory\").\n 1. Set this.\\[[BufferObject]] to resizableBuffer.\n 1. Return resizableBuffer.\n\nArrayBuffer objects returned by a Memory object must have a size that is a multiple of a WebAssembly page size (the constant 65536). For this reason HostResizeArrayBuffer is redefined as follows.\n\n The abstract operation HostResizeArrayBuffer takes arguments buffer (an ArrayBuffer) and newLength. It performs the following steps when called.\n\n 1. If buffer.\\[[ArrayBufferDetachKey]] is \"WebAssembly.Memory\",\n 1. Let map be the surrounding agent's associated Memory object cache.\n 1. Assert: buffer is the \\[[BufferObject]] of exactly one value in map.\n 1. For each memaddr &rarr; mem in map,\n 1. If SameValue(mem.\\[[BufferObject]], buffer) is true,\n 1. Assert: buffer.\\[[ArrayBufferByteLength]] modulo 65536 is 0.\n 1. Let lengthDelta be newLength - buffer.\\[[ArrayBufferByteLength]].\n 1. If lengthDelta < 0 or lengthDelta modulo 65536 is not 0,\n 1. Throw a RangeError exception.\n 1. Let delta be lengthDelta &div; 65536.\n 1. Grow the memory buffer associated with memaddr by delta.\n 1. Return handled.\n 1. Otherwise, return unhandled.\n\n The getter of the buffer attribute of Memory returns this.\\[[BufferObject]].","crossrefs":["memory instance","memory address","Data Block","identified with","surrounding agent","Memory object cache","map/exist","create a fixed length memory buffer","map/Set","map/exists","/new","initialize a memory object","?","AddressValueToU64","memory type","valid memtype","associated store","mem_alloc","IsFixedLengthArrayBuffer","!","mem_size","mem_grow","error","Refresh the memory buffer","address type","mem_type","grow the memory buffer","U64ToAddressValue","memory.grow","i32.const","i64.const","current frame","frame/module","moduleinst/memaddrs","Throw","create a resizable memory buffer","page size","HostResizeArrayBuffer","map/iterate","SameValue","Grow the memory buffer","Memory","Instance","ArrayBuffer","RangeError","TypeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#memories"},{"id":"tables","anchors":["tables"],"title":"Tables","level":3,"path":"js-api","prose":"A Table object represents a single table instance which can be simultaneously referenced by\nmultiple Instance objects.\nEach Table object has a \\[[Table]] internal slot, which is a table address.\n\n To initialize a table object table from a table address tableaddr, perform the following steps:\n 1. Let map be the surrounding agent's associated Table object cache.\n 1. Assert: map[tableaddr] doesn't map/exist.\n 1. Set table.\\[[Table]] to tableaddr.\n 1. map/Set map[tableaddr] to table.\n\n To create a table object from a table address tableaddr, perform the following steps:\n 1. Let map be the surrounding agent's associated Table object cache.\n 1. If map[tableaddr] map/exists,\n 1. Return map[tableaddr].\n 1. Let table be a /new Table.\n 1. Initialize table from tableaddr.\n 1. Return table.\n\n The Table(descriptor, value) constructor, when invoked, performs the following steps:\n 1. Let elementtype be ToValueType(descriptor[\"element\"]).\n 1. If elementtype is not a reftype,\n 1. Throw a TypeError exception.\n 1. If descriptor[\"address\"] map/exists, let addrtype be descriptor[\"address\"]; otherwise, let addrtype be \"i32\".\n 1. Let initial be ? AddressValueToU64(descriptor[\"initial\"], addrtype).\n 1. If descriptor[\"maximum\"] map/exists, let maximum be ? AddressValueToU64(descriptor[\"maximum\"], addrtype); otherwise, let maximum be empty.\n 1. Let type be the table type addrtype { min initial, max maximum } elementtype.\n 1. If type is not valid, throw a RangeError exception.\n 1. If value is missing,\n 1. Let ref be DefaultValue(elementtype).\n 1. Assert: ref is not error.\n 1. Otherwise,\n 1. Let ref be ? ToWebAssemblyValue(value, elementtype).\n 1. Let store be the surrounding agent's associated store.\n 1. Let (store, tableaddr) be table_alloc(store, type, ref). If allocation fails, throw a RangeError exception.\n 1. Set the surrounding agent's associated store to store.\n 1. Initialize this from tableaddr.\n\n The grow(delta, value) method, when invoked, performs the following steps:\n 1. Let tableaddr be this.\\[[Table]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let initialSize be table_size(store, tableaddr).\n 1. Let (addrtype, limits, elementtype) be table_type(store, tableaddr).\n 1. Let delta64 be ? AddressValueToU64(delta, addrtype).\n 1. If value is missing,\n 1. Let ref be DefaultValue(elementtype).\n 1. If ref is error, throw a TypeError exception.\n 1. Otherwise,\n 1. Let ref be ? ToWebAssemblyValue(value, elementtype).\n 1. Let result be table_grow(store, tableaddr, delta64, ref).\n 1. If result is error, throw a RangeError exception.\n\n Note: The above exception can happen due to either insufficient memory or an invalid size parameter.\n\n 1. Set the surrounding agent's associated store to result.\n 1. Return U64ToAddressValue(initialSize, addrtype).\n\n The getter of the length attribute of Table, when invoked, performs the following steps:\n 1. Let tableaddr be this.\\[[Table]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let addrtype be the address type in table_type(store, tableaddr).\n 1. Let length64 be table_size(store, tableaddr).\n 1. Return U64ToAddressValue(length64, addrtype).\n\n The get(index) method, when invoked, performs the following steps:\n 1. Let tableaddr be this.\\[[Table]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let (addrtype, limits, elementtype) be table_type(store, tableaddr).\n 1. If elementtype matches exnref,\n 1. Throw a TypeError exception.\n 1. Let index64 be ? AddressValueToU64(index, addrtype).\n 1. Let result be table_read(store, tableaddr, index64).\n 1. If result is error, throw a RangeError exception.\n 1. Return ! ToJSValue(result).\n\n The set(index, value) method, when invoked, performs the following steps:\n 1. Let tableaddr be this.\\[[Table]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let (addrtype, limits, elementtype) be table_type(store, tableaddr).\n 1. If elementtype matches exnref,\n 1. Throw a TypeError exception.\n 1. Let index64 be ? AddressValueToU64(index, addrtype).\n 1. If value is missing,\n 1. Let ref be DefaultValue(elementtype).\n 1. If ref is error, throw a TypeError exception.\n 1. Otherwise,\n 1. Let ref be ? ToWebAssemblyValue(value, elementtype).\n 1. Let store be table_write(store, tableaddr, index64, ref).\n 1. If store is error, throw a RangeError exception.\n 1. Set the surrounding agent's associated store to store.","crossrefs":["table instance","table address","surrounding agent","Table object cache","map/exist","map/Set","map/exists","/new","initialize a table object","ToValueType","reftype","Throw","?","AddressValueToU64","table type","limits","valid tabletype","DefaultValue","error","ToWebAssemblyValue","associated store","table_alloc","table_size","table_type","table_grow","U64ToAddressValue","address type","matches/reftype","exnref","table_read","!","ToJSValue","table_write","Table","Instance","TypeError","RangeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#tables"},{"id":"globals","anchors":["globals"],"title":"Globals","level":3,"path":"js-api","prose":"Note: this type may be extended with additional cases in future versions of WebAssembly.\n\n \n\nA Global object represents a single global instance\nwhich can be simultaneously referenced by multiple Instance objects. Each\nGlobal object has one internal slot:\n\n * \\[[Global]] : a global address\n\n To initialize a global object global from a global address globaladdr, perform the following steps:\n 1. Let map be the surrounding agent's associated Global object cache.\n 1. Assert: map[globaladdr] doesn't map/exist.\n 1. Set global.\\[[Global]] to globaladdr.\n 1. map/Set map[globaladdr] to global.\n\n To create a global object from a global address globaladdr, perform the following steps:\n 1. Let map be the surrounding agent's associated Global object cache.\n 1. If map[globaladdr] map/exists,\n 1. Return map[globaladdr].\n 1. Let global be a /new Global.\n 1. Initialize global from globaladdr.\n 1. Return global.\n\n The algorithm ToValueType(s) performs the following steps:\n 1. If s equals \"i32\", return i32.\n 1. If s equals \"i64\", return i64.\n 1. If s equals \"f32\", return f32.\n 1. If s equals \"f64\", return f64.\n 1. If s equals \"v128\", return v128.\n 1. If s equals \"anyfunc\", return funcref.\n 1. If s equals \"externref\", return externref.\n 1. Assert: This step is not reached.\n\n The algorithm DefaultValue(valuetype) performs the following steps:\n 1. If valuetype equals externref, return ! ToWebAssemblyValue(undefined, valuetype).\n 1. Return val_default(valuetype).\n\n The Global(descriptor, v) constructor, when invoked, performs the following steps:\n 1. Let mutable be descriptor[\"mutable\"].\n 1. Let valuetype be ToValueType(descriptor[\"value\"]).\n 1. If valuetype matches v128 or exnref,\n 1. Throw a TypeError exception.\n 1. If v is missing,\n 1. Let value be DefaultValue(valuetype).\n 1. Assert: value is not error.\n 1. Otherwise,\n 1. Let value be ? ToWebAssemblyValue(v, valuetype).\n 1. If mutable is true, let globaltype be var valuetype; otherwise, let globaltype be const valuetype.\n 1. Let store be the surrounding agent's associated store.\n 1. Let (store, globaladdr) be global_alloc(store, globaltype, value). \n 1. Set the surrounding agent's associated store to store.\n 1. Initialize this from globaladdr.\n\n The algorithm GetGlobalValue(Global global) performs the following steps:\n 1. Let store be the surrounding agent's associated store.\n 1. Let globaladdr be global.\\[[Global]].\n 1. Let globaltype be global_type(store, globaladdr).\n 1. If globaltype is of the form mut valuetype where valuetype matches v128 or exnref, throw a TypeError.\n 1. Let value be global_read(store, globaladdr).\n 1. Return ! ToJSValue(value).\n\n The getter of the value attribute of Global, when invoked, performs the following steps:\n 1. Return GetGlobalValue(this).\n\n The setter of the value attribute of Global, when invoked, performs the following steps:\n 1. Let store be the surrounding agent's associated store.\n 1. Let globaladdr be this.\\[[Global]].\n 1. Let mut valuetype be global_type(store, globaladdr).\n 1. If valuetype matches v128 or exnref, throw a TypeError.\n 1. If mut is const, throw a TypeError.\n 1. Let value be ? ToWebAssemblyValue(the given value, valuetype).\n 1. Let store be global_write(store, globaladdr, value).\n 1. If store is error, throw a RangeError exception.\n 1. Set the surrounding agent's associated store to store.\n\n The valueOf() method, when invoked, performs the following steps:\n 1. Return GetGlobalValue(this).","crossrefs":["global instance","global address","surrounding agent","Global object cache","map/exist","map/Set","map/exists","/new","initialize a global object","i32","i64","f32","f64","v128","funcref","externref","!","ToWebAssemblyValue","val_default","ToValueType","matches/valtype","exnref","DefaultValue","error","?","var","const","associated store","global_alloc","global_type","global_read","ToJSValue","GetGlobalValue","global_write","Global","Instance","TypeError","RangeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#globals"},{"id":"exported-function-exotic-objects","anchors":["exported-function-exotic-objects"],"title":"Exported Functions","level":3,"path":"js-api","prose":"A WebAssembly function is made available in JavaScript as an Exported Function.\nExported Functions are Built-in Function Objects which are not constructors, and which have a \\[[FunctionAddress]] internal slot.\nThis slot holds a function address relative to the surrounding agent's associated store.\n\n The name of the WebAssembly function funcaddr is found by performing the following steps:\n\n 1. Let store be the surrounding agent's associated store.\n 1. Let funcinst be store.funcs[funcaddr].\n 1. If funcinst is of the form {type functype, hostcode hostfunc},\n 1. Assert: hostfunc is a JavaScript object and [$IsCallable$](hostfunc) is true.\n 1. Let index be the index of the host function funcaddr.\n 1. Otherwise,\n 1. Let moduleinst be funcinst.module.\n 1. Assert: funcaddr is contained in moduleinst.funcaddrs.\n 1. Let index be the index of moduleinst.funcaddrs where funcaddr is found.\n 1. Return ! [$ToString$](index).\n\n To create a new Exported Function from a WebAssembly function address funcaddr, perform the following steps:\n\n 1. Let map be the surrounding agent's associated Exported Function cache.\n 1. If map[funcaddr] map/exists,\n 1. Return map[funcaddr].\n 1. Let steps be \"call the Exported Function funcaddr with arguments.\"\n 1. Let realm be the current Realm.\n 1. Let store be the surrounding agent's associated store.\n 1. Let functype be func_type(store, funcaddr).\n 1. Let [paramTypes] → [resultTypes] be functype.\n 1. Let arity be paramTypes's list/size.\n 1. Let name be the name of the WebAssembly function funcaddr.\n 1. Let function be ! [$CreateBuiltinFunction$](steps, arity, name, « \\[[FunctionAddress]] », realm).\n 1. Set function.\\[[FunctionAddress]] to funcaddr.\n 1. map/Set map[funcaddr] to function.\n 1. Return function.\n\n To call an Exported Function with function address funcaddr and a list of JavaScript arguments argValues, perform the following steps:\n\n 1. Let store be the surrounding agent's associated store.\n 1. Let functype be func_type(store, funcaddr).\n 1. Let [parameters] → [results] be functype.\n 1. If any type in parameters or results matches v128 or exnref, throw a TypeError.\n\n Note: the above error is thrown each time the \\[[Call]] method is invoked.\n 1. Let args be « ».\n 1. Let i be 0.\n 1. For each t of parameters,\n 1. If argValues's list/size > i, let arg be argValues[i].\n 1. Otherwise, let arg be undefined.\n 1. list/Append ? ToWebAssemblyValue(arg, t) to args.\n 1. Set i to i + 1.\n 1. Let (store, ret) be the result of func_invoke(store, funcaddr, args).\n 1. Set the surrounding agent's associated store to store.\n 1. If ret is error, throw an exception. This exception should be a WebAssembly RuntimeError exception, unless otherwise indicated by the WebAssembly error mapping.\n 1. If ret is exception exnaddr, then\n 1. Let tagaddr be exn_tag(store, exnaddr).\n 1. Let payload be exn_read(store, exnaddr).\n 1. Let jsTagAddr be the result of getting the JavaScript exception tag.\n 1. If tagaddr is equal to jsTagAddr,\n 1. Throw ! ToJSValue(payload[0]).\n 1. Otherwise,\n 1. Let exception be a new Exception created from exnaddr.\n 1. Throw exception.\n 1. Let outArity be the list/size of ret.\n 1. If outArity is 0, return undefined.\n 1. Otherwise, if outArity is 1, return ! ToJSValue(ret[0]).\n 1. Otherwise,\n 1. Let values be « ».\n 1. For each r of ret,\n 1. list/Append ! ToJSValue(r) to values.\n 1. Return [$CreateArrayFromList$](values).\n\nNote: Calling an Exported Function executes in the \\[[Realm]] of the callee Exported Function, as per the definition of built-in function objects.\n\nNote: Exported Functions do not have a \\[[Construct]] method and thus it is not possible to call one with the new operator.\n\n To run a host function from the JavaScript object func, type functype, and list of WebAssembly values arguments, perform the following steps:\n\n 1. Let [parameters] → [results] be functype.\n 1. If any type in parameters or results matches v128 or exnref, throw a TypeError.\n 1. Let jsArguments be « ».\n 1. For each arg of arguments,\n 1. list/Append ! ToJSValue(arg) to jsArguments.\n 1. Let ret be ? [$Call$](func, undefined, jsArguments).\n 1. Let resultsSize be results's list/size.\n 1. If resultsSize is 0, return « ».\n 1. Otherwise, if resultsSize is 1, return « ? ToWebAssemblyValue(ret, results[0]) ».\n 1. Otherwise,\n 1. Let method be ? [$GetMethod$](ret, %Symbol.iterator%).\n 1. If method is undefined, throw a TypeError.\n 1. Let values be ? [$IteratorToList$](? [$GetIteratorFromMethod$](ret, method)).\n 1. Let wasmValues be a new, empty list.\n 1. If values's list/size is not resultsSize, throw a TypeError exception.\n 1. For each value and resultType in values and results, paired linearly,\n 1. list/Append ? ToWebAssemblyValue(value, resultType) to wasmValues.\n 1. Return wasmValues.\n\n To create a host function from the JavaScript object func and type functype, perform the following steps:\n\n 1. Assert: [$IsCallable$](func).\n 1. Let stored settings be the incumbent settings object.\n 1. Let hostfunc be a host function which performs the following steps when called with arguments arguments:\n 1. Let realm be func's associated Realm.\n 1. Let relevant settings be realm's realm/settings object.\n 1. Prepare to run script with relevant settings.\n 1. Prepare to run a callback with stored settings.\n 1. Let result be the result of running a host function from func, functype, and arguments.\n 1. Clean up after running a callback with stored settings.\n 1. Clean up after running script with relevant settings.\n 1. Assert: result.\\[[Type]] is throw or normal.\n 1. Let store be the surrounding agent's associated store.\n 1. If result.\\[[Type]] is throw, then:\n 1. Let v be result.\\[[Value]].\n 1. If v implements Exception,\n 1. Let address be v.\\[[Address]].\n 1. Otherwise,\n 1. Let type be the result of getting the JavaScript exception tag.\n 1. Let payload be ! ToWebAssemblyValue(v, externref).\n 1. Let (store, address) be exn_alloc(store, type, « payload »).\n 1. Set the surrounding agent's associated store to store.\n 1. Execute the WebAssembly instructions (ref.exn address) (throw_ref).\n 1. Otherwise, return result.\\[[Value]].\n 1. Let store be the surrounding agent's associated store.\n 1. Let (store, funcaddr) be func_alloc(store, functype, hostfunc).\n 1. Set the surrounding agent's associated store to store.\n 1. Return funcaddr.\n\nThe algorithm ToJSValue(w) coerces a WebAssembly value to a JavaScript value by performing the following steps:\n\n1. Assert: w is not of the form v128.const v128.\n1. Assert: w is not of the form ref.exn exnaddr.\n1. If w is of the form i64.const u64,\n 1. Let i64 be signed_64(u64).\n 1. Return ℤ(i64 interpreted as a mathematical value).\n1. If w is of the form i32.const u32,\n 1. Let i32 be signed_32(u32).\n 1. Return 𝔽(i32 interpreted as a mathematical value).\n1. If w is of the form f32.const f32,\n 1. If f32 is +∞ or −∞, return +∞𝔽 or -∞𝔽, respectively.\n 1. If f32 is nan, return NaN.\n 1. Return 𝔽(f32 interpreted as a mathematical value).\n1. If w is of the form f64.const f64,\n 1. If f64 is +∞ or −∞, return +∞𝔽 or -∞𝔽, respectively.\n 1. If f64 is nan, return NaN.\n 1. Return 𝔽(f64 interpreted as a mathematical value).\n1. If w is of the form ref.null t, return null.\n1. If w is of the form ref.i31 u31,\n 1. Let i31 be signed_31(u31).\n 1. Return 𝔽(i31).\n1. If w is of the form ref.struct structaddr, return the result of creating a new Exported GC Object from structaddr and \"struct\".\n1. If w is of the form ref.array arrayaddr, return the result of creating a new Exported GC Object from arrayaddr and \"array\".\n1. If w is of the form ref.func funcaddr, return the result of creating a new Exported Function from funcaddr.\n1. If w is of the form ref.host hostaddr, return the result of retrieving a host value from hostaddr.\n1. If w is of the form ref.extern ref, return ToJSValue(ref).\n\nNote: Number values which are equal to NaN may have various observable NaN payloads; see [$NumericToRawBytes$] for details.\n\nFor retrieving a host value from an host address hostaddr, perform the following steps:\n\n1. Let map be the surrounding agent's associated host value cache.\n1. Assert: map[hostaddr] map/exists.\n1. Return map[hostaddr].\n\nThe algorithm ToWebAssemblyValue(v, type) coerces a JavaScript value to a WebAssembly value by performing the following steps:\n\n1. Assert: type is not v128.\n1. Assert: type does not match exnref.\n1. If type is i64,\n 1. Let i64 be ? [$ToBigInt64$](v).\n 1. Let u64 be the unsigned integer such that i64 is signed_64(u64).\n 1. Return i64.const u64.\n1. If type is i32,\n 1. Let i32 be ? [$ToInt32$](v).\n 1. Let u32 be the unsigned integer such that i32 is signed_32(u32).\n 1. Return i32.const u32.\n1. If type is f32,\n 1. Let number be ? [$ToNumber$](v).\n 1. If number is NaN,\n 1. Let n be an implementation-defined integer such that canon32 &leq; n < 2signif(32).\n 1. Let f32 be nan(n).\n 1. Otherwise,\n 1. Let f32 be number rounded to the nearest representable value using IEEE 754-2019 round to nearest, ties to even mode. IEEE-754\n 1. Return f32.const f32.\n1. If type is f64,\n 1. Let number be ? [$ToNumber$](v).\n 1. If number is NaN,\n 1. Let n be an implementation-defined integer such that canon64 &leq; n < 2signif(64).\n 1. Let f64 be nan(n).\n 1. Otherwise,\n 1. Let f64 be number.\n 1. Return f64.const f64.\n1. If type is of the form ref null heaptype,\n 1. If v is null,\n 1. Let r be ref.null heaptype.\n 1. Else if match_valtype(type, ref null heap-type/extern),\n 1. Let ref be ! ToWebAssemblyValue(v, ref heap-type/any).\n 1. Let r be ref.extern ref.\n 1. Else if v is an Exported Function and match_valtype(type, ref null heap-type/func),\n 1. Let funcaddr be the value of v's \\[[FunctionAddress]] internal slot.\n 1. Let r be ref.func funcaddr.\n 1. Else if v is a Number and v is equal to ? [$ToInt32$](v) and ℝ(v) 30 and ℝ(v) ⩾ -230,\n 1. Let i31 be ? [$ToInt32$](v).\n 1. Let u31 be the unsigned integer such that i31 is signed_31(u31).\n 1. Let r be ref.i31 u31.\n 1. Else if v is an Exported GC Object,\n 1. Let objectaddr be the value of v's \\[[ObjectAddress]] internal slot.\n 1. Let objectkind be the value of v's \\[[ObjectKind]] internal slot.\n 1. If objectkind is \"array\",\n 1. Let r be ref.array objectaddr.\n 1. Else if objectkind is \"struct\",\n 1. Let r be ref.struct objectaddr.\n 1. Else,\n 1. Let map be the surrounding agent's associated host value cache.\n 1. If a host address hostaddr exists such that map[hostaddr] is the same as v,\n 1. Return ref.host hostaddr.\n 1. Let host address hostaddr be the smallest address such that map[hostaddr] map/exists is false.\n 1. map/Set map[hostaddr] to v.\n 1. Let r be ref.host hostaddr.\n 1. Let store be the surrounding agent's associated store.\n 1. Let actualtype be ref_type(store, r).\n 1. If match_valtype(actualtype, type) is false,\n 1. Throw a TypeError.\n 1. Return r.\n1. Assert: This step is not reached.\n\nThe algorithm AddressValueToU64(v, addrtype) converts a JavaScript value to a WebAssembly u64 for use in embedding operations. It is designed to act like [=[EnforceRange]=] unsigned long for AddressType \"i32\", and to extend these semantics to AddressType \"i64\", by performing the following steps:\n\n1. If addrtype is \"i32\",\n 1. Let n be ? [$ConvertToInt$](v, 32, \"unsigned\"), where the destination type is associated with [=[EnforceRange]=].\n\n Note: This is equivalent to the JS conversion rules for [=[EnforceRange]=] unsigned long.\n 1. Return ℝ(n) as a WebAssembly u64.\n1. If addrtype is \"i64\",\n 1. Let n be ? [$ToBigInt$](v).\n 1. If n < 0 or n > 264 &minus; 1, throw a TypeError.\n\n Note: This operation is designed to emulate [=[EnforceRange]=].\n 1. Return ℝ(n) as a WebAssembly u64.\n1. Assert: This step is not reached.\n\nThe algorithm U64ToAddressValue(v, addrtype) converts a u64 value from a WebAssembly embedding operation to the correct variant of AddressValue for an AddressType, by performing the following steps:\n\n1. If addrtype is \"i32\", return 𝔽(v interpreted as a mathematical value).\n1. Else if addrtype is \"i64\", return ℤ(v interpreted as a mathematical value).\n1. Assert: This step is not reached.","crossrefs":["Built-in Function Objects","function address","surrounding agent","associated store","index of the host function","!","Exported Function cache","map/exists","call an Exported Function","current Realm","func_type","list/size","name of the WebAssembly function","map/Set","list","matches/valtype","v128","exnref","list/iterate","list/Append","?","ToWebAssemblyValue","func_invoke","error","exception","exn_tag","exn_read","get the JavaScript exception tag","ToJSValue","create an Exception object","built-in function objects","WebAssembly values","throw","host function","associated Realm","realm/settings object","Prepare to run script","Prepare to run a callback","run a host function","Clean up after running a callback","Clean up after running script","implements","externref","exn_alloc","ref.exn","throw_ref","func_alloc","WebAssembly value","v128.const","i64.const","signed_64","ℤ","mathematical value","i32.const","signed_32","𝔽","f32.const","+∞","−∞","nan","f64.const","ref.null","ref.i31","signed_31","ref.struct","a new Exported GC Object","ref.array","ref.func","a new Exported Function","ref.host","retrieving a host value","ref.extern","host address","host value cache","i64","i32","f32","canon","signif","f64","ref","match_valtype","heap-type/extern","heap-type/any","Exported Function","heap-type/func","is a Number","ℝ","Exported GC Object","ref_type","u64","unsigned long","js-unsigned-long","TypeError","RuntimeError","%Symbol.iterator%","Exception","AddressType","AddressValue"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#exported-function-exotic-objects"},{"id":"tags","anchors":["tags"],"title":"Tags","level":3,"path":"js-api","prose":"","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#tags"},{"id":"tag-types","anchors":["tag-types"],"title":"Tag types","level":4,"path":"js-api","prose":"A Tag value represents an exception tag.\n\nTo initialize a Tag object tag from a tag address tagAddress, perform the following steps:\n\n1. Let map be the surrounding agent's associated Tag object cache.\n1. Assert: map[tagAddress] doesn't map/exist.\n1. Set tag.\\[[Address]] to tagAddress.\n1. map/Set map[tagAddress] to tag.\n\nTo create a Tag object from a tag address tagAddress, perform the following steps:\n\n1. Let map be the surrounding agent's associated Tag object cache.\n1. If map[tagAddress] map/exists,\n 1. Return map[tagAddress].\n1. Let tag be a /new Tag.\n1. Initialize tag from tagAddress.\n1. Return tag.\n\nThe new Tag(type) constructor steps are:\n\n1. Let parameters be type[\"parameters\"].\n1. Let wasmParameters be «».\n1. For each paramType of parameters,\n 1. list/Append ToValueType(paramType) to wasmParameters.\n1. Let store be the surrounding agent's associated store.\n1. Let (store, tagAddress) be tag_alloc(store, wasmParameters → « »).\n1. Set the surrounding agent's associated store to store.\n1. Initialize this from tagAddress.","crossrefs":["tag address","surrounding agent","Tag object cache","map/exist","map/Set","map/exists","/new","initialize a Tag object","list/iterate","list/Append","ToValueType","associated store","tag_alloc","Tag"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#tag-types"},{"id":"gc-exotic-objects","anchors":["gc-exotic-objects"],"title":"Garbage Collected Objects","level":3,"path":"js-api","prose":"A WebAssembly struct or array is made available in JavaScript as an Exported GC Object.\nAn Exported GC Object is an exotic object that wraps a garbage collected WebAssembly reference value.\nMost JavaScript operations on an Exported GC Object will throw an exception or return undefined.\n\nNote: These operations may be refined in the future to allow richer interactions in JavaScript with WebAssembly structs and arrays.\n\nAn Exported GC Object contains an \\[[ObjectAddress]] internal slot, which holds a object address relative to the surrounding agent's associated store,\nand an \\[[ObjectKind]] internal slot, which holds the string value \"struct\" or \"array\".\n\nThe internal methods of an Exported GC Object use the following implementations.\n\n The \\[[GetPrototypeOf]] internal method of an Exported GC Object O takes no arguments and returns null. It performs the following steps when called:\n\n 1. Return null.\n\n The \\[[SetPrototypeOf]] internal method of an Exported GC Object O takes argument V (an Object or null) and returns a boolean. It performs the following steps when called:\n\n 1. Return false.\n\n The \\[[IsExtensible]] internal method of an Exported GC Object O takes no arguments and returns a boolean. It performs the following steps when called:\n\n 1. Return false.\n\n The \\[[PreventExtensions]] internal method of an Exported GC Object O takes no arguments and returns a boolean. It performs the following steps when called:\n\n 1. Return false.\n\n The \\[[GetOwnProperty]] internal method of an Exported GC Object O takes argument P (a property key) and returns undefined. It performs the following steps when called:\n\n 1. Return undefined.\n\n The \\[[DefineOwnProperty]] internal method of an Exported GC Object O takes arguments P (a property key) and Desc (a property descriptor) and returns a boolean. It performs the following steps when called:\n\n 1. Return false.\n\n The \\[[HasProperty]] internal method of an Exported GC Object O takes argument P (a property key) and returns a boolean. It performs the following steps when called:\n\n 1. Return false.\n\n The \\[[Get]] internal method of an Exported GC Object O takes arguments P (a property key) and Receiver (an ECMAScript language value) and returns undefined. It performs the following steps when called:\n\n 1. Return undefined.\n\n The \\[[Set]] internal method of an Exported GC Object O takes arguments P (a property key), V (an ECMAScript language value), and Receiver (an ECMAScript language value) and throws an exception. It performs the following steps when called:\n\n 1. Throw a TypeError.\n\n The \\[[Delete]] internal method of an Exported GC Object O takes argument P (a property key) and throws an exception. It performs the following steps when called:\n\n 1. Throw a TypeError.\n\n The \\[[OwnPropertyKeys]] internal method of an Exported GC Object O takes no arguments and returns a list. It performs the following steps when called:\n\n 1. Let keys be a new empty list.\n 1. Return keys.\n\n To create a new Exported GC Object from a WebAssembly object address objectaddr and a string objectkind, perform the following steps:\n\n 1. Assert: objectkind is either \"array\" or \"struct\".\n 1. Let map be the surrounding agent's associated exported GC object cache.\n 1. If map[objectaddr] map/exists,\n 1. Return map[objectaddr].\n 1. Let object be MakeBasicObject(« \\[[ObjectAddress]], \\[[ObjectKind]] »).\n 1. Set object.\\[[ObjectAddress]] to objectaddr.\n 1. Set object.\\[[ObjectKind]] to objectkind.\n 1. Set object.\\[[GetPrototypeOf]] as specified in [=[[GetPrototypeOf]] internal method of an Exported GC Object=].\n 1. Set object.\\[[SetPrototypeOf]] as specified in [=[[SetPrototypeOf]] internal method of an Exported GC Object=].\n 1. Set object.\\[[IsExtensible]] as specified in [=[[IsExtensible]] internal method of an Exported GC Object=].\n 1. Set object.\\[[PreventExtensions]] as specified in [=[[PreventExtensions]] internal method of an Exported GC Object=].\n 1. Set object.\\[[GetOwnProperty]] as specified in [=[[GetOwnProperty]] internal method of an Exported GC Object=].\n 1. Set object.\\[[DefineOwnProperty]] as specified in [=[[DefineOwnProperty]] internal method of an Exported GC Object=].\n 1. Set object.\\[[HasProperty]] as specified in [=[[HasProperty]] internal method of an Exported GC Object=].\n 1. Set object.\\[[Get]] as specified in [=[[Get]] internal method of an Exported GC Object=].\n 1. Set object.\\[[Set]] as specified in [=[[Set]] internal method of an Exported GC Object=].\n 1. Set object.\\[[Delete]] as specified in [=[[Delete]] internal method of an Exported GC Object=].\n 1. Set object.\\[[OwnPropertyKeys]] as specified in [=[[OwnPropertyKeys]] internal method of an Exported GC Object=].\n 1. map/Set map[objectaddr] to object.\n 1. Return object.","crossrefs":["Exported GC Object","object address","surrounding agent","associated store","exported GC object cache","map/exists","MakeBasicObject","map/Set","TypeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#gc-exotic-objects"},{"id":"exceptions","anchors":["exceptions"],"title":"Exceptions","level":3,"path":"js-api","prose":"An Exception value represents an exception.\n\nTo initialize an Exception object exn from an Exception address exnAddress, perform the following steps:\n\n1. Let map be the surrounding agent's associated Exception object cache.\n1. Assert: map[exnAddress] doesn't map/exist.\n1. Set exn.\\[[Address]] to exnAddress.\n1. map/Set map[exnAddress] to exn.\n1. Let store be the surrounding agent's associated store.\n1. Let tagaddr be exn_tag(store, exnAddress).\n1. Let payload be exn_read(store, exnAddress).\n1. Set exn.\\[[Type]] to tagaddr.\n1. Set exn.\\[[Payload]] to payload.\n1. Set exn.\\[[Stack]] to undefined.\n\nTo create an Exception object from a exception address exnAddress, perform the following steps:\n\n1. Let map be the surrounding agent's associated Exception object cache.\n1. If map[exnAddress] map/exists,\n 1. Return map[exnAddress].\n1. Let exn be a /new Exception.\n1. Initialize exn from exnAddress.\n1. Return exn.\n\nThe new Exception(exceptionTag, payload, options)\nconstructor steps are:\n\n1. Let JSTagAddr be the result of getting the JavaScript exception tag.\n1. If exceptionTag.\\[[Address]] is equal to JSTagAddr,\n 1. Throw a TypeError.\n1. Let store be the surrounding agent's associated store.\n1. Let [types] → [] be tag_type(store, exceptionTag.\\[[Address]]).\n1. If types's list/size is not payload's list/size,\n 1. Throw a TypeError.\n1. Let wasmPayload be « ».\n1. For each value and resultType of payload and types, paired linearly,\n 1. If resultType matches v128 or exnref,\n 1. Throw a TypeError.\n 1. list/Append ? ToWebAssemblyValue(value, resultType) to wasmPayload.\n1. Let (store, exceptionAddr) be exn_alloc(store, exceptionTag.\\[[Address]], wasmPayload).\n1. Set the surrounding agent's associated store to store.\n1. Initialize this from exceptionAddr.\n1. If options[\"traceStack\"] is true,\n 1. Set this.\\[[Stack]] to either a DOMString representation of the current call stack or undefined.\n\nThe getArg(exceptionTag, index) method steps are:\n\n1. Let store be the surrounding agent's associated store.\n1. If this.\\[[Type]] is not equal to exceptionTag.\\[[Address]],\n 1. Throw a TypeError.\n1. Let tagaddr be exn_tag(store, this.\\[[Address]]).\n1. Let payload be exn_read(store, this.\\[[Address]]).\n1. Assert: tagaddr is equal to this.\\[[Type]].\n1. If index ≥ payload's list/size,\n 1. Throw a RangeError.\n1. Let [types] → [] be tag_type(store, tagaddr).\n1. If types[index] matches v128 or exnref,\n 1. Throw a TypeError.\n1. Return ! ToJSValue(payload[index]).\n\nThe is(exceptionTag) method steps are:\n\n1. If this.\\[[Type]] is not equal to exceptionTag.\\[[Address]],\n 1. Return false.\n1. Return true.\n\nThe stack getter steps are:\n\n1. Return this.\\[[Stack]].","crossrefs":["Exception address","surrounding agent","Exception object cache","map/exist","map/Set","associated store","exn_tag","exn_read","exception address","map/exists","/new","initialize an Exception object","get the JavaScript exception tag","tag_type","list/size","list/iterate","matches/valtype","v128","exnref","list/Append","?","ToWebAssemblyValue","exn_alloc","!","ToJSValue","Exception","TypeError","DOMString","RangeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#exceptions"},{"id":"js-exceptions","anchors":["js-exceptions"],"title":"JavaScript exceptions","level":4,"path":"js-api","prose":"The JavaScript exception tag is a tag address associated with\nthe surrounding agent. It is allocated in the agent's associated store on\nfirst use and cached. It always has the tag type « externref » → « ».\n\nTo get the JavaScript exception tag, perform the following steps:\n\n 1. If the surrounding agent's associated JavaScript exception tag has been initialized,\n 1. return the surrounding agent's associated JavaScript exception tag\n 1. Let store be the surrounding agent's associated store.\n 1. Let (store, tagAddress) be tag_alloc(store, « externref » → « »).\n 1. Set the surrounding agent's associated store to store.\n 1. Set the surrounding agent's associated JavaScript exception tag to tagAddress.\n 1. return tagAddress.","crossrefs":["tag address","associated store","tag type","externref","surrounding agent","JavaScript exception tag","tag_alloc"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-exceptions"},{"id":"error-objects","anchors":["error-objects"],"title":"Error Objects","level":3,"path":"js-api","prose":"WebAssembly defines the following Error classes: CompileError, LinkError, and RuntimeError.\n\nWhen the namespace object for the WebAssembly namespace is created, the following steps must be run:\n\n1. Let namespaceObject be the namespace object.\n1. For each error of « \"CompileError\", \"LinkError\", \"RuntimeError\" »,\n 1. Let constructor be a new object, implementing the NativeError Object Structure, with NativeError set to error.\n 1. ! [$DefineMethodProperty$](namespaceObject, error, constructor, false).\n\nNote: This defines CompileError, LinkError, and RuntimeError classes on the WebAssembly namespace, which are produced by the APIs defined in this specification.\nThey expose the same interface as native JavaScript errors like TypeError and RangeError.\n\nNote: It is not currently possible to define this behavior using Web IDL.","crossrefs":["namespace object","create a namespace object","list/iterate","NativeError Object Structure","!","WebAssembly","CompileError","LinkError","RuntimeError","TypeError","RangeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#error-objects"},{"id":"builtins","anchors":["builtins"],"title":"Builtins","level":2,"path":"js-api","prose":"The JS-API defines sets of builtin functions which can be imported through WebAssemblyCompileOptions|options when compiling a module. WebAssembly builtin functions mirror existing JavaScript builtins, but adapt them to be useable directly as WebAssembly functions with minimal overhead.\n\nAll builtin functions are grouped into sets. Every builtin set has a name that is used in WebAssemblyCompileOptions, and a qualified name with a wasm: prefix that is used during import lookup.\n\nTo get the builtins for a builtin set with builtinSetName, perform the following steps:\n\n1. Return a list of (name, funcType, steps) for the set with name builtinSetName defined within this section.\n\nTo find a builtin with import and enabled builtins builtinSetNames, perform the following steps:\n\n1. Assert: validate builtin set names builtinSetNames is true.\n1. Let importModuleName be import[0].\n1. Let importName be import[1].\n1. For each builtinSetName of builtinSetNames,\n 1. If builtinSetName does not refer to a builtin set, then iteration/continue.\n 1. Let builtinSetQualifiedName be builtinSetName prefixed with \"wasm:\".\n 1. If importModuleName equals builtinSetQualifiedName,\n 1. Let builtins be the result of get the builtins for a builtin set builtinSetName.\n 1. For each builtin of builtins,\n 1. Let builtinName be builtin[0].\n 1. If importName equals builtinName, return (builtinSetName, builtin).\n1. Return null.\n\nTo validate builtin set names with builtinSetNames, perform the following steps:\n\n1. If builtinSetNames contains any duplicates, return false.\n1. Return true.\n\nTo create a builtin function from type funcType and execution steps steps, perform the following steps:\n\n1. Let hostfunc be a host function which executes steps when called.\n1. Let store be the surrounding agent's associated store.\n1. Let (store, funcaddr) be func_alloc(store, funcType, hostfunc).\n1. Set the surrounding agent's associated store to store.\n1. Return funcaddr.\n\nTo instantiate a builtin set with name builtinSetName, perform the following steps:\n\n1. Let builtins be the result of get the builtins for a builtin set builtinSetName.\n1. Let exportsObject be ! [$OrdinaryObjectCreate$](null).\n1. For each (name, funcType, steps) of builtins,\n 1. Let funcaddr be the result of create a builtin function with funcType and steps.\n 1. Let func be the result of creating a new Exported Function from funcaddr.\n 1. Let value be func.\n 1. Let status be ! [$CreateDataProperty$](exportsObject, name, value).\n 1. Assert: status is true.\n1. Return exportsObject.\n\nTo validate an import for builtins with import, enabled builtins builtinSetNames, perform the following steps:\n\n1. Assert: validate builtin set names builtinSetNames is true.\n1. Let maybeBuiltin be the result of finding a builtin for import and builtinSetNames.\n1. If maybeBuiltin is null, return true.\n1. Let importExternType be import[2].\n1. Let builtinFuncType be maybeBuiltin[1][1].\n1. Let builtinExternType be func builtinFuncType.\n1. Return match_externtype(builtinExternType, importExternType).","crossrefs":["read the imports","validate builtin set names","list/iterate","iteration/continue","get the builtins for a builtin set","host function","surrounding agent","associated store","func_alloc","!","create a builtin function","a new Exported Function","find a builtin","match_externtype","WebAssemblyCompileOptions|options","WebAssemblyCompileOptions"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#builtins"},{"id":"builtins-js-string","anchors":["builtins-js-string"],"title":"String Builtins","level":3,"path":"js-api","prose":"String builtins adapt the interface of the String builtin object. The builtin-set/name for this set is js-string, and the builtin-set/qualified name is wasm:js-string.\n\nNote: The algorithms in this section refer to JS builtins defined on String. These refer to the actual builtin and do not perform a dynamic lookup on the String object.","crossrefs":["String","builtin-set/name","builtin-set/qualified name"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#builtins-js-string"},{"id":"builtins-js-string-abstract-ops","anchors":["builtins-js-string-abstract-ops"],"title":"Abstract operations","level":4,"path":"js-api","prose":"The UnwrapString(v) abstract operation, when invoked, performs the following steps:\n\n1. If v is not a String,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Return v\n\nThe FromCharCode(v) abstract operation, when invoked, performs the following steps:\n\n1. Assert: v is of type i32.\n1. Return ! [$Call$](String.fromCharCode, undefined, « ToJSValue(v) »).\n\nThe CharCodeAt(string, index) abstract operation, when invoked, performs the following steps:\n\n1. Assert: index is of type i32.\n1. Return ! [$Call$](String.prototype.charCodeAt, string, « ToJSValue(index) »).","crossrefs":["is not a String","trap","i32","!","String.fromCharCode","ToJSValue","String.prototype.charCodeAt","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#builtins-js-string-abstract-ops"},{"id":"js-string-cast","anchors":["js-string-cast"],"title":"cast","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref) (result (ref extern))))).0.\n\nWhen this builtin is invoked with parameter v, the following steps must be run:\n\n1. Return ? [$UnwrapString$](v)","crossrefs":["?"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-cast"},{"id":"js-string-test","anchors":["js-string-test"],"title":"test","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref) (result i32)))).0.\n\nWhen this builtin is invoked with parameter v, the following steps must be run:\n\n1. If v is not a String,\n 1. Return 0.\n1. Return 1.","crossrefs":["is not a String"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-test"},{"id":"js-string-fromCharCodeArray","anchors":["js-string-fromCharCodeArray"],"title":"fromCharCodeArray","level":4,"path":"js-api","prose":"Let arrayType be (rec (type (array (mut i16)))).0.\n\nThe funcType of this builtin is (rec (type (func (param (ref null arrayType) i32 i32) (result (ref extern))))).0.\n\nWhen this builtin is invoked with parameters array, start, and end, the following steps must be run:\n\n1. If array is null,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Let length be the number of elements in array.\n1. If start > end or end > length,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Let result be the empty string.\n1. Let i be start.\n1. While i","crossrefs":["trap","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-fromCharCodeArray"},{"id":"js-string-intoCharCodeArray","anchors":["js-string-intoCharCodeArray"],"title":"intoCharCodeArray","level":4,"path":"js-api","prose":"Let arrayType be (rec (type (array (mut i16)))).0.\n\nThe funcType of this builtin is (rec (type (func (param externref (ref null arrayType) i32) (result i32)))).0.\n\nWhen this builtin is invoked with parameters string, array, and start, the following steps must be run:\n\n1. If array is null,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Let string be ? [$UnwrapString$](string).\n1. Let stringLength be the string/length of string.\n1. Let arrayLength be the number of elements in array.\n1. If start + stringLength > arrayLength,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Let i be 0.\n1. While i","crossrefs":["trap","?","string/length","ToWebAssemblyValue","i32","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-intoCharCodeArray"},{"id":"js-string-fromCharCode","anchors":["js-string-fromCharCode"],"title":"fromCharCode","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param i32) (result (ref extern))))).0.\n\nWhen this builtin is invoked with parameter v, the following steps must be run:\n\n1. Return [$FromCharCode$](v).","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-fromCharCode"},{"id":"js-string-fromCodePoint","anchors":["js-string-fromCodePoint"],"title":"fromCodePoint","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param i32) (result externref)))).0.\n\nWhen this builtin is invoked with parameter v, the following steps must be run:\n\n1. If v > 0x10ffff,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Return ! [$Call$](String.fromCodePoint, undefined, « ToJSValue(v) »).","crossrefs":["trap","!","String.fromCodePoint","ToJSValue","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-fromCodePoint"},{"id":"js-string-charCodeAt","anchors":["js-string-charCodeAt"],"title":"charCodeAt","level":4,"path":"js-api","prose":"The type of this function is (rec (type (func (param externref i32) (result i32)))).0.\n\nWhen this builtin is invoked with parameters string and index, the following steps must be run:\n\n1. Let string be ? [$UnwrapString$](string).\n1. Let length be the string/length of string.\n1. If index >= length,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Return [$CharCodeAt$](string, index).","crossrefs":["?","string/length","trap","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-charCodeAt"},{"id":"js-string-codePointAt","anchors":["js-string-codePointAt"],"title":"codePointAt","level":4,"path":"js-api","prose":"The type of this function is (rec (type (func (param externref i32) (result i32)))).0.\n\nWhen this builtin is invoked with parameters string and index, the following steps must be run:\n\n1. Let string be ? [$UnwrapString$](string).\n1. Let length be the string/length of string.\n1. If index >= length,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. Return ! [$Call$](String.prototype.codePointAt, string, « ToJSValue(index) »).","crossrefs":["?","string/length","trap","!","String.prototype.codePointAt","ToJSValue","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-codePointAt"},{"id":"js-string-length","anchors":["js-string-length"],"title":"length","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref) (result i32)))).0.\n\nWhen this builtin is invoked with parameter v, the following steps must be run:\n\n1. Let string be ? [$UnwrapString$](v).\n1. Return the string/length of string.","crossrefs":["?","string/length"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-length"},{"id":"js-string-concat","anchors":["js-string-concat"],"title":"concat","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref externref) (result (ref extern))))).0.\n\nWhen this builtin is invoked with parameters first and second, the following steps must be run:\n\n1. Let first be ? [$UnwrapString$](first).\n1. Let second be ? [$UnwrapString$](second).\n1. Return ! [$Call$](String.prototype.concat, first, « second »).","crossrefs":["?","!","String.prototype.concat"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-concat"},{"id":"js-string-substring","anchors":["js-string-substring"],"title":"substring","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref i32 i32) (result (ref extern))))).0.\n\nWhen this builtin is invoked with parameters string, start, and end, the following steps must be run:\n\n1. Let string be ? [$UnwrapString$](string).\n1. Let length be the string/length of string.\n1. If start > end or start > length,\n 1. Return the empty string.\n1. Return ! [$Call$](String.prototype.substring, string, « ToJSValue(start), ToJSValue(end) »).","crossrefs":["?","string/length","!","String.prototype.substring","ToJSValue"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-substring"},{"id":"js-string-equals","anchors":["js-string-equals"],"title":"equals","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref externref) (result i32)))).0.\n\nNote: Explicitly allow null strings to be compared for equality as that is meaningful.\n\nWhen this builtin is invoked with parameters first and second, the following steps must be run:\n\n1. If first is not null and first is not a String,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. If second is not null and second is not a String,\n 1. Throw a RuntimeError exception as if a trap was executed.\n1. If ! IsStrictlyEqual(first, second) is true,\n 1. Return 1.\n1. Return 0.","crossrefs":["is not a String","trap","!","IsStrictlyEqual","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-equals"},{"id":"js-string-compare","anchors":["js-string-compare"],"title":"compare","level":4,"path":"js-api","prose":"The funcType of this builtin is (rec (type (func (param externref externref) (result i32)))).0.\n\nWhen this builtin is invoked with parameters first and second, the following steps must be run:\n\n1. Let first be ? [$UnwrapString$](first).\n1. Let second be ? [$UnwrapString$](second).\n1. If ! IsStrictlyEqual(first, second) is true,\n 1. Return 0.\n1. If ! IsLessThan(first, second, true) is true,\n 1. Return -1.\n1. Return 1.","crossrefs":["?","!","IsStrictlyEqual","IsLessThan"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#js-string-compare"},{"id":"errors","anchors":["errors"],"title":"Error Condition Mappings to JavaScript","level":2,"path":"js-api","prose":"Running WebAssembly programs encounter certain events which halt execution of the WebAssembly code.\nWebAssembly code (currently)\nhas no way to catch these conditions and thus an exception will necessarily\npropagate to the enclosing non-WebAssembly caller (whether it is a browser,\nJavaScript or another runtime system) where it is handled like a normal JavaScript exception.\n\nIf WebAssembly calls JavaScript via import and the JavaScript throws an\nexception, the exception is propagated through the WebAssembly activation to the\nenclosing caller.\n\nBecause JavaScript exceptions can be handled, and JavaScript can continue to\ncall WebAssembly exports after a trap has been handled, traps do not, in\ngeneral, prevent future execution.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#errors"},{"id":"stack-overflow","anchors":["stack-overflow"],"title":"Stack Overflow","level":3,"path":"js-api","prose":"Whenever a stack overflow occurs in\nWebAssembly code, the same class of exception is thrown as for a stack overflow in\nJavaScript. The particular exception here is implementation-defined in both cases.\n\nNote: ECMAScript doesn't specify any sort of behavior on stack overflow; implementations have been observed to throw RangeError, InternalError or Error. Any is valid here.","crossrefs":["RangeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#stack-overflow"},{"id":"out-of-memory","anchors":["out-of-memory"],"title":"Out of Memory","level":3,"path":"js-api","prose":"Whenever validation, compilation or instantiation run out of memory, the\nsame class of exception is thrown as for out of memory conditions in JavaScript.\nThe particular exception here is implementation-defined in both cases.\n\nNote: ECMAScript doesn't specify any sort of behavior on out-of-memory conditions; implementations have been observed to throw OOMError and to crash. Either is valid here.\n\n A failed allocation of a large table or memory may either result in\n - a RangeError, as specified in the Memory Memory and Table Table operations\n - returning -1 as the memory.grow instruction\n - UA-specific OOM behavior as described in this section.\n In a future revision, we may reconsider more reliable and recoverable errors for allocations of large amounts of memory.\n\n See [Issue 879](https://github.com/WebAssembly/spec/issues/879) for further discussion.","crossrefs":["memory.grow","RangeError","Memory","Table"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#out-of-memory"},{"id":"limits","anchors":["limits"],"title":"Implementation-defined Limits","level":2,"path":"js-api","prose":"The WebAssembly core specification allows an implementation to define limits on the syntactic structure of the module.\nWhile each embedding of WebAssembly may choose to define its own limits, for predictability the standard WebAssembly JavaScript Interface described in this document defines the following exact limits.\nAn implementation must reject a module that exceeds one of the following limits with a CompileError.\nIn practice, an implementation may run out of resources for valid modules below these limits.\n\nThe maximum size of a module is 1,073,741,824 bytes (1 GiB).\nThe maximum number of types defined in the types section is 1,000,000.\nThe maximum number of recursion groups defined in the types sections is 1,000,000.\nThe maximum number of types defined in a recursion group is 1,000,000.\nThe maximum depth of a defined subtype hierarchy is 63 (where a type defined with no supertype has depth 0).\nThe maximum number of functions defined in a module is 1,000,000.\nThe maximum number of imports declared in a module is 1,000,000.\nThe maximum number of exports declared in a module is 1,000,000.\nThe maximum number of globals defined in a module is 1,000,000.\nThe maximum number of tags defined in a module is 1,000,000.\nThe maximum number of data segments defined in a module is 100,000.\n\nThe maximum number of tables, including declared or imported tables, is 100,000.\nThe maximum size of a table is 10,000,000.\nThe maximum number of table entries in any table initialization is 10,000,000.\n\nThe maximum number of memories, including defined and imported memories, is 100.\nThe maximum min or max field of a 32-bit memory is 65,536 pages (4 GiB).\nThe maximum min or max field of a 64-bit memory is 2^37-1 pages (2^53 - 2^16 bytes).\n\nThe maximum number of parameters to any function or block is 1,000.\nThe maximum number of return values for any function or block is 1,000.\nThe maximum size of a function body, including locals declarations, is 7,654,321 bytes.\nThe maximum number of locals declared in a function, including implicitly declared as parameters, is 50,000.\nThe maximum number of fields in a struct is 10,000.\nThe maximum number of operands to array.new_fixed is 10,000.\n\nAn implementation must throw a RuntimeError if one of the following limits is exceeded during runtime:\nIn practice, an implementation may run out of resources for valid modules below these limits.\n\nThe maximum size of a table is 10,000,000.\nThe maximum size of a 32-bit memory is 65,536 pages (4 GiB).\nThe maximum size of a 64-bit memory is 262,144 pages (16 GiB).","crossrefs":["CompileError","RuntimeError"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#limits"},{"id":"security-considerations","anchors":["security-considerations"],"title":"Security and Privacy Considerations","level":2,"path":"js-api","prose":"This section is non-normative.\n\nThis document defines a host environment for WebAssembly. It enables a WebAssembly instance to import JavaScript objects and functions from an import object, but otherwise provides no access to the embedding environment. Thus a WebAssembly instance is bound to the same constraints as JavaScript.","crossrefs":["import","read the imports"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#security-considerations"},{"id":"change-history","anchors":["change-history"],"title":"Change History","level":2,"path":"js-api","prose":"This section is non-normative.\n\nSince the original release 1.0 of the WebAssembly specification, a number of proposals for extensions have been integrated.\nThe following sections provide an overview of what has changed.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#change-history"},{"id":"release-20","anchors":["release-20"],"title":"Release 2.0","level":3,"path":"js-api","prose":"","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#release-20"},{"id":"changes-multivalue","anchors":["changes-multivalue"],"title":"Multiple Values","level":4,"path":"js-api","prose":"Multiple values can be returned to and from JavaScript functions as an Array object.","crossrefs":["Array"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#changes-multivalue"},{"id":"changes-bigint","anchors":["changes-bigint"],"title":"BigInt Integration","level":4,"path":"js-api","prose":"WebAssembly i64 values can be passed to and from JavaScript (via imported or exported globals, table get or set operations, function return values or arguments) as BigInt objects.","crossrefs":["i64","BigInt"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#changes-bigint"},{"id":"changes-reftypes","anchors":["changes-reftypes"],"title":"Reference Types","level":4,"path":"js-api","prose":"JavaScript values can be passed to and from WebAssembly (via imported or exported globals, table set or get operations, and function arguments or return values) as externref values.","crossrefs":["externref"],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#changes-reftypes"},{"id":"changes-multitable","anchors":["changes-multitable"],"title":"Multiple Tables","level":4,"path":"js-api","prose":"Multiple tables can be exported and imported to and from JavaScript.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#changes-multitable"},{"id":"release-30","anchors":["release-30"],"title":"Release 3.0","level":3,"path":"js-api","prose":"","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#release-30"},{"id":"changes-multimemory","anchors":["changes-multimemory"],"title":"Multiple Memories","level":4,"path":"js-api","prose":"Multiple memories can be exported and imported to and from JavaScript.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#changes-multimemory"},{"id":"changes-js-sb","anchors":["changes-js-sb"],"title":"JS String Builtins","level":4,"path":"js-api","prose":"Added a builtins option when compiling a module, and a collection of builtin functions for manipulating JS Strings.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/js-api/#changes-js-sb"}]}
@@ -0,0 +1 @@
1
+ {"pin":{"key":"spec/main","sha":"7a366e1531e6aab089c9a07ae5608909e187bb13","spec":"web-api","version":"main"},"sections":[{"id":"intro","anchors":["intro"],"title":"Introduction","level":2,"path":"web-api","prose":"This document builds off of the WebAssembly specification WEBASSEMBLY and the WebAssembly JavaScript embedding WASMJS.\nIt describes the integration of WebAssembly into the broader Web platform, for example with\nadditional APIs that are implemented by Web user agents but are outside the scope of JavaScript ECMASCRIPT itself.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#intro"},{"id":"streaming-modules","anchors":["streaming-modules"],"title":"Streaming Module Compilation and Instantiation","level":2,"path":"web-api","prose":"The compileStreaming(source, options) method, when invoked, returns the result of compiling a potential WebAssembly response with source using options.\n\nThe instantiateStreaming(source, importObject, options) method, when invoked, performs the following steps:\n\n 1. Let promiseOfModule be the result of compiling a potential WebAssembly response with source using options.\n 1. Return the result of instantiating the promise of a module promiseOfModule with imports importObject.\n\nTo compile a potential WebAssembly response with a promise of a Response source and WebAssemblyCompileOptions options, perform the following steps:\n\nNote: This algorithm accepts a Response object, or a\n promise for one, and compiles and instantiates the resulting bytes of the response. This compilation\n can be performed in the background and in a streaming manner. If the Response is not\n CORS-same-origin, does not represent an ok status, or does not match the\n ` application/wasm MIME type, the returned promise will be rejected with a TypeError; if\n compilation or instantiation fails, the returned promise will be rejected with a\n CompileError or other relevant error type, depending on the cause of failure.\n\n 1. Let returnValue be a new promise.\n 1. React to source:\n If source was fulfilled with value unwrappedSource:\n 1. Let response be unwrappedSource's Response/response.\n 1. Let mimeType be the result of header list/getting Content-Type from response's response/header list.\n 1. If mimeType is null, reject returnValue with a TypeError and abort these substeps.\n 1. Remove all HTTP tab or space byte from the start and end of mimeType.\n 1. If mimeType is not a byte-case-insensitive match for application/wasm , reject returnValue with a TypeError and abort these substeps.\n\n Note: extra parameters are not allowed, including the empty application/wasm; `.\n\n 1. If response is not CORS-same-origin, reject returnValue with a TypeError and abort these substeps.\n 1. If response's response/status is not an ok status, reject returnValue with a TypeError and abort these substeps.\n 1. Consume response's body as an ArrayBuffer, and let bodyPromise be the result.\n\n Note: Although it is specified here that the response is consumed entirely before compilation proceeds, that is purely for ease of specification; implementations are likely to instead perform processing in a streaming fashion. The difference is unobservable, and thus the simpler model is specified. \n\n 1. React to bodyPromise:\n If bodyPromise was fulfilled with value bodyArrayBuffer:\n 1. Let stableBytes be a copy of the bytes held by the buffer bodyArrayBuffer.\n 1. Asynchronously compile the WebAssembly module stableBytes using the networking task source and options and resolve returnValue with the result.\n If bodyPromise was rejected with reason reason:\n 1. Reject returnValue with reason.\n If source was rejected with reason reason:\n 1. Reject returnValue with reason.\n 1. Return returnValue.","crossrefs":["compile a potential WebAssembly response","instantiate a promise of a module","CORS-same-origin","ok status","a new promise","React","Response/response","header list/getting","response/header list","HTTP tab or space byte","byte-case-insensitive","reject","response/status","Consume body","get a copy of the buffer source","Asynchronously compile a WebAssembly module","networking task source","resolve","Reject","Response","WebAssemblyCompileOptions","TypeError","CompileError","ArrayBuffer"],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#streaming-modules"},{"id":"serialization","anchors":["serialization"],"title":"Serialization","level":2,"path":"web-api","prose":"Web user agents must augment the Module interface with the [Serializable] extended attribute.\n\nThe serialization steps, given value, serialized, and forStorage, are:\n\n 1. If forStorage is true, throw a \"DataCloneError\" DOMException.\n\n 1. Set serialized.\\[[Bytes]] to the sub-serialization of value.\\[[Bytes]].\n\n 1. Set serialized.\\[[AgentCluster]] to the current Realm's corresponding agent cluster.\n\nThe deserialization steps, given serialized, value, and targetRealm are:\n\n 1. Let bytes be the sub-deserialization of serialized.\\[[Bytes]].\n\n 1. Set value.\\[[Bytes]] to bytes.\n\n 1. If targetRealm's corresponding agent cluster is not serialized.\\[[AgentCluster]], then throw a \"DataCloneError\" DOMException.\n\n 1. Compile a WebAssembly module from bytes and set value.\\[[Module]] to the result.\n\nEngines should attempt to share/reuse internal compiled code when performing\na structured serialization, although in corner cases like CPU upgrade or browser\nupdate, this might not be possible and full recompilation may be necessary.\n\nNote: The semantics of a structured serialization is as-if the binary source, from which the\nModule was compiled, is serialized, then deserialized, and recompiled into the target realm.\nGiven the above engine optimizations, structured serialization provides developers\nexplicit control over both compiled-code caching and cross-window/worker code\nsharing.","crossrefs":["serialization steps","sub-serialization","current Realm","agent cluster","deserialization steps","sub-deserialization","Compile a WebAssembly module","Module","DOMException"],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#serialization"},{"id":"conventions","anchors":["conventions"],"title":"Developer-Facing Display Conventions","level":2,"path":"web-api","prose":"This section is non-normative.\n\nBrowsers, JavaScript engines, and offline tools have common ways of referring to\nJavaScript artifacts and language constructs. For example, locations in\nJavaScript source code are printed in stack traces or error messages, and are\nrepresented naturally as decimal-format lines and columns in text files. Names\nof functions and variables are taken directly from the sources. Therefore (for\nexample) even though the exact format of implementation-dependent stack trace\nstrings does not always match, the locations are easily understandable and the\nsame across browsers.\n\nTo achieve the same goal of a common representation for WebAssembly constructs, the\nfollowing conventions are adopted.\n\nA WebAssembly location is a reference to a particular instruction in the binary, and may be\ndisplayed by a browser or engine in similar contexts as JavaScript source locations.\nIt has the following format:\n\n${url}:wasm-function[${funcIndex}]:${pcOffset}\n\nWhere\n ${url} is the URL associated with the module, if applicable (see notes).\n ${funcIndex} is the function index relative to the module.\n ${pcOffset} is the offset in the module binary of the first byte of the instruction, printed in hexadecimal with lower-case digits, with a leading 0x prefix.\n\nNotes:\n The URL field may be interpreted differently depending on the\n context. When the response-based\n instantiation API is used in a\n browser, the associated URL should be used; or when the\n ArrayBuffer-based instantiation\n API is used, the browser should represent\n the location of the API call. This kind of instantiation is analogous to\n executing JavaScript using eval; therefore if the browser has an existing\n method to represent the location of the eval call it can use a similar\n one for WebAssembly.instantiate. For example if the browser uses\n foo.js line 10 > eval or eval at bar (foo.js:10:3) for eval, it could\n use foo.js line 10 > WebAssembly.instantiate or\n WebAssembly.instantiate at bar (foo.js:10:3), respectively.\n Offline tools may use a filename instead.\n Using hexadecimal for module offsets matches common conventions in native tools\n such as objdump (where addresses are printed in hex) and makes them visually\n distinct from JavaScript line numbers. Other numbers are represented in decimal.\n\nWhile the \"name\" property of an Exported Function instance\nis specified by the [[WASMJS|JS API]], synthesized function names are also\ndisplayed in other contexts like call stacks in debuggers and string representations\nof stack traces.\nIf a WebAssembly module contains a name section,\nthese names should be used to synthesize a function name as follows:\n If a function name subsection is present, the displayed name should be ${module_name}.${function_name} or ${function_name}, depending on whether the module name is present.\n Otherwise, the output can be context-dependent:\n If the function name is shown alongside its location in a stack trace, then just the module name (if present) or an empty string can be used (because the function index is already in the location).\n * Otherwise, ${module_name}.wasm-function[${funcIndex}] or wasm-function[${funcIndex}] should be used to convey the function index.\n\nNote that this document does not specify the full format of strings such as\nstack frame representations; this allows engines to continue using their\nexisting formats for JavaScript (which existing code may already be depending\non) while still printing WebAssembly frames in a format consistent with\nJavaScript.","crossrefs":["function index","instantiate","Exported Function","name section","ArrayBuffer"],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#conventions"},{"id":"mediaType","anchors":["mediaType"],"title":"Media-type Registration","level":2,"path":"web-api","prose":"The media type application/wasm has been registered with the IANA media type database IANA-MEDIA-TYPES,\nwith the following registration template:\n\napplication/wasm\n\nType Name:\n application\nSubtype Name:\n wasm\nRequired Parameters:\n None\nOptional Parameters:\n None\nEncoding Considerations:\n binary\nSecurity Considerations:\n \n WebAssembly is a standard, a safe, portable, low-level code format. The\n security considerations associated with executing WebAssembly code are\n described in https://www.w3.org/TR/wasm-core/#security-considerations.\n The WebAssembly format includes no integrity or privacy protection. If\n such protection is needed it must be provided externally, e.g., through\n the use of HTTPS.\n \nInteroperability Considerations:\n See WebAssembly Core Conformance\n https://www.w3.org/TR/wasm-core/#conformance\nPublished specification:\n https://www.w3.org/TR/wasm-core-1/\n https://www.w3.org/TR/wasm-js-api-1/\n https://www.w3.org/TR/wasm-web-api-1/\nApplication Usage:\n The application/wasm media type is intended for use as the type used to\n describe WebAssembly files when sent over HTTP to be executed by browsers,\n which is a common scenario. Additionally, the type is used by several\n WebAssembly runtimes that take advantage of the safety and portability\n while targeting efficient execution and compact representation.\nFragment Identifier Considerations:\n None\nRestrictions on usage:\n None\nProvisional Registrations:\n N/A\nAdditional information:\n\n Deprecated alias names for this type:\n None\n Magic number(s):\n 0x00 0x61 0x73 0x6D\n File extension(s):\n .wasm\n Macintosh file type code(s):\n None\n Object Identifier(s) or OID(s):\n None\n\nIntended usage:\n Common\nOther Information & Comments:\n Common\nContact Person:\n\n Contact Name:\n Eric Prud'hommeaux\n Contact Email Address:\n eric@w3.org\n Author/Change Controller:\n W3C","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#mediaType"},{"id":"security-considerations","anchors":["security-considerations"],"title":"Security and Privacy Considerations","level":2,"path":"web-api","prose":"This section is non-normative.\nWebAssembly provides no access to the surrounding environment other than via the JavaScript API described in the [[WASMJS|JS API]] specification.\nTherefore, WebAssembly cannot collect or expose any information (personal, sensitive or otherwise) to Web sites or other parties beyond what can be collected, exposed or processed with JavaScript.\nWebAssembly memory has the same lifetime as the objects in the surrounding JavaScript environment and is not persisted or serialized (other than by copying it out to JavaScript and using existing serialization APIs).\nNo access is provided to the underlying platform or hardware, or to other devices, or to the user agent’s native UI.\n\nWebAssembly is an additional program execution mechanism, and can be executed wherever JavaScript can be executed.\nTherefore the threat model is essentially the same as for JavaScript code, and has similar considerations for delivery (e.g. WebAssembly code should be protected in transit from active and passive network attackers)\nand policy (e.g. some loading mechanisms or execution are restricted via mechanisms such as the same-origin policy or Content Security Policy).","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#security-considerations"},{"id":"change-history","anchors":["change-history"],"title":"Change History","level":2,"path":"web-api","prose":"This section is non-normative.\n\nSince the original release 1.0 of the WebAssembly specification, a number of proposals for extensions have been integrated.\nThe following sections provide an overview of what has changed.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#change-history"},{"id":"release-20","anchors":["release-20"],"title":"Release 2.0","level":3,"path":"web-api","prose":"","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#release-20"},{"id":"changes-registration","anchors":["changes-registration"],"title":"Media-type Registraton Completed","level":4,"path":"web-api","prose":"The registration for the application/wasm media type has been successfully completed.","crossrefs":[],"formal_refs":[],"url":"https://webassembly.github.io/spec/web-api/#changes-registration"}]}