Skip to content

Commit

Permalink
deps: V8: cherry-pick 7f5daed62d47
Browse files Browse the repository at this point in the history
Original commit message:

    [symbol-as-weakmap-key] Add tests to check weak collection size

    ... after gc.

    This CL also adds a runtime test function GetWeakCollectionSize
    to get the weak collection size.

    Bug: v8:12947
    Change-Id: I4aff39165a54b63b3d690bfea71c2a439da01d00
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3905071
    Reviewed-by: Marja Hölttä <[email protected]>
    Commit-Queue: 王澳 <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#83464}

Refs: v8/v8@7f5daed
PR-URL: #51004
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
joyeecheung authored and richardlau committed Mar 15, 2024
1 parent 1ce901b commit d4a530e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 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.29',
'v8_embedder_string': '-node.30',

##### V8 defaults for Node.js #####

Expand Down
10 changes: 10 additions & 0 deletions deps/v8/src/runtime/runtime-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "src/logging/counters.h"
#include "src/objects/heap-object-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-collection-inl.h"
#include "src/objects/js-function-inl.h"
#include "src/objects/js-regexp-inl.h"
#include "src/objects/managed-inl.h"
Expand Down Expand Up @@ -1730,5 +1731,14 @@ RUNTIME_FUNCTION(Runtime_SharedGC) {
return ReadOnlyRoots(isolate).undefined_value();
}

RUNTIME_FUNCTION(Runtime_GetWeakCollectionSize) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
Handle<JSWeakCollection> collection = args.at<JSWeakCollection>(0);

return Smi::FromInt(
EphemeronHashTable::cast(collection->table()).NumberOfElements());
}

} // namespace internal
} // namespace v8
1 change: 1 addition & 0 deletions deps/v8/src/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace internal {
F(GetInitializerFunction, 1, 1) \
F(GetOptimizationStatus, 1, 1) \
F(GetUndetectable, 0, 1) \
F(GetWeakCollectionSize, 1, 1) \
F(GlobalPrint, 1, 1) \
F(HasDictionaryElements, 1, 1) \
F(HasDoubleElements, 1, 1) \
Expand Down
14 changes: 8 additions & 6 deletions 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
// Flags: --harmony-symbol-as-weakmap-key --expose-gc --allow-natives-syntax --noincremental-marking

(function TestWeakMapWithNonRegisteredSymbolKey() {
const key = Symbol('123');
Expand All @@ -28,16 +28,17 @@
const outerKey = Symbol('234');
const outerValue = 1;
map.set(outerKey, outerValue);
{
(function () {
const innerKey = Symbol('123');
const innerValue = 1;
map.set(innerKey, innerValue);
assertTrue(map.has(innerKey));
assertSame(innerValue, map.get(innerKey));
}
})();
gc();
assertTrue(map.has(outerKey));
assertSame(outerValue, map.get(outerKey));
assertEquals(1, %GetWeakCollectionSize(map));
})();

(function TestWeakMapWithRegisteredSymbolKey() {
Expand Down Expand Up @@ -74,13 +75,14 @@
const set = new WeakSet();
const outerKey = Symbol('234');
set.add(outerKey);
{
(function () {
const innerKey = Symbol('123');
set.add(innerKey);
assertTrue(set.has(innerKey));
}
gc();
})();
assertTrue(set.has(outerKey));
gc();
assertEquals(1, %GetWeakCollectionSize(set));
})();

(function TestWeakSetWithRegisteredSymbolKey() {
Expand Down

0 comments on commit d4a530e

Please sign in to comment.