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

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

Issue 2623183002: [wasm] Implement WebAssembly.Module.exports function. (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | src/wasm/wasm-module.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-js.cc
diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc
index b443610449aea77b91b0601055a1ed7b827fc839..8a4b06d9253a7451a104a8486f45377bc185bbd5 100644
--- a/src/wasm/wasm-js.cc
+++ b/src/wasm/wasm-js.cc
@@ -262,6 +262,36 @@ void WebAssemblyModuleImports(const v8::FunctionCallbackInfo<v8::Value>& args) {
return_value.Set(Utils::ToLocal(imports));
}
+void WebAssemblyModuleExports(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ HandleScope scope(args.GetIsolate());
+ v8::Isolate* isolate = args.GetIsolate();
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+
+ ErrorThrower thrower(i_isolate, "WebAssembly.Module.exports()");
+
+ if (args.Length() < 1) {
+ thrower.TypeError("Argument 0 must be a WebAssembly.Module");
+ return;
+ }
+
+ Local<Context> context = isolate->GetCurrentContext();
+ i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
+ if (!BrandCheck(isolate, Utils::OpenHandle(*args[0]),
+ i::Handle<i::Symbol>(i_context->wasm_module_sym()),
+ "Argument 0 must be a WebAssembly.Module")) {
+ return;
+ }
+
+ Local<Object> module_obj = Local<Object>::Cast(args[0]);
+ i::Handle<i::WasmModuleObject> i_module_obj =
+ i::Handle<i::WasmModuleObject>::cast(v8::Utils::OpenHandle(*module_obj));
+
+ i::Handle<i::JSArray> exports = i::wasm::GetExports(i_isolate, i_module_obj);
+
+ v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
+ return_value.Set(Utils::ToLocal(exports));
+}
+
void WebAssemblyInstanceCtor(const v8::FunctionCallbackInfo<v8::Value>& args) {
HandleScope scope(args.GetIsolate());
v8::Isolate* isolate = args.GetIsolate();
@@ -753,6 +783,8 @@ void WasmJs::InstallWasmConstructors(Isolate* isolate,
module_constructor, DONT_ENUM);
InstallFunc(isolate, module_constructor, "imports", WebAssemblyModuleImports,
1);
+ InstallFunc(isolate, module_constructor, "exports", WebAssemblyModuleExports,
+ 1);
// Setup Instance
Handle<JSFunction> instance_constructor =
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698