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 { ...@@ -324,7 +324,11 @@ class ModuleDecoder : public Decoder {
&module->min_mem_pages, &has_max, &module->min_mem_pages, &has_max,
kSpecMaxWasmMemoryPages, kSpecMaxWasmMemoryPages,
&module->max_mem_pages); &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; break;
} }
case kExternalGlobal: { case kExternalGlobal: {
......
...@@ -1658,6 +1658,9 @@ class WasmInstanceBuilder { ...@@ -1658,6 +1658,9 @@ class WasmInstanceBuilder {
break; break;
} }
case kExternalMemory: { case kExternalMemory: {
// Validation should have failed if more than one memory object was
// provided.
DCHECK(!instance->has_memory_object());
if (!WasmJs::IsWasmMemoryObject(isolate_, value)) { if (!WasmJs::IsWasmMemoryObject(isolate_, value)) {
ReportLinkError("memory import must be a WebAssembly.Memory object", ReportLinkError("memory import must be a WebAssembly.Memory object",
index, module_name, import_name); index, module_name, import_name);
......
...@@ -41,6 +41,13 @@ let importingModuleBinary = (() => { ...@@ -41,6 +41,13 @@ let importingModuleBinary = (() => {
return new Int8Array(builder.toBuffer()); 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 // 'WebAssembly' data property on global object
let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly'); let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly');
assertEq(typeof wasmDesc.value, "object"); assertEq(typeof wasmDesc.value, "object");
...@@ -478,6 +485,13 @@ assertEq(tbl.length, 2); ...@@ -478,6 +485,13 @@ assertEq(tbl.length, 2);
assertErrorMessage(() => tbl.grow(1), Error, /failed to grow table/); 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 // 'WebAssembly.compile' data property
let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile'); let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile');
assertEq(typeof compileDesc.value, "function"); 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