[wasm] Test and fix for module with no functions

Initialize the code table with a valid default (e.g. illegal builtin),
otherwise we're invalidating assumptions when relocating.

Bug: chromium:757217
Change-Id: I77890f1fe0e31534d9844d2e91694df1ec185110
Reviewed-on: https://chromium-review.googlesource.com/630097
Reviewed-by: Brad Nelson <bradnelson@chromium.org>
Commit-Queue: Brad Nelson <bradnelson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47560}
This commit is contained in:
Mircea Trofin 2017-08-23 14:55:45 -07:00 committed by Commit Bot
parent c5f675d022
commit 172d6f50e5
2 changed files with 23 additions and 1 deletions

View File

@ -2094,7 +2094,9 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
int code_table_size = static_cast<int>(module_->functions.size() +
module_->num_exported_functions);
job_->code_table_ = factory->NewFixedArray(code_table_size, TENURED);
for (int i = 0, e = module_->num_imported_functions; i < e; ++i) {
job_->code_table_->set(i, *illegal_builtin);
}
// Transfer ownership of the {WasmModule} to the {ModuleCompiler}, but
// keep a pointer.
WasmModule* module = module_.get();

View File

@ -0,0 +1,20 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
builder.addImport('','f', kSig_v_v);
builder.addExport('a', 0);
builder.addExport('b', 0);
var bytes = builder.toBuffer();
var m = new WebAssembly.Module(bytes);
assertTrue(m instanceof WebAssembly.Module);
assertPromiseResult(
WebAssembly.compile(bytes)
.then(async_result => assertTrue(async_result instanceof WebAssembly.Module),
assertUnreachable));