Skip to content

Commit 9c69d19

Browse files
authored
[js-api] Fix up missing preconditions on allocations (#1793)
1 parent b5c848b commit 9c69d19

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

document/js-api/index.bs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
6161
url: valid/modules.html#valid-module
6262
text: valid
6363
text: WebAssembly module validation
64+
text: valid limits; url: valid/types.html#valid-limits
65+
text: valid memtype; url: valid/types.html#valid-memtype
66+
text: valid tabletype; url: valid/types.html#valid-tabletype
6467
text: module grammar; url: binary/modules.html#binary-module
6568
text: custom section; url: binary/modules.html#custom-section
6669
text: customsec; url: binary/modules.html#binary-customsec
@@ -108,9 +111,11 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
108111
text: global_write; url: appendix/embedding.html#embed-global-write
109112
text: error; url: appendix/embedding.html#embed-error
110113
text: store; url: exec/runtime.html#syntax-store
114+
text: limits; url: syntax/types.html#syntax-limits
111115
text: table type; url: syntax/types.html#syntax-tabletype
112116
text: table address; url: exec/runtime.html#syntax-tableaddr
113117
text: function address; url: exec/runtime.html#syntax-funcaddr
118+
text: memory type; url: syntax/types.html#syntax-memtype
114119
text: memory address; url: exec/runtime.html#syntax-memaddr
115120
text: global address; url: exec/runtime.html#syntax-globaladdr
116121
text: extern address; url: exec/runtime.html#syntax-externaddr
@@ -675,8 +680,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
675680
The <dfn constructor for="Memory">Memory(|descriptor|)</dfn> constructor, when invoked, performs the following steps:
676681
1. Let |initial| be |descriptor|["initial"].
677682
1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
678-
1. If |maximum| is not empty and |maximum| &lt; |initial|, throw a {{RangeError}} exception.
679-
1. Let |memtype| be { min |initial|, max |maximum| }.
683+
1. Let |memtype| be the [=memory type=] { <b>[=limits|min=]</b> |initial|, <b>[=limits|max=]</b> |maximum| }.
684+
1. If |memtype| is not [=valid memtype|valid=], throw a {{RangeError}} exception.
680685
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
681686
1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception.
682687
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -836,14 +841,16 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
836841
1. [=Throw=] a {{TypeError}} exception.
837842
1. Let |initial| be |descriptor|["initial"].
838843
1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
839-
1. If |maximum| is not empty and |maximum| &lt; |initial|, throw a {{RangeError}} exception.
844+
1. Let |type| be the [=table type=] { <b>[=limits|min=]</b> |initial|, <b>[=limits|max=]</b> |maximum| } |elementType|.
845+
1. If |type| is not [=valid tabletype|valid=], throw a {{RangeError}} exception.
846+
847+
Note: Because tables may have up to 2<sup>32</sup> - 1 elements in validation, the checks for [=limits|min=] ≤ 2<sup>32</sup> - 1 and [=limits|max=] ≤ 2<sup>32</sup> - 1 in [=valid limits|limits validation=] cannot fail.
840848
1. If |value| is missing,
841849
1. Let |ref| be [=DefaultValue=](|elementType|).
842850
1. Otherwise,
843851
1. Let |ref| be [=?=] [=ToWebAssemblyValue=](|value|, |elementType|).
844-
1. Let |type| be the [=table type=] {[=table type|min=] |initial|, [=table type|max=] |maximum|} |elementType|.
845852
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
846-
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
853+
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). If allocation fails, throw a {{RangeError}} exception.
847854
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
848855
1. [=initialize a table object|Initialize=] **this** from |tableaddr|.
849856
</div>

0 commit comments

Comments
 (0)