deps: backport c608122b from upstream · nodejs/node@4dfafac · GitHub
Skip to content

Commit 4dfafac

Browse files
BridgeARrvagg
authored andcommitted
deps: backport c608122b from upstream
Original commit message: [api][keys] Allow skipping indices for Proxies with GetPropertyNames Bug: v8:7942 Change-Id: I7b3740b04cbcaa56dc809150900ab8d821b054ce Reviewed-on: https://chromium-review.googlesource.com/1156544 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#54821} PR-URL: #22210 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent 1ed03b0 commit 4dfafac

5 files changed

Lines changed: 136 additions & 26 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion

deps/v8/src/keys.cc

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
3737
// static
3838
MaybeHandle<FixedArray> KeyAccumulator::GetKeys(
3939
Handle<JSReceiver> object, KeyCollectionMode mode, PropertyFilter filter,
40-
GetKeysConversion keys_conversion, bool is_for_in) {
40+
GetKeysConversion keys_conversion, bool is_for_in, bool skip_indices) {
4141
Isolate* isolate = object->GetIsolate();
42-
FastKeyAccumulator accumulator(isolate, object, mode, filter);
43-
accumulator.set_is_for_in(is_for_in);
42+
FastKeyAccumulator accumulator(isolate, object, mode, filter, is_for_in,
43+
skip_indices);
4444
return accumulator.GetKeys(keys_conversion);
4545
}
4646

@@ -356,7 +356,8 @@ Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate,
356356
template <bool fast_properties>
357357
MaybeHandle<FixedArray> GetOwnKeysWithElements(Isolate* isolate,
358358
Handle<JSObject> object,
359-
GetKeysConversion convert) {
359+
GetKeysConversion convert,
360+
bool skip_indices) {
360361
Handle<FixedArray> keys;
361362
ElementsAccessor* accessor = object->GetElementsAccessor();
362363
if (fast_properties) {
@@ -365,8 +366,13 @@ MaybeHandle<FixedArray> GetOwnKeysWithElements(Isolate* isolate,
365366
// TODO(cbruni): preallocate big enough array to also hold elements.
366367
keys = KeyAccumulator::GetOwnEnumPropertyKeys(isolate, object);
367368
}
368-
MaybeHandle<FixedArray> result =
369-
accessor->PrependElementIndices(object, keys, convert, ONLY_ENUMERABLE);
369+
MaybeHandle<FixedArray> result;
370+
if (skip_indices) {
371+
result = keys;
372+
} else {
373+
result =
374+
accessor->PrependElementIndices(object, keys, convert, ONLY_ENUMERABLE);
375+
}
370376

371377
if (FLAG_trace_for_in_enumerate) {
372378
PrintF("| strings=%d symbols=0 elements=%u || prototypes>=1 ||\n",
@@ -404,7 +410,8 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysFast(
404410

405411
// Do not try to use the enum-cache for dict-mode objects.
406412
if (map->is_dictionary_map()) {
407-
return GetOwnKeysWithElements<false>(isolate_, object, keys_conversion);
413+
return GetOwnKeysWithElements<false>(isolate_, object, keys_conversion,
414+
skip_indices_);
408415
}
409416
int enum_length = receiver_->map()->EnumLength();
410417
if (enum_length == kInvalidEnumCacheSentinel) {
@@ -422,7 +429,8 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysFast(
422429
}
423430
// The properties-only case failed because there were probably elements on the
424431
// receiver.
425-
return GetOwnKeysWithElements<true>(isolate_, object, keys_conversion);
432+
return GetOwnKeysWithElements<true>(isolate_, object, keys_conversion,
433+
skip_indices_);
426434
}
427435

428436
MaybeHandle<FixedArray>
@@ -451,6 +459,7 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysSlow(
451459
GetKeysConversion keys_conversion) {
452460
KeyAccumulator accumulator(isolate_, mode_, filter_);
453461
accumulator.set_is_for_in(is_for_in_);
462+
accumulator.set_skip_indices(skip_indices_);
454463
accumulator.set_last_non_empty_prototype(last_non_empty_prototype_);
455464

456465
MAYBE_RETURN(accumulator.CollectKeys(receiver_, receiver_),
@@ -698,13 +707,15 @@ Maybe<bool> KeyAccumulator::CollectOwnPropertyNames(Handle<JSReceiver> receiver,
698707
Maybe<bool> KeyAccumulator::CollectAccessCheckInterceptorKeys(
699708
Handle<AccessCheckInfo> access_check_info, Handle<JSReceiver> receiver,
700709
Handle<JSObject> object) {
701-
MAYBE_RETURN((CollectInterceptorKeysInternal(
702-
receiver, object,
703-
handle(InterceptorInfo::cast(
704-
access_check_info->indexed_interceptor()),
705-
isolate_),
706-
this, kIndexed)),
707-
Nothing<bool>());
710+
if (!skip_indices_) {
711+
MAYBE_RETURN((CollectInterceptorKeysInternal(
712+
receiver, object,
713+
handle(InterceptorInfo::cast(
714+
access_check_info->indexed_interceptor()),
715+
isolate_),
716+
this, kIndexed)),
717+
Nothing<bool>());
718+
}
708719
MAYBE_RETURN(
709720
(CollectInterceptorKeysInternal(
710721
receiver, object,
@@ -935,8 +946,9 @@ Maybe<bool> KeyAccumulator::CollectOwnJSProxyTargetKeys(
935946
Handle<FixedArray> keys;
936947
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
937948
isolate_, keys,
938-
KeyAccumulator::GetKeys(target, KeyCollectionMode::kOwnOnly, filter_,
939-
GetKeysConversion::kConvertToString, is_for_in_),
949+
KeyAccumulator::GetKeys(
950+
target, KeyCollectionMode::kOwnOnly, filter_,
951+
GetKeysConversion::kConvertToString, is_for_in_, skip_indices_),
940952
Nothing<bool>());
941953
Maybe<bool> result = AddKeysFromJSProxy(proxy, keys);
942954
return result;

deps/v8/src/keys.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class KeyAccumulator final BASE_EMBEDDED {
4040
static MaybeHandle<FixedArray> GetKeys(
4141
Handle<JSReceiver> object, KeyCollectionMode mode, PropertyFilter filter,
4242
GetKeysConversion keys_conversion = GetKeysConversion::kKeepNumbers,
43-
bool is_for_in = false);
43+
bool is_for_in = false, bool skip_indices = false);
4444

4545
Handle<FixedArray> GetKeys(
4646
GetKeysConversion convert = GetKeysConversion::kKeepNumbers);
@@ -128,14 +128,19 @@ class KeyAccumulator final BASE_EMBEDDED {
128128
class FastKeyAccumulator {
129129
public:
130130
FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver,
131-
KeyCollectionMode mode, PropertyFilter filter)
132-
: isolate_(isolate), receiver_(receiver), mode_(mode), filter_(filter) {
131+
KeyCollectionMode mode, PropertyFilter filter,
132+
bool is_for_in = false, bool skip_indices = false)
133+
: isolate_(isolate),
134+
receiver_(receiver),
135+
mode_(mode),
136+
filter_(filter),
137+
is_for_in_(is_for_in),
138+
skip_indices_(skip_indices) {
133139
Prepare();
134140
}
135141

136142
bool is_receiver_simple_enum() { return is_receiver_simple_enum_; }
137143
bool has_empty_prototype() { return has_empty_prototype_; }
138-
void set_is_for_in(bool value) { is_for_in_ = value; }
139144

140145
MaybeHandle<FixedArray> GetKeys(
141146
GetKeysConversion convert = GetKeysConversion::kKeepNumbers);
@@ -153,6 +158,7 @@ class FastKeyAccumulator {
153158
KeyCollectionMode mode_;
154159
PropertyFilter filter_;
155160
bool is_for_in_ = false;
161+
bool skip_indices_ = false;
156162
bool is_receiver_simple_enum_ = false;
157163
bool has_empty_prototype_ = false;
158164

deps/v8/src/runtime/runtime-forin.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ MaybeHandle<HeapObject> Enumerate(Handle<JSReceiver> receiver) {
2525
JSObject::MakePrototypesFast(receiver, kStartAtReceiver, isolate);
2626
FastKeyAccumulator accumulator(isolate, receiver,
2727
KeyCollectionMode::kIncludePrototypes,
28-
ENUMERABLE_STRINGS);
29-
accumulator.set_is_for_in(true);
28+
ENUMERABLE_STRINGS, true);
3029
// Test if we have an enum cache for {receiver}.
3130
if (!accumulator.is_receiver_simple_enum()) {
3231
Handle<FixedArray> keys;

deps/v8/test/cctest/test-api.cc

Lines changed: 95 additions & 2 deletions

0 commit comments

Comments
 (0)