| Index: src/compiler-dispatcher/compiler-dispatcher-job.cc | 
| diff --git a/src/compiler-dispatcher/compiler-dispatcher-job.cc b/src/compiler-dispatcher/compiler-dispatcher-job.cc | 
| index 8134e4fec0b975f232505d015a67b329c361f0b7..923793665aa3cd503ab554ada9fcf67f00b4e662 100644 | 
| --- a/src/compiler-dispatcher/compiler-dispatcher-job.cc | 
| +++ b/src/compiler-dispatcher/compiler-dispatcher-job.cc | 
| @@ -119,7 +119,7 @@ void CompilerDispatcherJob::Parse() { | 
| status_ = CompileJobStatus::kParsed; | 
| } | 
|  | 
| -void CompilerDispatcherJob::FinalizeParsingOnMainThread() { | 
| +bool CompilerDispatcherJob::FinalizeParsingOnMainThread() { | 
| DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 
| DCHECK(status() == CompileJobStatus::kParsed); | 
|  | 
| @@ -130,22 +130,37 @@ void CompilerDispatcherJob::FinalizeParsingOnMainThread() { | 
|  | 
| if (parse_info_->literal() == nullptr) { | 
| status_ = CompileJobStatus::kFailed; | 
| -    return; | 
| +  } else { | 
| +    status_ = CompileJobStatus::kReadyToCompile; | 
| } | 
|  | 
| -  InternalizeParsingResult(); | 
| - | 
| -  status_ = CompileJobStatus::kReadyToCompile; | 
| -} | 
| - | 
| -void CompilerDispatcherJob::ReportErrorsOnMainThread() { | 
| -  DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 
| -  DCHECK(status() == CompileJobStatus::kFailed); | 
| - | 
| -  // Internalizing the parsing result will throw the error. | 
| -  InternalizeParsingResult(); | 
| +  DeferredHandleScope scope(isolate_); | 
| +  { | 
| +    // Create a canonical handle scope before internalizing parsed values if | 
| +    // compiling bytecode. This is required for off-thread bytecode generation. | 
| +    std::unique_ptr<CanonicalHandleScope> canonical; | 
| +    if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | 
| + | 
| +    Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 
| +    Handle<Script> script(Script::cast(shared->script()), isolate_); | 
| + | 
| +    parse_info_->set_script(script); | 
| +    parse_info_->set_context(handle(function_->context(), isolate_)); | 
| + | 
| +    // Do the parsing tasks which need to be done on the main thread. This will | 
| +    // also handle parse errors. | 
| +    parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); | 
| +    parser_->HandleSourceURLComments(isolate_, script); | 
| + | 
| +    parse_info_->set_character_stream(nullptr); | 
| +    parse_info_->set_unicode_cache(nullptr); | 
| +    parser_.reset(); | 
| +    unicode_cache_.reset(); | 
| +    character_stream_.reset(); | 
| +  } | 
| +  handles_from_parsing_.reset(scope.Detach()); | 
|  | 
| -  status_ = CompileJobStatus::kDone; | 
| +  return status_ != CompileJobStatus::kFailed; | 
| } | 
|  | 
| void CompilerDispatcherJob::ResetOnMainThread() { | 
| @@ -156,6 +171,7 @@ void CompilerDispatcherJob::ResetOnMainThread() { | 
| character_stream_.reset(); | 
| parse_info_.reset(); | 
| zone_.reset(); | 
| +  handles_from_parsing_.reset(); | 
|  | 
| if (!source_.is_null()) { | 
| i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 
| @@ -165,35 +181,5 @@ void CompilerDispatcherJob::ResetOnMainThread() { | 
| status_ = CompileJobStatus::kInitial; | 
| } | 
|  | 
| -void CompilerDispatcherJob::InternalizeParsingResult() { | 
| -  DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 
| -  DCHECK(status() == CompileJobStatus::kParsed || | 
| -         status() == CompileJobStatus::kFailed); | 
| - | 
| -  HandleScope scope(isolate_); | 
| - | 
| -  // Create a canonical handle scope before internalizing parsed values if | 
| -  // compiling bytecode. This is required for off-thread bytecode generation. | 
| -  std::unique_ptr<CanonicalHandleScope> canonical; | 
| -  if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | 
| - | 
| -  Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 
| -  Handle<Script> script(Script::cast(shared->script()), isolate_); | 
| - | 
| -  parse_info_->set_script(script); | 
| -  parse_info_->set_context(handle(function_->context(), isolate_)); | 
| - | 
| -  // Do the parsing tasks which need to be done on the main thread. This will | 
| -  // also handle parse errors. | 
| -  parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); | 
| -  parser_->HandleSourceURLComments(isolate_, script); | 
| - | 
| -  parse_info_->set_character_stream(nullptr); | 
| -  parse_info_->set_unicode_cache(nullptr); | 
| -  parser_.reset(); | 
| -  unicode_cache_.reset(); | 
| -  character_stream_.reset(); | 
| -} | 
| - | 
| }  // namespace internal | 
| }  // namespace v8 | 
|  |