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

Unified Diff: src/api.cc

Issue 2302783002: [modules] Basic support of exports (Closed)
Patch Set: . Created 4 years, 3 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/ast/ast.h » ('j') | src/contexts.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 0dfe70d5dd69c973e060ff636da8a7bf00385835..4996adcfbbe20cb5e60daacb41a40488b275866e 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1842,11 +1842,22 @@ MaybeLocal<Value> Script::Run(Local<Context> context) {
i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this));
- i::Handle<i::Object> receiver = isolate->global_proxy();
+
+ i::Handle<i::Object> receiver;
Local<Value> result;
- has_pending_exception =
- !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL),
- &result);
+
+ // TODO(neis): Make sure this is the only path that executes a module.
+ if (fun->shared()->scope_info()->scope_type() == i::MODULE_SCOPE) {
+ receiver = isolate->factory()->undefined_value();
+ i::Handle<i::Object> argv[] = {handle(isolate->native_context()->current_module())};
+ has_pending_exception = !ToLocal<Value>(
+ i::Execution::Call(isolate, fun, receiver, 1, argv), &result);
+ } else {
+ receiver = isolate->global_proxy();
+ has_pending_exception = !ToLocal<Value>(
+ i::Execution::Call(isolate, fun, receiver, 0, nullptr), &result);
+ }
+
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
@@ -1987,7 +1998,35 @@ MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context,
Local<UnboundScript> generic;
if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>();
v8::Context::Scope scope(context);
- return generic->BindToCurrentContext();
+ auto result = generic->BindToCurrentContext();
+
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ i::Handle<i::JSModule> module = i_isolate->factory()->NewJSModule();
+ // TODO: Storing the module into the native context is a temporary hack to
+ // pass it to the Script::Run function.
+ i_isolate->native_context()->set_current_module(*module);
+
+ i::Handle<i::SharedFunctionInfo> shared =
+ i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(*generic));
+ i::Handle<i::FixedArray> regular_exports =
+ i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(),
+ i_isolate);
+ for (int i = 0; i < regular_exports->length(); ++i) {
+ i::Handle<i::ModuleInfoEntry> entry =
+ i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate);
+ DCHECK(entry->import_name()->IsUndefined(i_isolate));
+ i::Handle<i::String> export_name =
+ handle(i::String::cast(entry->export_name()), i_isolate);
+ i::JSModule::CreateExport(module, export_name);
+#ifdef DEBUG
+ // TODO: Remove before landing.
+ printf("Created cell for export ");
+ export_name->Print();
+ printf("\n");
+#endif // DEBUG
+ }
+
+ return result;
}
« no previous file with comments | « no previous file | src/ast/ast.h » ('j') | src/contexts.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698