Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: src/wasm/wasm-module.cc

Issue 1692173002: [wasm] Add support for a start function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/start-function.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 340125e73a7d008ffcf3e673d2f26d3344d74928..b1dfbc602e0d7cb0266a9e4f180491272440c494 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -256,15 +256,21 @@ bool AllocateGlobals(ErrorThrower* thrower, Isolate* isolate,
}
} // namespace
-
WasmModule::WasmModule()
- : globals(nullptr),
+ : shared_isolate(nullptr),
+ module_start(nullptr),
+ module_end(nullptr),
+ min_mem_size_log2(0),
+ max_mem_size_log2(0),
+ mem_export(false),
+ mem_external(false),
+ start_function_index(-1),
+ globals(nullptr),
signatures(nullptr),
functions(nullptr),
data_segments(nullptr),
function_table(nullptr) {}
-
WasmModule::~WasmModule() {
if (globals) delete globals;
if (signatures) delete signatures;
@@ -403,6 +409,25 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
linker.Link(instance.function_table, this->function_table);
instance.js_object->SetInternalField(kWasmModuleFunctionTable,
Smi::FromInt(0));
+
+ // Run the start function if one was specified.
+ if (this->start_function_index >= 0) {
+ HandleScope scope(isolate);
+ uint32_t index = static_cast<uint32_t>(this->start_function_index);
+ Handle<String> name = isolate->factory()->NewStringFromStaticChars("start");
+ Handle<Code> code = linker.GetFunctionCode(index);
+ Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper(
+ isolate, &module_env, name, code, instance.js_object, index);
+
+ // Call the JS function.
+ Handle<Object> undefined(isolate->heap()->undefined_value(), isolate);
+ MaybeHandle<Object> retval =
+ Execution::Call(isolate, jsfunc, undefined, 0, nullptr);
+
+ if (retval.is_null()) {
+ thrower.Error("WASM.instantiateModule(): start function failed");
+ }
+ }
return instance.js_object;
}
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/start-function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698