Commit e2563e94 authored by rossberg's avatar rossberg Committed by Commit bot

Test that table object indexing does not interfere with backing table

BUG=
R=ahaas@chromium.or

Review-Url: https://codereview.chromium.org/2502383003
Cr-Commit-Position: refs/heads/master@{#41074}
parent 937b8cb6
......@@ -55,17 +55,21 @@ function assertTableIsValid(table) {
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);
......@@ -160,6 +164,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 +172,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,6 +197,30 @@ function assertTableIsValid(table) {
}
})();
(function TestIndexing() {
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 [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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment