aboutsummaryrefslogtreecommitdiff
path: root/JS.md
diff options
context:
space:
mode:
authorrossberg-chromium <rossberg@chromium.org>2016-10-14 18:28:41 +0200
committerGitHub <noreply@github.com>2016-10-14 18:28:41 +0200
commitf7004430f876c60fa53e6dcd14d2c7537ed1198e (patch)
treecb9f8fb9d6925c615cffca25d777459754319a6b /JS.md
parent1dc44d30feab35d5a482e72c182aa45b7b517ed3 (diff)
downloadnanowasm-design-f7004430f876c60fa53e6dcd14d2c7537ed1198e.tar.gz
Throw `RangeError` for invalid sizes or indices (#821)
The `WebAssembly.RuntimeError` exception should be reserved for actual traps in WebAssembly code. API functions should otherwise use appropriate regular JS exceptions. In particular, this PR changes table/memory access and grow methods to throw a `RangeError` for out of bound sizes or indices. That is consistent with what their constructors do already.
Diffstat (limited to 'JS.md')
-rw-r--r--JS.md8
1 files changed, 6 insertions, 2 deletions
diff --git a/JS.md b/JS.md
index 232377a..71dbe6a 100644
--- a/JS.md
+++ b/JS.md
@@ -409,7 +409,7 @@ Let `d` be [`ToNonWrappingUint32`](#tononwrappinguint32)(`delta`).
Let `ret` be the result of performing a
[`grow_memory`](Semantics.md#resizing) operation given delta `d`.
-If `ret` is `-1`, a `WebAssembly.RuntimeError` is thrown.
+If `ret` is `-1`, a [`RangeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror) is thrown.
Perform [`DetachArrayBuffer`](http://tc39.github.io/ecma262/#sec-detacharraybuffer)(`M.[[BufferObject]]`).
@@ -490,7 +490,7 @@ Return `T.[[Values]].length`.
This method calls `Table.grow`, having performed
[`ToNonWrappingUint32`](#tononwrappinguint32) on the first argument.
-On failure, a `WebAssembly.RuntimeError` is thrown.
+On failure, a [`RangeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror) is thrown.
(Note: the ML spec currently doesn't support resizing tables; we assume here it
will be extended in the future to have a `grow` operation similar to
@@ -507,6 +507,8 @@ is thrown.
Let `i` be the result of [`ToNonWrappingUint32`](#tononwrappinguint32)(`index`).
+If `i` is greater or equal than the length of `T.[[Values]]`, a [`RangeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror) is thrown.
+
Return `T.[[Values]][i]`.
### `WebAssembly.Table.prototype.set`
@@ -524,6 +526,8 @@ or `null`, throw a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-erro
Let `i` be the result of [`ToNonWrappingUint32`](#tononwrappinguint32)(`index`).
+If `i` is greater or equal than the length of `T.[[Values]]`, a [`RangeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror) is thrown.
+
If `v` is an [Exported Function Exotic Object](#exported-function-exotic-objects):
* Set the `i`th element of `T.[[Table]]` to the `v.[[FunctionIndex]]`th function
in the module's [function index space](Modules.md#function-index-space).