From 58c70344a231289c25a90d116a9889a71cf638e0 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 1 Dec 2023 20:02:32 +0100 Subject: [PATCH] deps: V8: cherry-pick 705e374124ae Original commit message: [symbol-as-weakmap-key] Ship the proposal I2S with 3 LGTMs: https://groups.google.com/a/chromium.org/g/blink-dev/c/E6pDZP_TiBA/m/ZcXLwiz8AAAJ Bug: v8:12947 Change-Id: Ibce4abc8b0610afb2041d44cc9ed136db8b62c0d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4004610 Commit-Queue: Shu-yu Guo Reviewed-by: Camillo Bruni Cr-Commit-Position: refs/heads/main@{#84128} Refs: https://github.com/v8/v8/commit/705e374124ae026206e90519356cd980a1a515ba PR-URL: https://github.com/nodejs/node/pull/51004 Reviewed-By: Chengzhong Wu --- common.gypi | 2 +- deps/v8/src/builtins/builtins-collections-gen.cc | 2 +- deps/v8/src/builtins/builtins-weak-refs.cc | 10 +++------- deps/v8/src/builtins/finalization-registry.tq | 2 +- deps/v8/src/builtins/weak-ref.tq | 2 +- deps/v8/src/codegen/code-stub-assembler.h | 6 ------ deps/v8/src/codegen/external-reference.cc | 5 ----- deps/v8/src/codegen/external-reference.h | 2 -- deps/v8/src/flags/flag-definitions.h | 3 +-- deps/v8/src/init/bootstrapper.cc | 1 - deps/v8/src/objects/objects-inl.h | 7 ++----- .../debugger/object-preview-internal-properties.js | 2 -- deps/v8/test/mjsunit/es6/collections.js | 1 - .../mjsunit/harmony/regress/regress-crbug-1372500.js | 2 +- deps/v8/test/mjsunit/harmony/symbol-as-weakmap-key.js | 2 +- deps/v8/test/mjsunit/harmony/weakrefs/basics.js | 3 --- .../harmony/weakrefs/symbol-as-weakref-target-gc.js | 2 +- .../harmony/weakrefs/symbol-as-weakref-target.js | 2 -- 18 files changed, 13 insertions(+), 43 deletions(-) diff --git a/common.gypi b/common.gypi index 58fef6b3f1726a..f5ceda2eec3bda 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.34', + 'v8_embedder_string': '-node.35', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/builtins/builtins-collections-gen.cc b/deps/v8/src/builtins/builtins-collections-gen.cc index 19d77fa261ec61..d83038f7f65c40 100644 --- a/deps/v8/src/builtins/builtins-collections-gen.cc +++ b/deps/v8/src/builtins/builtins-collections-gen.cc @@ -399,6 +399,7 @@ TNode BaseCollectionsAssembler::EstimatedInitialSize( [=] { return IntPtrConstant(0); }); } +// https://tc39.es/ecma262/#sec-canbeheldweakly void BaseCollectionsAssembler::GotoIfCannotBeHeldWeakly( const TNode obj, Label* if_cannot_be_held_weakly) { Label check_symbol_key(this); @@ -411,7 +412,6 @@ void BaseCollectionsAssembler::GotoIfCannotBeHeldWeakly( GotoIf(IsJSSharedStructInstanceType(instance_type), if_cannot_be_held_weakly); Goto(&end); Bind(&check_symbol_key); - GotoIfNot(HasHarmonySymbolAsWeakmapKeyFlag(), if_cannot_be_held_weakly); GotoIfNot(IsSymbolInstanceType(instance_type), if_cannot_be_held_weakly); TNode flags = LoadSymbolFlags(CAST(obj)); GotoIf(Word32And(flags, Symbol::IsInPublicSymbolTableBit::kMask), diff --git a/deps/v8/src/builtins/builtins-weak-refs.cc b/deps/v8/src/builtins/builtins-weak-refs.cc index a944159f247bec..eef9de1cb1d66f 100644 --- a/deps/v8/src/builtins/builtins-weak-refs.cc +++ b/deps/v8/src/builtins/builtins-weak-refs.cc @@ -9,23 +9,19 @@ namespace v8 { namespace internal { -// https://tc39.es/proposal-symbols-as-weakmap-keys/#sec-finalization-registry.prototype.unregister +// https://tc39.es/ecma262/#sec-finalization-registry.prototype.unregister BUILTIN(FinalizationRegistryUnregister) { HandleScope scope(isolate); const char* method_name = "FinalizationRegistry.prototype.unregister"; // 1. Let finalizationGroup be the this value. // - // 2. If Type(finalizationGroup) is not Object, throw a TypeError - // exception. - // - // 3. If finalizationGroup does not have a [[Cells]] internal slot, - // throw a TypeError exception. + // 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]). CHECK_RECEIVER(JSFinalizationRegistry, finalization_registry, method_name); Handle unregister_token = args.atOrUndefined(isolate, 1); - // 4. If CanBeHeldWeakly(unregisterToken) is false, throw a TypeError + // 3. If CanBeHeldWeakly(unregisterToken) is false, throw a TypeError // exception. if (!unregister_token->CanBeHeldWeakly()) { THROW_NEW_ERROR_RETURN_FAILURE( diff --git a/deps/v8/src/builtins/finalization-registry.tq b/deps/v8/src/builtins/finalization-registry.tq index 4e4b4be068669f..c4e7f038ade07f 100644 --- a/deps/v8/src/builtins/finalization-registry.tq +++ b/deps/v8/src/builtins/finalization-registry.tq @@ -129,7 +129,7 @@ FinalizationRegistryConstructor( return finalizationRegistry; } -// https://tc39.es/proposal-symbols-as-weakmap-keys/#sec-finalization-registry.prototype.register +// https://tc39.es/ecma262/#sec-finalization-registry.prototype.register transitioning javascript builtin FinalizationRegistryRegister( js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { diff --git a/deps/v8/src/builtins/weak-ref.tq b/deps/v8/src/builtins/weak-ref.tq index 051831698534ce..ea0842c1ac2dd2 100644 --- a/deps/v8/src/builtins/weak-ref.tq +++ b/deps/v8/src/builtins/weak-ref.tq @@ -13,7 +13,7 @@ extern runtime JSWeakRefAddToKeptObjects(implicit context: Context)( namespace weakref { -// https://tc39.es/proposal-symbols-as-weakmap-keys/#sec-weak-ref-target +// https://tc39.es/ecma262/#sec-weak-ref-target transitioning javascript builtin WeakRefConstructor( js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny, diff --git a/deps/v8/src/codegen/code-stub-assembler.h b/deps/v8/src/codegen/code-stub-assembler.h index a1c8816c54b90b..bccdc34b746bdb 100644 --- a/deps/v8/src/codegen/code-stub-assembler.h +++ b/deps/v8/src/codegen/code-stub-assembler.h @@ -2679,12 +2679,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ExternalReference::address_of_shared_string_table_flag()); } - TNode HasHarmonySymbolAsWeakmapKeyFlag() { - return LoadRuntimeFlag( - ExternalReference:: - address_of_FLAG_harmony_symbol_as_weakmap_key()); - } - // True iff |object| is a Smi or a HeapNumber or a BigInt. TNode IsNumeric(TNode object); diff --git a/deps/v8/src/codegen/external-reference.cc b/deps/v8/src/codegen/external-reference.cc index 686a91da6dc4b5..6d206663ba86b7 100644 --- a/deps/v8/src/codegen/external-reference.cc +++ b/deps/v8/src/codegen/external-reference.cc @@ -550,11 +550,6 @@ ExternalReference::address_of_mock_arraybuffer_allocator_flag() { return ExternalReference(&FLAG_mock_arraybuffer_allocator); } -ExternalReference -ExternalReference::address_of_FLAG_harmony_symbol_as_weakmap_key() { - return ExternalReference(&FLAG_harmony_symbol_as_weakmap_key); -} - ExternalReference ExternalReference::address_of_builtin_subclassing_flag() { return ExternalReference(&FLAG_builtin_subclassing); } diff --git a/deps/v8/src/codegen/external-reference.h b/deps/v8/src/codegen/external-reference.h index 636c528dabfe41..7715aa6a816f33 100644 --- a/deps/v8/src/codegen/external-reference.h +++ b/deps/v8/src/codegen/external-reference.h @@ -92,8 +92,6 @@ class StatsCounter; #define EXTERNAL_REFERENCE_LIST(V) \ V(abort_with_reason, "abort_with_reason") \ - V(address_of_FLAG_harmony_symbol_as_weakmap_key, \ - "FLAG_harmony_symbol_as_weakmap_key") \ V(address_of_builtin_subclassing_flag, "FLAG_builtin_subclassing") \ V(address_of_double_abs_constant, "double_absolute_constant") \ V(address_of_double_neg_constant, "double_negate_constant") \ diff --git a/deps/v8/src/flags/flag-definitions.h b/deps/v8/src/flags/flag-definitions.h index 4627f96c07ed60..c101c5730c98f2 100644 --- a/deps/v8/src/flags/flag-definitions.h +++ b/deps/v8/src/flags/flag-definitions.h @@ -319,8 +319,7 @@ DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features") // Features that are complete (but still behind the --harmony flag). #define HARMONY_STAGED_BASE(V) \ - V(harmony_array_grouping, "harmony array grouping") \ - V(harmony_symbol_as_weakmap_key, "harmony symbols as weakmap keys") + V(harmony_array_grouping, "harmony array grouping") #ifdef V8_INTL_SUPPORT #define HARMONY_STAGED(V) \ diff --git a/deps/v8/src/init/bootstrapper.cc b/deps/v8/src/init/bootstrapper.cc index fd75d5faa317de..d4c4122c22f4d7 100644 --- a/deps/v8/src/init/bootstrapper.cc +++ b/deps/v8/src/init/bootstrapper.cc @@ -4484,7 +4484,6 @@ void Genesis::InitializeConsole(Handle extras_binding) { EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_assertions) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_private_brand_checks) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_class_static_blocks) -EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_symbol_as_weakmap_key) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_error_cause) #ifdef V8_INTL_SUPPORT diff --git a/deps/v8/src/objects/objects-inl.h b/deps/v8/src/objects/objects-inl.h index 6a4f976029662c..a1f73d23a9ca86 100644 --- a/deps/v8/src/objects/objects-inl.h +++ b/deps/v8/src/objects/objects-inl.h @@ -1206,7 +1206,7 @@ MaybeHandle Object::Share(Isolate* isolate, Handle value, throw_if_cannot_be_shared); } -// https://tc39.es/proposal-symbols-as-weakmap-keys/#sec-canbeheldweakly-abstract-operation +// https://tc39.es/ecma262/#sec-canbeheldweakly bool Object::CanBeHeldWeakly() const { if (IsJSReceiver()) { // TODO(v8:12547) Shared structs and arrays should only be able to point @@ -1217,10 +1217,7 @@ bool Object::CanBeHeldWeakly() const { } return true; } - if (FLAG_harmony_symbol_as_weakmap_key) { - return IsSymbol() && !Symbol::cast(*this).is_in_public_symbol_table(); - } - return false; + return IsSymbol() && !Symbol::cast(*this).is_in_public_symbol_table(); } Handle ObjectHashTableShape::AsHandle(Handle key) { diff --git a/deps/v8/test/inspector/debugger/object-preview-internal-properties.js b/deps/v8/test/inspector/debugger/object-preview-internal-properties.js index d2b3a7816339e9..026c4bc1c364c9 100644 --- a/deps/v8/test/inspector/debugger/object-preview-internal-properties.js +++ b/deps/v8/test/inspector/debugger/object-preview-internal-properties.js @@ -1,8 +1,6 @@ // Copyright 2016 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. -// -// Flags: --harmony-symbol-as-weakmap-key let {session, contextGroup, Protocol} = InspectorTest.start("Check internal properties reported in object preview."); diff --git a/deps/v8/test/mjsunit/es6/collections.js b/deps/v8/test/mjsunit/es6/collections.js index feae6294392365..2b608e1f5da10d 100644 --- a/deps/v8/test/mjsunit/es6/collections.js +++ b/deps/v8/test/mjsunit/es6/collections.js @@ -77,7 +77,6 @@ function TestInvalidCalls(m) { assertThrows(function () { m.set(null, 0) }, TypeError); assertThrows(function () { m.set(0, 0) }, TypeError); assertThrows(function () { m.set('a-key', 0) }, TypeError); - assertThrows(function () { m.set(Symbol(), 0) }, TypeError); } TestInvalidCalls(new WeakMap); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-1372500.js b/deps/v8/test/mjsunit/harmony/regress/regress-crbug-1372500.js index 6264570fdd3bd7..bccca0b40761fe 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-1372500.js +++ b/deps/v8/test/mjsunit/harmony/regress/regress-crbug-1372500.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-symbol-as-weakmap-key --expose-gc +// Flags: --expose-gc // Register an object in a FinalizationRegistry with a Symbol as the unregister // token. diff --git a/deps/v8/test/mjsunit/harmony/symbol-as-weakmap-key.js b/deps/v8/test/mjsunit/harmony/symbol-as-weakmap-key.js index 284e78b30196b7..9070b9309a5aa1 100644 --- a/deps/v8/test/mjsunit/harmony/symbol-as-weakmap-key.js +++ b/deps/v8/test/mjsunit/harmony/symbol-as-weakmap-key.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-symbol-as-weakmap-key --expose-gc --allow-natives-syntax --noincremental-marking +// Flags: --expose-gc --allow-natives-syntax --noincremental-marking (function TestWeakMapWithNonRegisteredSymbolKey() { const key = Symbol('123'); diff --git a/deps/v8/test/mjsunit/harmony/weakrefs/basics.js b/deps/v8/test/mjsunit/harmony/weakrefs/basics.js index 7628c641bc7984..018dc6d5ab1def 100644 --- a/deps/v8/test/mjsunit/harmony/weakrefs/basics.js +++ b/deps/v8/test/mjsunit/harmony/weakrefs/basics.js @@ -51,7 +51,6 @@ assertThrows(() => fg.register(1, "holdings"), TypeError, message); assertThrows(() => fg.register(false, "holdings"), TypeError, message); assertThrows(() => fg.register("foo", "holdings"), TypeError, message); - assertThrows(() => fg.register(Symbol(), "holdings"), TypeError, message); assertThrows(() => fg.register(null, "holdings"), TypeError, message); assertThrows(() => fg.register(undefined, "holdings"), TypeError, message); })(); @@ -97,7 +96,6 @@ assertThrows(() => fg.unregister(1), TypeError); assertThrows(() => fg.unregister(1n), TypeError); assertThrows(() => fg.unregister('one'), TypeError); - assertThrows(() => fg.unregister(Symbol()), TypeError); assertThrows(() => fg.unregister(true), TypeError); assertThrows(() => fg.unregister(false), TypeError); assertThrows(() => fg.unregister(undefined), TypeError); @@ -121,7 +119,6 @@ assertThrows(() => new WeakRef(1), TypeError, message); assertThrows(() => new WeakRef(false), TypeError, message); assertThrows(() => new WeakRef("foo"), TypeError, message); - assertThrows(() => new WeakRef(Symbol()), TypeError, message); assertThrows(() => new WeakRef(null), TypeError, message); assertThrows(() => new WeakRef(undefined), TypeError, message); })(); diff --git a/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target-gc.js b/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target-gc.js index 561bf4f058bdd7..3f663d2b0e0f52 100644 --- a/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target-gc.js +++ b/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target-gc.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-symbol-as-weakmap-key --expose-gc --noincremental-marking +// Flags: --expose-gc --noincremental-marking (function TestWeakRefWithSymbolGC() { let weakRef; diff --git a/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target.js b/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target.js index 1dc874ed83b3da..a969f388717a50 100644 --- a/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target.js +++ b/deps/v8/test/mjsunit/harmony/weakrefs/symbol-as-weakref-target.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-symbol-as-weakmap-key - (function TestRegisterWithSymbolTarget() { const fg = new FinalizationRegistry(() => { }); fg.register(Symbol('123'), 'holdings');