| 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;
|
| }
|
|
|
|
|
|
|