diff --git a/common.gypi b/common.gypi index 3e84350395dfe4..33cd361e67a672 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.11', + 'v8_embedder_string': '-node.12', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index f0f1355f590b37..8aaf0912802807 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -2537,29 +2537,6 @@ MaybeLocal ScriptCompiler::CompileModule( return ToApiHandle(i_isolate->factory()->NewSourceTextModule(shared)); } -namespace { -bool IsIdentifier(i::Isolate* isolate, i::Handle string) { - string = i::String::Flatten(isolate, string); - const int length = string->length(); - if (length == 0) return false; - if (!i::IsIdentifierStart(string->Get(0))) return false; - i::DisallowGarbageCollection no_gc; - i::String::FlatContent flat = string->GetFlatContent(no_gc); - if (flat.IsOneByte()) { - auto vector = flat.ToOneByteVector(); - for (int i = 1; i < length; i++) { - if (!i::IsIdentifierPart(vector[i])) return false; - } - } else { - auto vector = flat.ToUC16Vector(); - for (int i = 1; i < length; i++) { - if (!i::IsIdentifierPart(vector[i])) return false; - } - } - return true; -} -} // namespace - // static V8_WARN_UNUSED_RESULT MaybeLocal ScriptCompiler::CompileFunction( Local context, Source* source, size_t arguments_count, @@ -2608,7 +2585,7 @@ MaybeLocal ScriptCompiler::CompileFunctionInternal( isolate->factory()->NewFixedArray(static_cast(arguments_count)); for (int i = 0; i < static_cast(arguments_count); i++) { i::Handle argument = Utils::OpenHandle(*arguments[i]); - if (!IsIdentifier(isolate, argument)) return Local(); + if (!i::String::IsIdentifier(isolate, argument)) return Local(); arguments_list->set(i, *argument); } diff --git a/deps/v8/src/objects/call-site-info.cc b/deps/v8/src/objects/call-site-info.cc index 75abced310aa13..decd46dda14e18 100644 --- a/deps/v8/src/objects/call-site-info.cc +++ b/deps/v8/src/objects/call-site-info.cc @@ -629,12 +629,6 @@ void AppendFileLocation(Isolate* isolate, Handle frame, } } -int StringIndexOf(Isolate* isolate, Handle subject, - Handle pattern) { - if (pattern->length() > subject->length()) return -1; - return String::IndexOf(isolate, subject, pattern, 0); -} - // Returns true iff // 1. the subject ends with '.' + pattern, or // 2. subject == pattern. @@ -676,9 +670,8 @@ void AppendMethodCall(Isolate* isolate, Handle frame, Handle function_string = Handle::cast(function_name); if (IsNonEmptyString(type_name)) { Handle type_string = Handle::cast(type_name); - bool starts_with_type_name = - (StringIndexOf(isolate, function_string, type_string) == 0); - if (!starts_with_type_name) { + if (String::IsIdentifier(isolate, function_string) && + !String::Equals(isolate, function_string, type_string)) { builder->AppendString(type_string); builder->AppendCharacter('.'); } diff --git a/deps/v8/src/objects/string.cc b/deps/v8/src/objects/string.cc index ce72d499d4f48b..1670a8114cab0b 100644 --- a/deps/v8/src/objects/string.cc +++ b/deps/v8/src/objects/string.cc @@ -1558,6 +1558,35 @@ bool String::HasOneBytePrefix(base::Vector str) { namespace { +template +bool IsIdentifierVector(const base::Vector& vec) { + if (vec.empty()) { + return false; + } + if (!IsIdentifierStart(vec[0])) { + return false; + } + for (size_t i = 1; i < vec.size(); ++i) { + if (!IsIdentifierPart(vec[i])) { + return false; + } + } + return true; +} + +} // namespace + +// static +bool String::IsIdentifier(Isolate* isolate, Handle str) { + str = String::Flatten(isolate, str); + DisallowGarbageCollection no_gc; + String::FlatContent flat = str->GetFlatContent(no_gc); + return flat.IsOneByte() ? IsIdentifierVector(flat.ToOneByteVector()) + : IsIdentifierVector(flat.ToUC16Vector()); +} + +namespace { + template uint32_t HashString(String string, size_t start, int length, uint64_t seed, PtrComprCageBase cage_base, diff --git a/deps/v8/src/objects/string.h b/deps/v8/src/objects/string.h index 838ef304d35606..e060e1f26244e5 100644 --- a/deps/v8/src/objects/string.h +++ b/deps/v8/src/objects/string.h @@ -391,6 +391,9 @@ class String : public TorqueGeneratedString { V8_EXPORT_PRIVATE bool HasOneBytePrefix(base::Vector str); V8_EXPORT_PRIVATE inline bool IsOneByteEqualTo(base::Vector str); + // Returns true if the |str| is a valid ECMAScript identifier. + static bool IsIdentifier(Isolate* isolate, Handle str); + // Return a UTF8 representation of the string. The string is null // terminated but may optionally contain nulls. Length is returned // in length_output if length_output is not a null pointer The string diff --git a/deps/v8/test/message/fail/class-fields-static-throw.js b/deps/v8/test/message/fail/class-fields-static-throw.js index 5de3fa744b4615..602e707634bbcd 100644 --- a/deps/v8/test/message/fail/class-fields-static-throw.js +++ b/deps/v8/test/message/fail/class-fields-static-throw.js @@ -1,8 +1,6 @@ // Copyright 2018 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. -// -// TODO(gsathya): Remove 'Function' from stack trace. class X { static x = foo(); diff --git a/deps/v8/test/message/fail/class-fields-static-throw.out b/deps/v8/test/message/fail/class-fields-static-throw.out index 417f4c00ead6f3..a93a7bcc60990e 100644 --- a/deps/v8/test/message/fail/class-fields-static-throw.out +++ b/deps/v8/test/message/fail/class-fields-static-throw.out @@ -1,6 +1,6 @@ -*%(basename)s:8: ReferenceError: foo is not defined +*%(basename)s:6: ReferenceError: foo is not defined static x = foo(); ^ ReferenceError: foo is not defined - at Function. (*%(basename)s:8:14) + at (*%(basename)s:6:14) at *%(basename)s:1:1 diff --git a/deps/v8/test/message/fail/class-fields-throw.out b/deps/v8/test/message/fail/class-fields-throw.out index b7bce52a7fd332..3129f326b7671a 100644 --- a/deps/v8/test/message/fail/class-fields-throw.out +++ b/deps/v8/test/message/fail/class-fields-throw.out @@ -2,6 +2,6 @@ x = foo(); ^ ReferenceError: foo is not defined - at X. (*%(basename)s:6:7) + at (*%(basename)s:6:7) at new X (*%(basename)s:5:1) - at *%(basename)s:9:1 \ No newline at end of file + at *%(basename)s:9:1 diff --git a/deps/v8/test/message/fail/class-private-field-reinitialization.out b/deps/v8/test/message/fail/class-private-field-reinitialization.out index 6e8024f587b746..91aab86c99766f 100644 --- a/deps/v8/test/message/fail/class-private-field-reinitialization.out +++ b/deps/v8/test/message/fail/class-private-field-reinitialization.out @@ -2,6 +2,6 @@ class B extends A { #x; } ^ TypeError: Cannot initialize #x twice on the same object - at Object. (*%(basename)s:7:21) + at (*%(basename)s:7:21) at new B (*%(basename)s:7:1) at *%(basename)s:10:1 diff --git a/deps/v8/test/message/fail/stack-trace-method-name-configured.js b/deps/v8/test/message/fail/stack-trace-method-name-configured.js new file mode 100644 index 00000000000000..200ff246ee55c2 --- /dev/null +++ b/deps/v8/test/message/fail/stack-trace-method-name-configured.js @@ -0,0 +1,12 @@ +// Copyright 2022 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. + +// Check that the user configured method name ('SomeClass.someMethod') is used +// as-is in error.stack output without prepending the inferred type name ('A'). +const A = function() {}; +A.prototype.a = function() { + throw new Error; +}; +Object.defineProperty(A.prototype.a, 'name', {value: 'SomeClass.someMethod'}); +(new A).a(); diff --git a/deps/v8/test/message/fail/stack-trace-method-name-configured.out b/deps/v8/test/message/fail/stack-trace-method-name-configured.out new file mode 100644 index 00000000000000..cfbea6827de024 --- /dev/null +++ b/deps/v8/test/message/fail/stack-trace-method-name-configured.out @@ -0,0 +1,11 @@ +# Copyright 2022 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. + +*%(basename)s:9: Error + throw new Error; + ^ +Error + at SomeClass.someMethod [as a] (*%(basename)s:9:9) + at *%(basename)s:12:9 + diff --git a/deps/v8/test/message/fail/stack-trace-method-name-renaming.js b/deps/v8/test/message/fail/stack-trace-method-name-renaming.js new file mode 100644 index 00000000000000..0360858636b046 --- /dev/null +++ b/deps/v8/test/message/fail/stack-trace-method-name-renaming.js @@ -0,0 +1,12 @@ +// Copyright 2022 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. + +// Check that the dynamic type name ('A') is not prepended to the inferred +// method name ('C.a') in error.stack output. +const A = function() {}; +const C = A; +C.prototype.a = function() { + throw new Error; +}; +(new A).a(); diff --git a/deps/v8/test/message/fail/stack-trace-method-name-renaming.out b/deps/v8/test/message/fail/stack-trace-method-name-renaming.out new file mode 100644 index 00000000000000..8cf31e4a366c36 --- /dev/null +++ b/deps/v8/test/message/fail/stack-trace-method-name-renaming.out @@ -0,0 +1,11 @@ +# Copyright 2022 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. + +*%(basename)s:10: Error + throw new Error; + ^ +Error + at C.a (*%(basename)s:10:9) + at *%(basename)s:12:9 + diff --git a/deps/v8/test/mjsunit/stack-traces-class-fields.js b/deps/v8/test/mjsunit/stack-traces-class-fields.js index 03edb811881333..1c2a954fdfe132 100644 --- a/deps/v8/test/mjsunit/stack-traces-class-fields.js +++ b/deps/v8/test/mjsunit/stack-traces-class-fields.js @@ -75,16 +75,13 @@ function testClassInstantiation() { // ReferenceError: FAIL is not defined // at thrower -// at X. +// at // at new X // at testClassInstantiation // at testTrace testTrace( - "during class instantiation", - testClassInstantiation, - ["thrower", "X.", "new X"], - ["anonymous"] -); + 'during class instantiation', testClassInstantiation, + ['thrower', '', 'new X'], ['anonymous']); function testClassInstantiationWithSuper() { class Base {} @@ -98,16 +95,14 @@ function testClassInstantiationWithSuper() { // ReferenceError: FAIL is not defined // at thrower -// at X. +// at // at new X // at testClassInstantiation // at testTrace testTrace( - "during class instantiation with super", - testClassInstantiationWithSuper, - ["thrower", "X.", "new X"], - ["Base", "anonymous"] -); + 'during class instantiation with super', testClassInstantiationWithSuper, + ['thrower', '', 'new X'], + ['Base', 'anonymous']); function testClassInstantiationWithSuper2() { class Base {} @@ -124,16 +119,14 @@ function testClassInstantiationWithSuper2() { // ReferenceError: FAIL is not defined // at thrower -// at X. +// at // at new X // at testClassInstantiation // at testTrace testTrace( - "during class instantiation with super2", - testClassInstantiationWithSuper2, - ["thrower", "X.", "new X"], - ["Base", "anonymous"] -); + 'during class instantiation with super2', testClassInstantiationWithSuper2, + ['thrower', '', 'new X'], + ['Base', 'anonymous']); function testClassInstantiationWithSuper3() { class Base { @@ -151,17 +144,15 @@ function testClassInstantiationWithSuper3() { // ReferenceError: FAIL is not defined // at thrower -// at X. +// at // at new Base // at new X // at testClassInstantiationWithSuper3 // at testTrace testTrace( - "during class instantiation with super3", - testClassInstantiationWithSuper3, - ["thrower", "X.", "new Base", "new X"], - ["anonymous"] -); + 'during class instantiation with super3', testClassInstantiationWithSuper3, + ['thrower', '', 'new Base', 'new X'], + ['anonymous']); function testClassFieldCall() { class X {