summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/table.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/table.js')
-rw-r--r--deps/v8/test/mjsunit/wasm/table.js71
1 files changed, 60 insertions, 11 deletions
diff --git a/deps/v8/test/mjsunit/wasm/table.js b/deps/v8/test/mjsunit/wasm/table.js
index 1abc29664e..ed5c61f41a 100644
--- a/deps/v8/test/mjsunit/wasm/table.js
+++ b/deps/v8/test/mjsunit/wasm/table.js
@@ -13,6 +13,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var outOfUint32RangeValue = 1e12;
var int32ButOob = 1073741824;
+var kMaxUint32 = (4 * 1024 * 1024 * 1024) - 1;
+var kV8MaxWasmTableSize = 10000000;
function assertTableIsValid(table) {
assertSame(WebAssembly.Table.prototype, table.__proto__);
@@ -41,31 +43,38 @@ function assertTableIsValid(table) {
assertThrows(() => new WebAssembly.Table({element: 0, initial: 10}), TypeError);
assertThrows(() => new WebAssembly.Table({element: "any", initial: 10}), TypeError);
- assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: -1}), RangeError);
- assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUint32RangeValue}), RangeError);
+ assertThrows(() => new WebAssembly.Table(
+ {element: "anyfunc", initial: -1}), RangeError);
+ assertThrows(() => new WebAssembly.Table(
+ {element: "anyfunc", initial: outOfUint32RangeValue}), RangeError);
- assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, maximum: -1}), RangeError);
- assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, maximum: outOfUint32RangeValue}), RangeError);
- assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, maximum: 9}), RangeError);
-
- assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: int32ButOob}));
+ assertThrows(() => new WebAssembly.Table(
+ {element: "anyfunc", initial: 10, maximum: -1}), RangeError);
+ assertThrows(() => new WebAssembly.Table(
+ {element: "anyfunc", initial: 10, maximum: outOfUint32RangeValue}), RangeError);
+ assertThrows(() => new WebAssembly.Table(
+ {element: "anyfunc", initial: 10, maximum: 9}), RangeError);
let table;
table = new WebAssembly.Table({element: "anyfunc", initial: 1});
assertTableIsValid(table);
assertEquals(1, table.length);
assertEquals(null, table.get(0));
+ assertEquals(undefined, table[0]);
table = new WebAssembly.Table({element: "anyfunc", initial: "2"});
assertTableIsValid(table);
assertEquals(2, table.length);
assertEquals(null, table.get(0));
assertEquals(null, table.get(1));
+ assertEquals(undefined, table[0]);
+ assertEquals(undefined, table[1]);
table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { return "1" }}});
assertTableIsValid(table);
assertEquals(1, table.length);
assertEquals(null, table.get(0));
+ assertEquals(undefined, table[0]);
table = new WebAssembly.Table({element: "anyfunc", initial: undefined});
assertTableIsValid(table);
@@ -90,6 +99,14 @@ function assertTableIsValid(table) {
table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefined});
assertTableIsValid(table);
assertEquals(0, table.length);
+
+ table = new WebAssembly.Table({element: "anyfunc", maximum: kMaxUint32});
+ assertTableIsValid(table);
+ assertEquals(0, table.length);
+
+ table = new WebAssembly.Table({element: "anyfunc", maximum: kV8MaxWasmTableSize + 1});
+ assertTableIsValid(table);
+ assertEquals(0, table.length);
})();
(function TestMaximumIsReadOnce() {
@@ -148,8 +165,8 @@ function assertTableIsValid(table) {
(function TestSet() {
let builder = new WasmModuleBuilder;
- builder.addExport("wasm", builder.addFunction("", kSig_v_v));
- builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v));
+ builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
+ builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
@@ -160,6 +177,7 @@ function assertTableIsValid(table) {
assertSame(null, table.get(i));
assertSame(undefined, table.set(i, f));
assertSame(f, table.get(i));
+ assertSame(undefined, table[i]);
}
for (let i = 0; i < table.length; ++i) table.set(i, null);
@@ -167,12 +185,14 @@ function assertTableIsValid(table) {
assertSame(null, table.get(i));
assertSame(undefined, table.set(String(i), f));
assertSame(f, table.get(i));
+ assertSame(undefined, table[i]);
}
for (let key of [0.4, "", NaN, {}, [], () => {}]) {
assertSame(undefined, table.set(0, null));
assertSame(undefined, table.set(key, f));
assertSame(f, table.get(0));
+ assertSame(undefined, table[key]);
}
for (let key of [-1, table.length, table.length * 10]) {
@@ -190,10 +210,34 @@ function assertTableIsValid(table) {
}
})();
+
+(function TestIndexing() {
+ let builder = new WasmModuleBuilder;
+ builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
+ builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
+ let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
+
+ let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
+
+ for (let f of [wasm, host, () => {}, 5, {}, ""]) {
+ for (let i = 0; i < table.length; ++i) table[i] = f;
+ for (let i = 0; i < table.length; ++i) {
+ assertSame(null, table.get(i));
+ assertSame(f, table[i]);
+ }
+
+ for (let key of [0.4, "", NaN, {}, [], () => {}]) {
+ assertSame(f, table[key] = f);
+ assertSame(f, table[key]);
+ assertSame(null, table.get(key));
+ }
+ }
+})();
+
(function TestGrow() {
let builder = new WasmModuleBuilder;
- builder.addExport("wasm", builder.addFunction("", kSig_v_v));
- builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v));
+ builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
+ builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
function init(table) {
@@ -229,4 +273,9 @@ function assertTableIsValid(table) {
assertThrows(() => table.grow(-10), RangeError);
assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError);
+
+ table = new WebAssembly.Table(
+ {element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize});
+ table.grow(kV8MaxWasmTableSize);
+ assertThrows(() => table.grow(1), RangeError);
})();