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

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

Issue 2414053002: [wasm] Implement Table#set and Table#grow (Closed)
Patch Set: 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') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | 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 1b56b615850b41a9966ec1ea8c342fad1d590072..e2f76dad1ae9974d4486def91bebed3448867acb 100644
--- a/test/mjsunit/wasm/table.js
+++ b/test/mjsunit/wasm/table.js
@@ -4,6 +4,11 @@
// Flags: --expose-wasm
+'use strict';
+
+load("test/mjsunit/wasm/wasm-constants.js");
+load("test/mjsunit/wasm/wasm-module-builder.js");
+
// Basic tests.
var outOfUint32RangeValue = 1e12;
@@ -131,15 +136,93 @@ function assertTableIsValid(table) {
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));
+ for (let key of [0.4, "", NaN, {}, [], () => {}]) {
+ assertEquals(null, table.get(key));
+ }
+ for (let key of [10, -1]) {
+ assertEquals(undefined, table.get(key));
+ }
assertThrows(() => table.get(Symbol()), TypeError);
assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError);
})();
+
+(function TestSet() {
+ let builder = new WasmModuleBuilder;
+ builder.addExport("wasm", builder.addFunction("", kSig_v_v));
+ builder.addExport("host", builder.addImportWithModule("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 [null, wasm, host]) {
+ for (let i = 0; i < 10; ++i) table.set(i, f);
+ for (let i = 0; i < 10; ++i) assertSame(f, table.get(i));
+ for (let i = 0; i < 10; ++i) table.set(String(i), f);
ahaas 2016/10/13 14:25:09 Could you do the last two for loops in a separate
rossberg 2016/10/13 14:43:46 Done.
+ for (let i = 0; i < 10; ++i) assertSame(f, table.get(i));
+
ahaas 2016/10/13 14:25:09 Could you also add a test where you check that the
rossberg 2016/10/13 14:43:46 Done.
+ for (let key of [0.4, "", NaN, {}, [], () => {}]) {
+ table.set(0, null);
+ table.set(key, f);
+ assertSame(f, table.get(0));
+ }
+
+ for (let key of [10, -1]) {
ahaas 2016/10/13 14:25:09 According to the spec a RangeError should be throw
rossberg 2016/10/13 14:43:46 Done.
+ table.set(key, f); // ignored
ahaas 2016/10/13 14:25:09 Should we adjust the spec to specify what should h
rossberg 2016/10/13 14:43:46 Yes, probably. I changed the implementation to thr
+ }
+
+ assertThrows(() => table.set(0), TypeError);
+ assertThrows(() => table.set(0, undefined), TypeError);
+ assertThrows(() => table.set(0, 0), TypeError);
+ assertThrows(() => table.set(0, ""), TypeError);
+ assertThrows(() => table.set(0, {}), TypeError);
+ assertThrows(() => table.set(0, () => {}), TypeError);
+
+ assertThrows(() => table.set(Symbol(), f), TypeError);
+ assertThrows(() => WebAssembly.Table.prototype.set.call([], 0, f),
+ TypeError);
+ }
ahaas 2016/10/13 14:25:09 Do you check somewhere already that table.set retu
rossberg 2016/10/13 14:43:46 No, done.
+})();
+
+(function TestGrow() {
+ let builder = new WasmModuleBuilder;
+ builder.addExport("wasm", builder.addFunction("", kSig_v_v));
+ builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v));
+ let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
+
+ function init(table) {
+ for (let i = 0; i < 5; ++i) table.set(i, wasm);
+ for (let i = 15; i < 20; ++i) table.set(i, host);
+ }
+ function check(table) {
+ for (let i = 0; i < 5; ++i) assertSame(wasm, table.get(i));
+ for (let i = 6; i < 15; ++i) assertSame(null, table.get(i));
+ for (let i = 15; i < 20; ++i) assertSame(host, table.get(i));
+ for (let i = 21; i < table.length; ++i) assertSame(null, table.get(i));
+ }
+
+ let table = new WebAssembly.Table({element: "anyfunc", initial: 20});
+ init(table);
+ check(table);
+ table.grow(20);
+ check(table);
+ table.grow(30);
+ check(table);
+ assertThrows(() => table.grow(10), RangeError);
+ assertThrows(() => table.grow(20), RangeError);
+
+ table = new WebAssembly.Table({element: "anyfunc", initial: 20, maximum: 25});
+ init(table);
+ check(table);
+ table.grow(20);
+ check(table);
+ table.grow(25);
+ check(table);
+ table.grow(25);
+ check(table);
+ assertThrows(() => table.grow(10), RangeError);
+ assertThrows(() => table.grow(20), RangeError);
+ assertThrows(() => table.grow(26), RangeError);
+
+ assertThrows(() => WebAssembly.Table.prototype.grow.call([], 20), TypeError);
+})();
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698