Commit 040f7434 authored by mtrofin's avatar mtrofin Committed by Commit bot

[wasm] JS API tests for `WebAssembly.validate`

Also ensuring it is validation error to specify more than
one memory import.

BUG=v8:5824

Review-Url: https://codereview.chromium.org/2624853002
Cr-Commit-Position: refs/heads/master@{#42205}
parent b5071c87
......@@ -324,7 +324,11 @@ class ModuleDecoder : public Decoder {
&module->min_mem_pages, &has_max,
kSpecMaxWasmMemoryPages,
&module->max_mem_pages);
module->has_memory = true;
if (module->has_memory) {
error("At most one memory object is supported");
} else {
module->has_memory = true;
}
break;
}
case kExternalGlobal: {
......
......@@ -1658,6 +1658,9 @@ class WasmInstanceBuilder {
break;
}
case kExternalMemory: {
// Validation should have failed if more than one memory object was
// provided.
DCHECK(!instance->has_memory_object());
if (!WasmJs::IsWasmMemoryObject(isolate_, value)) {
ReportLinkError("memory import must be a WebAssembly.Memory object",
index, module_name, import_name);
......
......@@ -41,6 +41,13 @@ let importingModuleBinary = (() => {
return new Int8Array(builder.toBuffer());
})();
let moduleBinaryImporting2Memories = (() => {
var builder = new WasmModuleBuilder();
builder.addImportedMemory("", "memory1");
builder.addImportedMemory("", "memory2");
return new Int8Array(builder.toBuffer());
})();
// 'WebAssembly' data property on global object
let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly');
assertEq(typeof wasmDesc.value, "object");
......@@ -478,6 +485,13 @@ assertEq(tbl.length, 2);
assertErrorMessage(() => tbl.grow(1), Error, /failed to grow table/);
}
// 'WebAssembly.validate' function
assertErrorMessage(() => WebAssembly.validate(), TypeError);
assertErrorMessage(() => WebAssembly.validate("hi"), TypeError);
assertEq(WebAssembly.validate(emptyModuleBinary), true);
// TODO: other ways for validate to return false.
assertEq(WebAssembly.validate(moduleBinaryImporting2Memories), false);
// 'WebAssembly.compile' data property
let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile');
assertEq(typeof compileDesc.value, "function");
......
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