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

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

Issue 1744713003: [wasm] Add an export table. (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/export-table.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 02d197c547b5ff8362c836b0f6d25c7fadad1ed7..f2f39cf56bde8f5c537c5833bc687394ff70a8ea 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -283,7 +283,8 @@ WasmModule::WasmModule()
functions(nullptr),
data_segments(nullptr),
function_table(nullptr),
- import_table(nullptr) {}
+ import_table(nullptr),
+ export_table(nullptr) {}
WasmModule::~WasmModule() {
if (globals) delete globals;
@@ -292,6 +293,7 @@ WasmModule::~WasmModule() {
if (data_segments) delete data_segments;
if (function_table) delete function_table;
if (import_table) delete import_table;
+ if (export_table) delete export_table;
}
static MaybeHandle<JSFunction> LookupFunction(ErrorThrower& thrower,
@@ -455,6 +457,32 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
instance.js_object->SetInternalField(kWasmModuleFunctionTable,
Smi::FromInt(0));
+ //-------------------------------------------------------------------------
+ // Create and populate the exports object.
+ //-------------------------------------------------------------------------
+ if (export_table->size() > 0) {
+ index = 0;
+ // Create the "exports" object.
+ Handle<JSFunction> object_function = Handle<JSFunction>(
+ isolate->native_context()->object_function(), isolate);
+ Handle<JSObject> exports_object =
+ factory->NewJSObject(object_function, TENURED);
+ Handle<String> exports_name = factory->InternalizeUtf8String("exports");
+ JSObject::AddProperty(instance.js_object, exports_name, exports_object,
+ READ_ONLY);
+
+ // Compile wrappers and add them to the exports object.
+ for (const WasmExport& exp : *export_table) {
+ if (thrower.error()) break;
+ const char* cstr = GetName(exp.name_offset);
+ Handle<String> name = factory->InternalizeUtf8String(cstr);
+ Handle<Code> code = linker.GetFunctionCode(exp.func_index);
+ Handle<JSFunction> function = compiler::CompileJSToWasmWrapper(
+ isolate, &module_env, name, code, instance.js_object, exp.func_index);
+ JSObject::AddProperty(exports_object, name, function, READ_ONLY);
+ }
+ }
+
// Run the start function if one was specified.
if (this->start_function_index >= 0) {
HandleScope scope(isolate);
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698