From 1d00b7856f9071c2c62ad66dbdbfdebff6dc370c Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Fri, 24 Apr 2020 11:07:24 +0200 Subject: [PATCH] [runtime] Fix source location for CallWithSpread with errors Unify error handling for errors in CallWithSpread Bytecode and thus fix source location mismatches. Bug: v8:10378 Change-Id: If224cd34f1306492059dbedd8d2ca5c0feee5658 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2162856 Reviewed-by: Toon Verwaest Commit-Queue: Camillo Bruni Cr-Commit-Position: refs/heads/master@{#67365} --- src/builtins/builtins-call-gen.cc | 16 +++++++++++++--- src/diagnostics/objects-printer.cc | 3 +++ src/execution/isolate.cc | 3 ++- src/execution/messages.cc | 5 ++--- src/execution/messages.h | 4 ++-- src/runtime/runtime-internal.cc | 10 ++++++---- src/runtime/runtime.h | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/builtins/builtins-call-gen.cc b/src/builtins/builtins-call-gen.cc index 1b53e9ca8e..4dafbd3929 100644 --- a/src/builtins/builtins-call-gen.cc +++ b/src/builtins/builtins-call-gen.cc @@ -317,7 +317,9 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructWithSpread( BIND(&if_generic); { Label if_iterator_fn_not_callable(this, Label::kDeferred), - if_iterator_is_null_or_undefined(this, Label::kDeferred); + if_iterator_is_null_or_undefined(this, Label::kDeferred), + throw_spread_error(this, Label::kDeferred); + TVARIABLE(Smi, message_id); GotoIf(IsNullOrUndefined(spread), &if_iterator_is_null_or_undefined); @@ -336,10 +338,18 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructWithSpread( &if_smiorobject, &if_double); BIND(&if_iterator_fn_not_callable); - ThrowTypeError(context, MessageTemplate::kIteratorSymbolNonCallable); + message_id = SmiConstant( + static_cast(MessageTemplate::kIteratorSymbolNonCallable)), + Goto(&throw_spread_error); BIND(&if_iterator_is_null_or_undefined); - CallRuntime(Runtime::kThrowSpreadArgIsNullOrUndefined, context, spread); + message_id = SmiConstant( + static_cast(MessageTemplate::kNotIterableNoSymbolLoad)); + Goto(&throw_spread_error); + + BIND(&throw_spread_error); + CallRuntime(Runtime::kThrowSpreadArgError, context, message_id.value(), + spread); Unreachable(); } diff --git a/src/diagnostics/objects-printer.cc b/src/diagnostics/objects-printer.cc index 2922a7176c..254d3dde35 100644 --- a/src/diagnostics/objects-printer.cc +++ b/src/diagnostics/objects-printer.cc @@ -2241,12 +2241,14 @@ void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT os << "\n - break_points: "; break_points().FixedArrayPrint(os); os << "\n - coverage_info: " << Brief(coverage_info()); + os << "\n"; } void WasmValue::WasmValuePrint(std::ostream& os) { // NOLINT PrintHeader(os, "WasmValue"); os << "\n - value_type: " << value_type(); os << "\n - bytes: " << Brief(bytes()); + os << "\n"; } void StackTraceFrame::StackTraceFramePrint(std::ostream& os) { // NOLINT @@ -2254,6 +2256,7 @@ void StackTraceFrame::StackTraceFramePrint(std::ostream& os) { // NOLINT os << "\n - frame_index: " << frame_index(); os << "\n - id: " << id(); os << "\n - frame_info: " << Brief(frame_info()); + os << "\n"; } void StackFrameInfo::StackFrameInfoPrint(std::ostream& os) { // NOLINT diff --git a/src/execution/isolate.cc b/src/execution/isolate.cc index e4188cc11a..20956f723a 100644 --- a/src/execution/isolate.cc +++ b/src/execution/isolate.cc @@ -622,8 +622,9 @@ class FrameArrayBuilder { if (is_constructor) flags |= FrameArray::kIsConstructor; Handle parameters = isolate_->factory()->empty_fixed_array(); - if (V8_UNLIKELY(FLAG_detailed_error_stack_trace)) + if (V8_UNLIKELY(FLAG_detailed_error_stack_trace)) { parameters = summary.parameters(); + } elements_ = FrameArray::AppendJSFrame( elements_, TheHoleToUndefined(isolate_, summary.receiver()), function, diff --git a/src/execution/messages.cc b/src/execution/messages.cc index 53a1cc51c2..b0b17b1c08 100644 --- a/src/execution/messages.cc +++ b/src/execution/messages.cc @@ -1308,8 +1308,8 @@ Handle ErrorUtils::NewIteratorError(Isolate* isolate, return isolate->factory()->NewTypeError(id, callsite); } -Object ErrorUtils::ThrowSpreadArgIsNullOrUndefinedError(Isolate* isolate, - Handle object) { +Object ErrorUtils::ThrowSpreadArgError(Isolate* isolate, MessageTemplate id, + Handle object) { MessageLocation location; Handle callsite; if (ComputeLocation(isolate, &location)) { @@ -1337,7 +1337,6 @@ Object ErrorUtils::ThrowSpreadArgIsNullOrUndefinedError(Isolate* isolate, } } - MessageTemplate id = MessageTemplate::kNotIterableNoSymbolLoad; Handle exception = isolate->factory()->NewTypeError(id, callsite, object); return isolate->Throw(*exception, &location); diff --git a/src/execution/messages.h b/src/execution/messages.h index f7dcfe9a2b..fc73af669b 100644 --- a/src/execution/messages.h +++ b/src/execution/messages.h @@ -297,8 +297,8 @@ class ErrorUtils : public AllStatic { Handle source); static Handle NewConstructedNonConstructable(Isolate* isolate, Handle source); - static Object ThrowSpreadArgIsNullOrUndefinedError(Isolate* isolate, - Handle object); + static Object ThrowSpreadArgError(Isolate* isolate, MessageTemplate id, + Handle object); static Object ThrowLoadFromNullOrUndefined(Isolate* isolate, Handle object); static Object ThrowLoadFromNullOrUndefined(Isolate* isolate, diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index 7a2a57a833..957a884fb9 100644 --- a/src/runtime/runtime-internal.cc +++ b/src/runtime/runtime-internal.cc @@ -427,11 +427,13 @@ RUNTIME_FUNCTION(Runtime_ThrowIteratorError) { return isolate->Throw(*ErrorUtils::NewIteratorError(isolate, object)); } -RUNTIME_FUNCTION(Runtime_ThrowSpreadArgIsNullOrUndefined) { +RUNTIME_FUNCTION(Runtime_ThrowSpreadArgError) { HandleScope scope(isolate); - DCHECK_EQ(1, args.length()); - CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); - return ErrorUtils::ThrowSpreadArgIsNullOrUndefinedError(isolate, object); + DCHECK_EQ(2, args.length()); + CONVERT_SMI_ARG_CHECKED(message_id_smi, 0); + MessageTemplate message_id = MessageTemplateFromInt(message_id_smi); + CONVERT_ARG_HANDLE_CHECKED(Object, object, 1); + return ErrorUtils::ThrowSpreadArgError(isolate, message_id, object); } RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) { diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 67cec15c27..dc563aef4f 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -239,7 +239,7 @@ namespace internal { F(ThrowInvalidStringLength, 0, 1) \ F(ThrowInvalidTypedArrayAlignment, 2, 1) \ F(ThrowIteratorError, 1, 1) \ - F(ThrowSpreadArgIsNullOrUndefined, 1, 1) \ + F(ThrowSpreadArgError, 2, 1) \ F(ThrowIteratorResultNotAnObject, 1, 1) \ F(ThrowNotConstructor, 1, 1) \ F(ThrowPatternAssignmentNonCoercible, 1, 1) \