// 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(args_[0].type, kMainThreadHandle); args_[0].type = kMainThreadHandle; args_[0].js_string = string; } void PendingCompilationErrorHandler::MessageDetails::SetString( Handle string, LocalIsolate* isolate) { DCHECK_NE(args_[0].type, kMainThreadHandle); args_[0].type = kMainThreadHandle; args_[0].js_string = isolate->heap()->NewPersistentHandle(string); } template void PendingCompilationErrorHandler::MessageDetails::Prepare( IsolateT* isolate) { for (int i = 0; i < kMaxArgumentCount; i++) { switch (args_[i].type) { case kAstRawString: return SetString(args_[i].ast_string->string(), isolate); case kNone: case kConstCharString: // We can delay allocation until ArgString(isolate). return; case kMainThreadHandle: // The message details might already be prepared, so skip them if this // is the case. return; } } } Handle PendingCompilationErrorHandler::MessageDetails::ArgString( Isolate* isolate, int index) const { // `index` may be >= argc; in that case we return a default value to pass on // elsewhere. DCHECK_LT(index, kMaxArgumentCount); switch (args_[index].type) { case kMainThreadHandle: return args_[index].js_string; case kNone: return Handle::null(); case kConstCharString: return isolate->factory() ->NewStringFromUtf8(base::CStrVector(args_[index].c_string), AllocationType::kOld) .ToHandleChecked(); case kAstRawString: UNREACHABLE(); } } MessageLocation PendingCompilationErrorHandler::MessageDetails::GetLocation( Handle