// 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/handles/handles.h" #include "src/heap/local-heap-inl.h" #include "src/objects/objects-inl.h" namespace v8 { namespace internal { void PendingCompilationErrorHandler::MessageDetails::SetString( Handle string, Isolate* isolate) { DCHECK_NE(type_, kMainThreadHandle); type_ = kMainThreadHandle; arg_handle_ = string; } void PendingCompilationErrorHandler::MessageDetails::SetString( Handle string, LocalIsolate* isolate) { DCHECK_NE(type_, kMainThreadHandle); type_ = kMainThreadHandle; arg_handle_ = isolate->heap()->NewPersistentHandle(string); } template void PendingCompilationErrorHandler::MessageDetails::Prepare( IsolateT* 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: // The message details might already be prepared, so skip them if this is // the case. return; } } Handle PendingCompilationErrorHandler::MessageDetails::ArgumentString( Isolate* isolate) const { switch (type_) { case kMainThreadHandle: return arg_handle_; case kNone: return isolate->factory()->undefined_string(); case kConstCharString: return isolate->factory() ->NewStringFromUtf8(base::CStrVector(char_arg_), AllocationType::kOld) .ToHandleChecked(); case kAstRawString: UNREACHABLE(); } } MessageLocation PendingCompilationErrorHandler::MessageDetails::GetLocation( Handle