From f7004430f876c60fa53e6dcd14d2c7537ed1198e Mon Sep 17 00:00:00 2001 From: rossberg-chromium Date: Fri, 14 Oct 2016 18:28:41 +0200 Subject: 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. --- JS.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'JS.md') 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). -- cgit v1.2.3