Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1017)

Unified Diff: test/mjsunit/wasm/table.js

Issue 2411963003: Implement Table#length and Table#get (Closed)
Patch Set: Git format nonsense Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+})();
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698