Commit 68fdaf6d authored by titzer's avatar titzer Committed by Commit bot

[wasm] Wrap start function in a JS->WASM wrapper before calling it during initialization.

BUG=v8:5599
R=ahaas@chromium.org

Review-Url: https://codereview.chromium.org/2483193002
Cr-Commit-Position: refs/heads/master@{#40830}
parent 03a1eb5a
......@@ -1233,12 +1233,18 @@ class WasmInstanceBuilder {
//--------------------------------------------------------------------------
if (module_->start_function_index >= 0) {
HandleScope scope(isolate_);
ModuleEnv module_env;
module_env.module = module_;
module_env.instance = nullptr;
module_env.origin = module_->origin;
int start_index = module_->start_function_index;
Handle<Code> startup_code =
code_table->GetValueChecked<Code>(isolate_, start_index);
FunctionSig* sig = module_->functions[start_index].sig;
Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper(
isolate_, &module_env, startup_code, start_index);
Handle<JSFunction> startup_fct = WrapExportCodeAsJSFunction(
isolate_, startup_code, factory->InternalizeUtf8String("start"), sig,
isolate_, wrapper_code, factory->InternalizeUtf8String("start"), sig,
start_index, instance);
RecordStats(isolate_, *startup_code);
// Call the JS function.
......
......@@ -62,14 +62,31 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
})();
(function testRun() {
print("testRun");
(function testRun1() {
print("testRun1");
var builder = new WasmModuleBuilder();
builder.addMemory(12, 12, true);
var func = builder.addFunction("", kSig_v_v)
.addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]);
.addBody([kExprI8Const, 0, kExprI8Const, 66, kExprI32StoreMem, 0, 0]);
builder.addStart(func.index);
var module = builder.instantiate();
var memory = module.exports.memory.buffer;
var view = new Int8Array(memory);
assertEquals(66, view[0]);
})();
(function testRun2() {
print("testRun2");
var builder = new WasmModuleBuilder();
builder.addMemory(12, 12, true);
var func = builder.addFunction("", kSig_v_v)
.addBody([kExprI8Const, 0, kExprI8Const, 22, kExprI8Const, 55, kExprI32Add, kExprI32StoreMem, 0, 0]);
builder.addStart(func.index);
......
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