Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
Browse files Browse the repository at this point in the history
…any resulting failures. r=lth.

The WebAssembly Specification, branch [1] (see also, more generally,
comments in [2]), contains a new test, limits.js, to check whether the
generally agreed embedding limits (numbers of functions, imports, etc) are
observed.  This bug is to import the test and fix any resulting breakage
detected with it.

[1] https://github.com/WebAssembly/spec/tree/embedding_limits
[2] WebAssembly/spec#607

* js/src/wasm/WasmBinaryConstants.h:
  - Added MaxTableMaximumLength as a counterpart to MaxTableInitialLength.
  - Split the constant group into two parts: spec-required, and those
    pertaining only to our own implementation.

* js/src/wasm/WasmJS.cpp  WasmTableObject::construct():
  - Update GetLimits call with correct max size bound

* js/src/wasm/WasmValidate.cpp  DecodeTableLimits():
  - Implement missing check for a Table's maximum size.

* js/src/jit-test/tests/wasm/import-export.js:
  js/src/jit-test/tests/wasm/spec/jsapi.js:
  testing/web-platform/mozilla/tests/wasm/js/jsapi.js:
  - Update Table maximum size tests.  All tests trying to make a Table
    with more than 10,000,000 entries now throw instead of succeeding.

* js/src/jit-test/tests/wasm/spec/harness/wasm-module-builder.js:
  - Import minimal updates and bug fixes from [1], needed to make the
    new tests work.

* js/src/jit-test/tests/wasm/spec/limits.js
  - New file.  Derived from [1], with comments added to each test to show
    SM's compliance situation, and with two tests disabled.
  • Loading branch information
julian-seward1 committed Jun 8, 2018
1 parent cde0ed3 commit cfee145
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 24 deletions.
4 changes: 2 additions & 2 deletions js/src/jit-test/tests/wasm/import-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ assertErrorMessage(() => new Memory({initial: 0, maximum: 65537}), RangeError, /
assertErrorMessage(() => new Table({initial:2, maximum:1, element:"anyfunc"}), RangeError, /bad Table maximum size/);
new Table({ initial: 10000000, element:"anyfunc" });
assertErrorMessage(() => new Table({initial:10000001, element:"anyfunc"}), RangeError, /bad Table initial size/);
new Table({ initial: 0, maximum: 2**32 - 1, element:"anyfunc" });
assertErrorMessage(() => new Table({initial:0, maximum: 2**32, element:"anyfunc"}), RangeError, /bad Table maximum size/);
new Table({ initial: 0, maximum: 10000000, element:"anyfunc" });
assertErrorMessage(() => new Table({initial:0, maximum: 10000001, element:"anyfunc"}), RangeError, /bad Table maximum size/);

const m1 = new Module(wasmTextToBinary('(module (import "foo" "bar") (import "baz" "quux"))'));
assertErrorMessage(() => new Instance(m1), TypeError, /second argument must be an object/);
Expand Down
39 changes: 28 additions & 11 deletions js/src/jit-test/tests/wasm/spec/harness/wasm-module-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ class Binary extends Array {
// Emit section name.
this.emit_u8(section_code);
// Emit the section to a temporary buffer: its full length isn't know yet.
let section = new Binary;
const section = new Binary;
content_generator(section);
// Emit section length.
this.emit_u32v(section.length);
// Copy the temporary buffer.
this.push(...section);
for (const b of section) {
this.push(b);
}
}
}

Expand Down Expand Up @@ -238,11 +240,22 @@ class WasmModuleBuilder {
}

appendToTable(array) {
for (let n of array) {
if (typeof n != 'number')
throw new Error('invalid table (entries have to be numbers): ' + array);
}
return this.addFunctionTableInit(this.function_table.length, false, array);
}

setFunctionTableBounds(min, max) {
this.function_table_length_min = min;
this.function_table_length_max = max;
return this;
}

setFunctionTableLength(length) {
this.function_table_length = length;
this.function_table_length_min = length;
this.function_table_length_max = length;
return this;
}

Expand Down Expand Up @@ -320,25 +333,29 @@ class WasmModuleBuilder {
}

// Add function_table.
if (wasm.function_table_length > 0) {
if (wasm.function_table_length_min > 0) {
if (debug) print("emitting table @ " + binary.length);
binary.emit_section(kTableSectionCode, section => {
section.emit_u8(1); // one table entry
section.emit_u8(kWasmAnyFunctionTypeForm);
section.emit_u8(1);
section.emit_u32v(wasm.function_table_length);
section.emit_u32v(wasm.function_table_length);
const max = wasm.function_table_length_max;
const has_max = max !== undefined;
section.emit_u8(has_max ? kResizableMaximumFlag : 0);
section.emit_u32v(wasm.function_table_length_min);
if (has_max) section.emit_u32v(max);
});
}

// Add memory section
if (wasm.memory != undefined) {
if (wasm.memory !== undefined) {
if (debug) print("emitting memory @ " + binary.length);
binary.emit_section(kMemorySectionCode, section => {
section.emit_u8(1); // one memory entry
section.emit_u32v(kResizableMaximumFlag);
const max = wasm.memory.max;
const has_max = max !== undefined;
section.emit_u32v(has_max ? kResizableMaximumFlag : 0);
section.emit_u32v(wasm.memory.min);
section.emit_u32v(wasm.memory.max);
if (has_max) section.emit_u32v(max);
});
}

Expand Down Expand Up @@ -426,9 +443,9 @@ class WasmModuleBuilder {
binary.emit_section(kElementSectionCode, section => {
var inits = wasm.function_table_inits;
section.emit_u32v(inits.length);
section.emit_u8(0); // table index

for (let init of inits) {
section.emit_u8(0); // table index
if (init.is_global) {
section.emit_u8(kExprGetGlobal);
} else {
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/spec/jsapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ test(() => {
assert_equals(new Table({initial:1, element:"anyfunc"}) instanceof Table, true);
assert_equals(new Table({initial:1.5, element:"anyfunc"}) instanceof Table, true);
assert_equals(new Table({initial:1, maximum:1.5, element:"anyfunc"}) instanceof Table, true);
assert_equals(new Table({initial:1, maximum:Math.pow(2,32)-1, element:"anyfunc"}) instanceof Table, true);
assertThrows(() => new Table({initial:1, maximum:Math.pow(2,32)-1, element:"anyfunc"}), RangeError);
}, "'WebAssembly.Table' constructor function");

test(() => {
Expand Down
Loading

0 comments on commit cfee145

Please sign in to comment.