Skip to content

Commit 6aeafe6

Browse files
committed
Editorial: Use USVString rather than DOMString to explain encoding
WebAssembly names are in the AST as strings of Unicode code points, rather than UTF-8-encoded byte sequences. This patch uses WebIDL's USVString type to encode this--the type is sequences of code points in IDL-land, which is then converted to an ECMAScript value by encoding in UTF-16. The place where this is inapplicable is custom sections, which don't have a decoded name, but whose name is still validated as UTF-8. Thanks to @lukewagner for pointing this out in WebAssembly#591 (comment)
1 parent 5afc0fd commit 6aeafe6

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

document/js-api/index.bs

+8-13
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
365365
1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
366366
1. Assert: |ret| is empty.
367367
1. Let |exportsObject| be ! [=ObjectCreate=](null).
368-
1. For each pair (|nameBytes|, |externtype|) in [=module_exports=](|module|),
369-
1. Let |name| be |nameBytes| [=UTF-8 decode without BOM or fail|decoded as UTF-8=].
370-
1. Assert: |name| is not failure (|module| is [=valid=]).
368+
1. For each pair (|name|, |externtype|) in [=module_exports=](|module|),
371369
1. Let |externval| be [=get_export=](|instance|, |name|).
372370
1. If |externtype| is of the form [=𝖿𝗎𝗇𝖼=] |functype|,
373371
1. If |funcs| contains an entry |func| where 𝖿𝗎𝗇𝖼 |func|.\[[FunctionAddress]] is |externval|, let |value| be |func|
@@ -442,22 +440,22 @@ enum ImportExportKind {
442440
};
443441

444442
dictionary ModuleExportDescriptor {
445-
required DOMString name;
443+
required USVString name;
446444
required ImportExportKind kind;
447445
// Note: Other fields such as signature may be added in the future.
448446
};
449447

450448
dictionary ModuleImportDescriptor {
451-
required DOMString module;
452-
required DOMString name;
449+
required USVString module;
450+
required USVString name;
453451
required ImportExportKind kind;
454452
};
455453

456454
[LegacyNamespace=WebAssembly, Constructor(BufferSource bytes), Exposed=(Window,Worker,Worklet)]
457455
interface Module {
458456
static sequence&lt;ModuleExportDescriptor> exports(Module module);
459457
static sequence&lt;ModuleImportDescriptor> imports(Module module);
460-
static sequence&lt;ArrayBuffer> customSections(Module module, DOMString sectionName);
458+
static sequence&lt;ArrayBuffer> customSections(Module module, USVString sectionName);
461459
};
462460
</pre>
463461

@@ -473,8 +471,8 @@ interface Module {
473471
The <dfn method for="Module">exports(moduleObject)</dfn> method, when invoked, performs the following steps:
474472
1. Let |module| be |moduleObject|.\[[Module]].
475473
1. Let |exports| be an empty [=list=].
476-
1. For each (|nameBytes|, |type|) in [=module_exports=](|module|)
477-
1. Let |name| be |nameBytes| [=UTF-8 decode without BOM or fail|decoded as UTF-8=].
474+
1. For each (|name|, |type|) in [=module_exports=](|module|)
475+
1. Let |nameString| be String value consisting of the [=UTF16Encoding=] of each code point of |name|.
478476
1. Assert: |name| is not failure (|module| is [=valid=]).
479477
1. Let |kind| be the [=string value of the extern type=] |type|.
480478
1. Let |obj| be a new {{ModuleExportDescriptor}} dictionary with {{ModuleExportDescriptor/name}} |name| and {{ModuleExportDescriptor/kind}} |kind|.
@@ -486,10 +484,7 @@ interface Module {
486484
The <dfn method for="Module">imports(moduleObject)</dfn> method, when invoked, performs the following steps:
487485
1. Let |module| be |moduleObject|.\[[Module]].
488486
1. Let |imports| be an empty [=list=].
489-
1. For each (|moduleBytes|, |nameBytes|, |type|) in [=module_imports=](|module|),
490-
1. Let |moduleName| be |moduleBytes| [=UTF-8 decode without BOM or fail|decoded as UTF-8=].
491-
1. Let |name| be |nameBytes| [=UTF-8 decode without BOM or fail|decoded as UTF-8=].
492-
1. Assert: The previous operations are not failure, as |module| is [=valid=].
487+
1. For each (|moduleName|, |name|, |type|) in [=module_imports=](|module|),
493488
1. Let |kind| be the [=string value of the extern type=] |type|.
494489
1. Let |obj| be a new {{ModuleImportDescriptor}} dictionary with {{ModuleImportDescriptor/module}} |moduleName|, {{ModuleImportDescriptor/name}} |name| and {{ModuleImportDescriptor/kind}} |kind|.
495490
1. [=Append=] |obj| to the end of |imports|.

0 commit comments

Comments
 (0)