From 8455b98be39d62c3021b100a547e3a1080571048 Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Mon, 30 Aug 2021 09:49:07 +0200 Subject: [PATCH] [parsing] Refactor MessageDetails arguments .. to consistently support more than a single argument. Each argument is now a tagged union that may contain an AST string, a C string, or a JS string handle. Change-Id: Iac8e40b717dea95a2bc2903449dab56c181702d6 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3122086 Commit-Queue: Jakob Gruber Auto-Submit: Jakob Gruber Reviewed-by: Leszek Swirski Cr-Commit-Position: refs/heads/main@{#76559} --- .../pending-compilation-error-handler.cc | 73 +++++++++---------- .../pending-compilation-error-handler.h | 71 ++++++++++-------- 2 files changed, 76 insertions(+), 68 deletions(-) diff --git a/src/parsing/pending-compilation-error-handler.cc b/src/parsing/pending-compilation-error-handler.cc index 9b4e1ca694..4756628ca7 100644 --- a/src/parsing/pending-compilation-error-handler.cc +++ b/src/parsing/pending-compilation-error-handler.cc @@ -19,49 +19,52 @@ namespace internal { void PendingCompilationErrorHandler::MessageDetails::SetString( Handle string, Isolate* isolate) { - DCHECK_NE(arg0_type_, kMainThreadHandle); - arg0_type_ = kMainThreadHandle; - arg0_handle_ = string; + 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(arg0_type_, kMainThreadHandle); - arg0_type_ = kMainThreadHandle; - arg0_handle_ = isolate->heap()->NewPersistentHandle(string); + 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) { - switch (arg0_type_) { - case kAstRawString: - return SetString(arg0_->string(), 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 Arg0String(isolate). - // TODO(leszeks): We don't actually have to transfer this string, since - // it's a root. - return; + 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; + case kMainThreadHandle: + // The message details might already be prepared, so skip them if this + // is the case. + return; + } } } -Handle PendingCompilationErrorHandler::MessageDetails::Arg0String( - Isolate* isolate) const { - switch (arg0_type_) { +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 arg0_handle_; + return args_[index].js_string; case kNone: - return isolate->factory()->undefined_string(); + return Handle::null(); case kConstCharString: return isolate->factory() - ->NewStringFromUtf8(base::CStrVector(char_arg0_), + ->NewStringFromUtf8(base::CStrVector(args_[index].c_string), AllocationType::kOld) .ToHandleChecked(); case kAstRawString: @@ -69,14 +72,6 @@ Handle PendingCompilationErrorHandler::MessageDetails::Arg0String( } } -Handle PendingCompilationErrorHandler::MessageDetails::Arg1String( - Isolate* isolate) const { - if (arg1_ == nullptr) return Handle::null(); - return isolate->factory() - ->NewStringFromUtf8(base::CStrVector(arg1_), AllocationType::kOld) - .ToHandleChecked(); -} - MessageLocation PendingCompilationErrorHandler::MessageDetails::GetLocation( Handle