// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/parsing/pending-compilation-error-handler.h" #include "src/ast/ast-value-factory.h" #include "src/base/export-template.h" #include "src/base/logging.h" #include "src/debug/debug.h" #include "src/execution/isolate.h" #include "src/execution/messages.h" #include "src/execution/off-thread-isolate.h" #include "src/handles/handles.h" #include "src/heap/off-thread-factory-inl.h" #include "src/objects/objects-inl.h" namespace v8 { namespace internal { void PendingCompilationErrorHandler::MessageDetails::SetString( Handle string, Isolate* isolate) { DCHECK_NE(type_, kMainThreadHandle); DCHECK_NE(type_, kOffThreadTransferHandle); type_ = kMainThreadHandle; arg_handle_ = string; } void PendingCompilationErrorHandler::MessageDetails::SetString( Handle string, OffThreadIsolate* isolate) { DCHECK_NE(type_, kMainThreadHandle); DCHECK_NE(type_, kOffThreadTransferHandle); type_ = kOffThreadTransferHandle; arg_transfer_handle_ = isolate->TransferHandle(string); } template void PendingCompilationErrorHandler::MessageDetails::Prepare( LocalIsolate* isolate) { switch (type_) { case kAstRawString: return SetString(arg_->string(), isolate); case kNone: case kConstCharString: // We can delay allocation until ArgumentString(isolate). // TODO(leszeks): We don't actually have to transfer this string, since // it's a root. return; case kMainThreadHandle: case kOffThreadTransferHandle: UNREACHABLE(); } } Handle PendingCompilationErrorHandler::MessageDetails::ArgumentString( Isolate* isolate) const { switch (type_) { case kMainThreadHandle: return arg_handle_; case kOffThreadTransferHandle: return arg_transfer_handle_.ToHandle(); case kNone: return isolate->factory()->undefined_string(); case kConstCharString: return isolate->factory() ->NewStringFromUtf8(CStrVector(char_arg_), AllocationType::kOld) .ToHandleChecked(); case kAstRawString: UNREACHABLE(); } } MessageLocation PendingCompilationErrorHandler::MessageDetails::GetLocation( Handle