Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index a8af9de2d17a2b11359bc1d798a27090ba3bb598..c9876794b757c9c25cbda7fd446e8d1d82f3a292 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -463,15 +463,9 @@ MaybeLocal<Script> Shell::CompileString( |
| ScriptCompiler::CompileOptions compile_options, SourceType source_type) { |
|
neis
2016/09/16 20:53:33
This shouldn't take a SourceType anymore.
adamk
2016/09/16 20:58:06
Done.
|
| Local<Context> context(isolate->GetCurrentContext()); |
| ScriptOrigin origin(name); |
| - // TODO(adamk): Make use of compile options for Modules. |
| - if (compile_options == ScriptCompiler::kNoCompileOptions || |
| - source_type == MODULE) { |
| + if (compile_options == ScriptCompiler::kNoCompileOptions) { |
| ScriptCompiler::Source script_source(source, origin); |
| - return source_type == SCRIPT |
| - ? ScriptCompiler::Compile(context, &script_source, |
| - compile_options) |
| - : ScriptCompiler::CompileModule(context, &script_source, |
| - compile_options); |
| + return ScriptCompiler::Compile(context, &script_source, compile_options); |
| } |
| ScriptCompiler::CachedData* data = |
| @@ -507,14 +501,32 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, |
| Local<Context> realm = |
| Local<Context>::New(isolate, data->realms_[data->realm_current_]); |
| Context::Scope context_scope(realm); |
| - Local<Script> script; |
| - if (!Shell::CompileString(isolate, source, name, options.compile_options, |
| - source_type).ToLocal(&script)) { |
| - // Print errors that happened during compilation. |
| - if (report_exceptions) ReportException(isolate, &try_catch); |
| - return false; |
| + if (source_type == SCRIPT) { |
| + Local<Script> script; |
| + if (!Shell::CompileString(isolate, source, name, options.compile_options, |
| + source_type) |
| + .ToLocal(&script)) { |
| + // Print errors that happened during compilation. |
| + if (report_exceptions) ReportException(isolate, &try_catch); |
| + return false; |
| + } |
| + maybe_result = script->Run(realm); |
| + } else { |
| + DCHECK_EQ(MODULE, source_type); |
| + Local<Module> module; |
| + ScriptOrigin origin(name); |
| + ScriptCompiler::Source script_source(source, origin); |
| + // TODO(adamk): Make use of compile options for Modules. |
| + if (!ScriptCompiler::CompileModule(isolate, &script_source) |
| + .ToLocal(&module)) { |
| + // Print errors that happened during compilation. |
| + if (report_exceptions) ReportException(isolate, &try_catch); |
| + return false; |
| + } |
| + // This can't fail until we support linking. |
| + CHECK(module->Instantiate(realm).FromJust()); |
| + maybe_result = module->Evaluate(realm); |
| } |
| - maybe_result = script->Run(realm); |
| EmptyMessageQueues(isolate); |
| data->realm_current_ = data->realm_switch_; |
| } |