Commit a64e6b50 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm][test] Add additional module builder checks.

R=clemensh@chromium.org

Change-Id: I9734259c9f41378ac216d5a222f0f7c71fcb5fa6
Reviewed-on: https://chromium-review.googlesource.com/1219023Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55781}
parent 6afe7d18
......@@ -37,8 +37,6 @@ function GlobalImportedInitTest(pad) {
var builder = new WasmModuleBuilder();
builder.addMemory(1, 1, false);
while (pad-- > 0) builder.addGlobal(kWasmI32); // pad
var g = builder.addImportedGlobal("mod", "offset", kWasmI32);
while (pad-- > 0) builder.addGlobal(kWasmI32); // pad
......
......@@ -195,7 +195,7 @@ function addGlobalGetterAndSetter(builder, index, name, type) {
(function TestImportedAndNonImportedMutableGlobal() {
let global = new WebAssembly.Global({value: 'i32', mutable: true}, 1);
let builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI32, true).exportAs('i32');
builder.addImportedGlobal("mod", "g", kWasmI32, true);
builder.addGlobal(kWasmI32, true).exportAs('i32');
builder.instantiate({mod: {g: global}});
})();
......@@ -159,8 +159,8 @@ function assertTableIsValid(table, length) {
(function TestSet() {
let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
......@@ -207,8 +207,8 @@ function assertTableIsValid(table, length) {
(function TestIndexing() {
let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
......@@ -230,8 +230,8 @@ function assertTableIsValid(table, length) {
(function TestGrow() {
let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
function init(table) {
......
......@@ -246,6 +246,9 @@ class WasmModuleBuilder {
}
addImport(module = "", name, type) {
if (this.functions.length != 0) {
throw new Error('Imported functions must be declared before local ones');
}
let type_index = (typeof type) == "number" ? type : this.addType(type);
this.imports.push({module: module, name: name, kind: kExternalFunction,
type: type_index});
......@@ -253,6 +256,9 @@ class WasmModuleBuilder {
}
addImportedGlobal(module = "", name, type, mutable = false) {
if (this.globals.length != 0) {
throw new Error('Imported globals must be declared before local ones');
}
let o = {module: module, name: name, kind: kExternalGlobal, type: type,
mutable: mutable};
this.imports.push(o);
......
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