Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spec] Normative: Support [Serializable] for WebAssembly.Module #711

Merged
merged 7 commits into from
Jun 27, 2018
46 changes: 46 additions & 0 deletions document/web-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Prepare For TR: true
"title": "WebAssembly JS Integration Specification",
"publisher": "W3C WebAssembly Community Group",
"status": "Draft"
},
"SECURECONTEXTS": {
"href": "https://w3c.github.io/webappsec-secure-contexts/",
"title": "Secure Contexts",
"publisher": "WebAppSec WG",
"status": "Candidate Recommendation"
}
}
</pre>
Expand All @@ -42,6 +48,9 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
text: TypeError; url: sec-native-error-types-used-in-this-standard-typeerror
type: interface
text: ArrayBuffer; url: sec-arraybuffer-objects
type: dfn
text: agent cluster; url: sec-agent-clusters
text: current Realm; url: current-realm
urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn
text: function index; url: syntax/modules.html#syntax-funcidx
text: name section; url: appendix/custom.html?highlight=name%20section#binary-namesec
Expand All @@ -61,6 +70,7 @@ urlPrefix: https://webassembly.github.io/spec/js-api/; spec: WASMJS
text: Exported Function; url: #exported-function
url:https://html.spec.whatwg.org/#cors-same-origin;text:CORS-same-origin;type:dfn;spec:HTML
url:https://fetch.spec.whatwg.org/#concept-body-consume-body;text:consume body;type:dfn;spec:FETCH
url:https://w3c.github.io/webappsec-secure-contexts/#environment-settings-object-contextually-secure; text:contextually secure; type: dfn; spec: SECURECONTEXTS
</pre>

<pre class='link-defaults'>
Expand Down Expand Up @@ -125,6 +135,42 @@ Note: This algorithm accepts a {{Response}} object, or a
1. Return |returnValue|.
</div>

<h2 id="serialization">Serialization</h2>

Web user agents must augment the {{Module}} interface with the <code>[<a extended-attribute>Serializable</a>]</code> extended attribute.

The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are:

1. If |forStorage| is true, throw a
"<a exception>DataCloneError</a>" {{DOMException}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "{{DataCloneError}}" is more conventional.


1. Set |serialized|.\[[Bytes]] to the [=sub-serialization=] of |value|.\[[Bytes]].

1. Set |serialized|.\[[AgentCluster]] to the
[=current Realm=]'s corresponding [=agent cluster=].

The [=deserialization steps=], given |serialized| and |value|, are:

1. Let |bytes| be the [=sub-deserialization=] of |serialized|.\[[Bytes]].

1. Set |value|.\[[Bytes]] to |bytes|.

1. If |targetRealm|'s corresponding [=agent cluster=] is not
|serialized|.\[[AgentCluster]], then throw a
"<a exception>DataCloneError</a>" {{DOMException}}.

1. [=Compile a WebAssembly module=] from |bytes| and set |value|.\[[Module]] to the result.

Engines should attempt to share/reuse internal compiled code when performing
a structured serialization, although in corner cases like CPU upgrade or browser
update, this might not be possible and full recompilation may be necessary.

Note: The semantics of a structured serialization is as-if the binary source, from which the
{{Module}} was compiled, is serialized, then deserialized, and recompiled into the target realm.
Given the above engine optimizations, structured serialization provides developers
explicit control over both compiled-code caching and cross-window/worker code
sharing.

<h2 id="conventions">Developer-Facing Display Conventions</h2>

<em>This section is non-normative.</em>
Expand Down