Skip to content

Commit

Permalink
deps: V8: cherry-pick 705e374124ae
Browse files Browse the repository at this point in the history
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 <syg@chromium.org>
    Reviewed-by: Camillo Bruni <cbruni@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#84128}

Refs: v8/v8@705e374
PR-URL: #51004
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
joyeecheung authored and richardlau committed Mar 15, 2024
1 parent b0e8889 commit 58c7034
Show file tree
Hide file tree
Showing 18 changed files with 13 additions and 43 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####

Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/builtins/builtins-collections-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ TNode<IntPtrT> BaseCollectionsAssembler::EstimatedInitialSize(
[=] { return IntPtrConstant(0); });
}

// https://tc39.es/ecma262/#sec-canbeheldweakly
void BaseCollectionsAssembler::GotoIfCannotBeHeldWeakly(
const TNode<Object> obj, Label* if_cannot_be_held_weakly) {
Label check_symbol_key(this);
Expand All @@ -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<Uint32T> flags = LoadSymbolFlags(CAST(obj));
GotoIf(Word32And(flags, Symbol::IsInPublicSymbolTableBit::kMask),
Expand Down
10 changes: 3 additions & 7 deletions deps/v8/src/builtins/builtins-weak-refs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> 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(
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/builtins/finalization-registry.tq
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/builtins/weak-ref.tq
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions deps/v8/src/codegen/code-stub-assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2679,12 +2679,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
ExternalReference::address_of_shared_string_table_flag());
}

TNode<BoolT> 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<BoolT> IsNumeric(TNode<Object> object);

Expand Down
5 changes: 0 additions & 5 deletions deps/v8/src/codegen/external-reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions deps/v8/src/codegen/external-reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand Down
3 changes: 1 addition & 2 deletions deps/v8/src/flags/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/init/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4484,7 +4484,6 @@ void Genesis::InitializeConsole(Handle<JSObject> 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
Expand Down
7 changes: 2 additions & 5 deletions deps/v8/src/objects/objects-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ MaybeHandle<Object> Object::Share(Isolate* isolate, Handle<Object> 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
Expand All @@ -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<Object> ObjectHashTableShape::AsHandle(Handle<Object> key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.");

Expand Down
1 change: 0 additions & 1 deletion deps/v8/test/mjsunit/es6/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/test/mjsunit/harmony/symbol-as-weakmap-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 0 additions & 3 deletions deps/v8/test/mjsunit/harmony/weakrefs/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 58c7034

Please sign in to comment.