diff options
Diffstat (limited to 'deps/v8/src/parsing/pending-compilation-error-handler.cc')
-rw-r--r-- | deps/v8/src/parsing/pending-compilation-error-handler.cc | 111 |
1 files changed, 86 insertions, 25 deletions
diff --git a/deps/v8/src/parsing/pending-compilation-error-handler.cc b/deps/v8/src/parsing/pending-compilation-error-handler.cc index 80d201d13f7..f131b7ad8e6 100644 --- a/deps/v8/src/parsing/pending-compilation-error-handler.cc +++ b/deps/v8/src/parsing/pending-compilation-error-handler.cc @@ -5,24 +5,68 @@ #include "src/parsing/pending-compilation-error-handler.h" #include "src/ast/ast-value-factory.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> string, Isolate* isolate) { + DCHECK_NE(type_, kMainThreadHandle); + DCHECK_NE(type_, kOffThreadTransferHandle); + type_ = kMainThreadHandle; + arg_handle_ = string; +} + +void PendingCompilationErrorHandler::MessageDetails::SetString( + Handle<String> string, OffThreadIsolate* isolate) { + DCHECK_NE(type_, kMainThreadHandle); + DCHECK_NE(type_, kOffThreadTransferHandle); + type_ = kOffThreadTransferHandle; + arg_transfer_handle_ = isolate->TransferHandle(string); +} + +template <typename LocalIsolate> +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<String> PendingCompilationErrorHandler::MessageDetails::ArgumentString( Isolate* isolate) const { - if (arg_ != nullptr) return arg_->string(); - if (char_arg_ != nullptr) { - return isolate->factory() - ->NewStringFromUtf8(CStrVector(char_arg_)) - .ToHandleChecked(); + 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(); } - return isolate->factory()->undefined_string(); } MessageLocation PendingCompilationErrorHandler::MessageDetails::GetLocation( @@ -37,8 +81,7 @@ void PendingCompilationErrorHandler::ReportMessageAt(int start_position, if (has_pending_error_) return; has_pending_error_ = true; - error_details_ = - MessageDetails(start_position, end_position, message, nullptr, arg); + error_details_ = MessageDetails(start_position, end_position, message, arg); } void PendingCompilationErrorHandler::ReportMessageAt(int start_position, @@ -48,8 +91,7 @@ void PendingCompilationErrorHandler::ReportMessageAt(int start_position, if (has_pending_error_) return; has_pending_error_ = true; - error_details_ = - MessageDetails(start_position, end_position, message, arg, nullptr); + error_details_ = MessageDetails(start_position, end_position, message, arg); } void PendingCompilationErrorHandler::ReportWarningAt(int start_position, @@ -57,11 +99,23 @@ void PendingCompilationErrorHandler::ReportWarningAt(int start_position, MessageTemplate message, const char* arg) { warning_messages_.emplace_front( - MessageDetails(start_position, end_position, message, nullptr, arg)); + MessageDetails(start_position, end_position, message, arg)); } -void PendingCompilationErrorHandler::ReportWarnings(Isolate* isolate, - Handle<Script> script) { +template <typename LocalIsolate> +void PendingCompilationErrorHandler::PrepareWarnings(LocalIsolate* isolate) { + DCHECK(!has_pending_error()); + + for (MessageDetails& warning : warning_messages_) { + warning.Prepare(isolate); + } +} +template void PendingCompilationErrorHandler::PrepareWarnings(Isolate* isolate); +template void PendingCompilationErrorHandler::PrepareWarnings( + OffThreadIsolate* isolate); + +void PendingCompilationErrorHandler::ReportWarnings( + Isolate* isolate, Handle<Script> script) const { DCHECK(!has_pending_error()); for (const MessageDetails& warning : warning_messages_) { @@ -75,27 +129,33 @@ void PendingCompilationErrorHandler::ReportWarnings(Isolate* isolate, } } -void PendingCompilationErrorHandler::ReportWarnings(OffThreadIsolate* isolate, - Handle<Script> script) { - // TODO(leszeks): Do nothing, re-report on the main thread. - UNREACHABLE(); +template <typename LocalIsolate> +void PendingCompilationErrorHandler::PrepareErrors( + LocalIsolate* isolate, AstValueFactory* ast_value_factory) { + if (stack_overflow()) return; + + DCHECK(has_pending_error()); + // Internalize ast values for throwing the pending error. + ast_value_factory->Internalize(isolate); + error_details_.Prepare(isolate); } +template void PendingCompilationErrorHandler::PrepareErrors( + Isolate* isolate, AstValueFactory* ast_value_factory); +template void PendingCompilationErrorHandler::PrepareErrors( + OffThreadIsolate* isolate, AstValueFactory* ast_value_factory); -void PendingCompilationErrorHandler::ReportErrors( - Isolate* isolate, Handle<Script> script, - AstValueFactory* ast_value_factory) { +void PendingCompilationErrorHandler::ReportErrors(Isolate* isolate, + Handle<Script> script) const { if (stack_overflow()) { isolate->StackOverflow(); } else { DCHECK(has_pending_error()); - // Internalize ast values for throwing the pending error. - ast_value_factory->Internalize(isolate); ThrowPendingError(isolate, script); } } -void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate, - Handle<Script> script) { +void PendingCompilationErrorHandler::ThrowPendingError( + Isolate* isolate, Handle<Script> script) const { if (!has_pending_error_) return; MessageLocation location = error_details_.GetLocation(script); @@ -109,7 +169,8 @@ void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate, } Handle<String> PendingCompilationErrorHandler::FormatErrorMessageForTest( - Isolate* isolate) const { + Isolate* isolate) { + error_details_.Prepare(isolate); return MessageFormatter::Format(isolate, error_details_.message(), error_details_.ArgumentString(isolate)); } |