Index: test/mjsunit/wasm/table.js |
diff --git a/test/mjsunit/wasm/table.js b/test/mjsunit/wasm/table.js |
index 0275bc05225c70e5be65032b6e0f0053b5c27cfb..1b56b615850b41a9966ec1ea8c342fad1d590072 100644 |
--- a/test/mjsunit/wasm/table.js |
+++ b/test/mjsunit/wasm/table.js |
@@ -45,25 +45,46 @@ function assertTableIsValid(table) { |
assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: int32ButOob})); |
- let table = new WebAssembly.Table({element: "anyfunc", initial: 1}); |
+ let table; |
+ table = new WebAssembly.Table({element: "anyfunc", initial: 1}); |
assertTableIsValid(table); |
-})(); |
+ assertEquals(1, table.length); |
+ assertEquals(null, table.get(0)); |
-(function TestConstructorWithMaximum() { |
- let table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); |
+ table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); |
assertTableIsValid(table); |
-})(); |
+ assertEquals(2, table.length); |
+ assertEquals(null, table.get(0)); |
+ assertEquals(null, table.get(1)); |
-(function TestInitialIsUndefined() { |
- // New memory with initial = undefined, which means initial = 0. |
- let table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); |
+ table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { return "1" }}}); |
assertTableIsValid(table); |
-})(); |
+ assertEquals(1, table.length); |
+ assertEquals(null, table.get(0)); |
+ |
+ table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); |
+ assertTableIsValid(table); |
+ assertEquals(0, table.length); |
+ |
+ table = new WebAssembly.Table({element: "anyfunc"}); |
+ assertTableIsValid(table); |
+ assertEquals(0, table.length); |
+ |
+ table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); |
+ assertTableIsValid(table); |
+ assertEquals(0, table.length); |
+ |
+ table = new WebAssembly.Table({element: "anyfunc", maximum: "10"}); |
+ assertTableIsValid(table); |
+ assertEquals(0, table.length); |
-(function TestMaximumIsUndefined() { |
- // New memory with maximum = undefined, which means maximum = 0. |
- let table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefined}); |
+ table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { return "10" }}}); |
assertTableIsValid(table); |
+ assertEquals(0, table.length); |
+ |
+ table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefined}); |
+ assertTableIsValid(table); |
+ assertEquals(0, table.length); |
})(); |
(function TestMaximumIsReadOnce() { |
@@ -93,3 +114,32 @@ function assertTableIsValid(table) { |
let table = new WebAssembly.Table(desc); |
assertTableIsValid(table); |
})(); |
+ |
+(function TestLength() { |
+ for (let i = 0; i < 10; ++i) { |
+ let table = new WebAssembly.Table({element: "anyfunc", initial: i}); |
+ assertEquals(i, table.length); |
+ } |
+ |
+ assertThrows(() => WebAssembly.Table.prototype.length.call([]), TypeError); |
+})(); |
+ |
+(function TestGet() { |
+ let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); |
+ |
+ for (let i = 0; i < 10; ++i) { |
+ assertEquals(null, table.get(i)); |
+ assertEquals(null, table.get(String(i))); |
+ } |
+ assertEquals(null, table.get("")); |
+ assertEquals(null, table.get(NaN)); |
+ assertEquals(null, table.get({})); |
+ assertEquals(null, table.get([])); |
+ assertEquals(null, table.get(() => {})); |
+ |
+ assertEquals(undefined, table.get(10)); |
+ assertEquals(undefined, table.get(-1)); |
+ |
+ assertThrows(() => table.get(Symbol()), TypeError); |
+ assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError); |
+})(); |