Skip to content

Commit 29ba98a

Browse files
debadree25danielleadams
authored andcommitted
deps: V8: cherry-pick 975ff4dbfd1b
Original commit message: fix GetPropertyNames for proxys with ownKeys trap Added checks to FilterProxyKeys function for when skip_indices is enabled. Bug: v8:13728 Change-Id: Id096e32ef8e6c2344be9682e8222aea8790bd66d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4333698 Reviewed-by: Camillo Bruni <cbruni@chromium.org> Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/main@{#86548} Refs: v8/v8@975ff4d PR-URL: #47209 Fixes: #41714 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
1 parent c598877 commit 29ba98a

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed

deps/v8/AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Darshan Sen <raisinten@gmail.com>
9797
David Carlier <devnexen@gmail.com>
9898
David Manouchehri <david@davidmanouchehri.com>
9999
David Sanders <dsanders11@ucsbalum.com>
100+
Debadree Chatterjee <debadree333@gmail.com>
100101
Deepak Mohan <hop2deep@gmail.com>
101102
Deon Dior <diaoyuanjie@gmail.com>
102103
Derek Tu <derek.t@rioslab.org>

deps/v8/src/objects/keys.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ ExceptionStatus KeyAccumulator::AddKeys(Handle<JSObject> array_like,
182182
MaybeHandle<FixedArray> FilterProxyKeys(KeyAccumulator* accumulator,
183183
Handle<JSProxy> owner,
184184
Handle<FixedArray> keys,
185-
PropertyFilter filter) {
185+
PropertyFilter filter,
186+
bool skip_indices) {
186187
if (filter == ALL_PROPERTIES) {
187188
// Nothing to do.
188189
return keys;
@@ -192,6 +193,10 @@ MaybeHandle<FixedArray> FilterProxyKeys(KeyAccumulator* accumulator,
192193
for (int i = 0; i < keys->length(); ++i) {
193194
Handle<Name> key(Name::cast(keys->get(i)), isolate);
194195
if (key->FilterKey(filter)) continue; // Skip this key.
196+
if (skip_indices) {
197+
uint32_t index;
198+
if (key->AsArrayIndex(&index)) continue; // Skip this key.
199+
}
195200
if (filter & ONLY_ENUMERABLE) {
196201
PropertyDescriptor desc;
197202
Maybe<bool> found =
@@ -218,7 +223,8 @@ Maybe<bool> KeyAccumulator::AddKeysFromJSProxy(Handle<JSProxy> proxy,
218223
// Postpone the enumerable check for for-in to the ForInFilter step.
219224
if (!is_for_in_) {
220225
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
221-
isolate_, keys, FilterProxyKeys(this, proxy, keys, filter_),
226+
isolate_, keys,
227+
FilterProxyKeys(this, proxy, keys, filter_, skip_indices_),
222228
Nothing<bool>());
223229
}
224230
// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys

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

+104
Original file line numberDiff line numberDiff line change
@@ -14636,6 +14636,110 @@ THREADED_TEST(ProxyGetPropertyNames) {
1463614636
CheckIsSymbolAt(isolate, properties, 4, "symbol");
1463714637
}
1463814638

14639+
THREADED_TEST(ProxyGetPropertyNamesWithOwnKeysTrap) {
14640+
LocalContext context;
14641+
v8::Isolate* isolate = context->GetIsolate();
14642+
v8::HandleScope scope(isolate);
14643+
v8::Local<v8::Value> result = CompileRun(
14644+
"var target = {0: 0, 1: 1, a: 2, b: 3};"
14645+
"target[2**32] = '4294967296';"
14646+
"target[2**32-1] = '4294967295';"
14647+
"target[2**32-2] = '4294967294';"
14648+
"target[Symbol('symbol')] = true;"
14649+
"target.__proto__ = {__proto__:null, 2: 4, 3: 5, c: 6, d: 7};"
14650+
"var result = new Proxy(target, { ownKeys: (t) => Reflect.ownKeys(t) });"
14651+
"result;");
14652+
v8::Local<v8::Object> object = result.As<v8::Object>();
14653+
v8::PropertyFilter default_filter =
14654+
static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE | v8::SKIP_SYMBOLS);
14655+
v8::PropertyFilter include_symbols_filter = v8::ONLY_ENUMERABLE;
14656+
14657+
v8::Local<v8::Array> properties =
14658+
object->GetPropertyNames(context.local()).ToLocalChecked();
14659+
const char* expected_properties1[] = {"0", "1", "4294967294", "a",
14660+
"b", "4294967296", "4294967295", "2",
14661+
"3", "c", "d"};
14662+
CheckStringArray(isolate, properties, 11, expected_properties1);
14663+
14664+
properties =
14665+
object
14666+
->GetPropertyNames(context.local(),
14667+
v8::KeyCollectionMode::kIncludePrototypes,
14668+
default_filter, v8::IndexFilter::kIncludeIndices)
14669+
.ToLocalChecked();
14670+
CheckStringArray(isolate, properties, 11, expected_properties1);
14671+
14672+
properties = object
14673+
->GetPropertyNames(context.local(),
14674+
v8::KeyCollectionMode::kIncludePrototypes,
14675+
include_symbols_filter,
14676+
v8::IndexFilter::kIncludeIndices)
14677+
.ToLocalChecked();
14678+
const char* expected_properties1_1[] = {
14679+
"0", "1", "4294967294", "a", "b", "4294967296",
14680+
"4294967295", nullptr, "2", "3", "c", "d"};
14681+
CheckStringArray(isolate, properties, 12, expected_properties1_1);
14682+
CheckIsSymbolAt(isolate, properties, 7, "symbol");
14683+
14684+
properties =
14685+
object
14686+
->GetPropertyNames(context.local(),
14687+
v8::KeyCollectionMode::kIncludePrototypes,
14688+
default_filter, v8::IndexFilter::kSkipIndices)
14689+
.ToLocalChecked();
14690+
const char* expected_properties2[] = {"a", "b", "4294967296",
14691+
"4294967295", "c", "d"};
14692+
CheckStringArray(isolate, properties, 6, expected_properties2);
14693+
14694+
properties = object
14695+
->GetPropertyNames(context.local(),
14696+
v8::KeyCollectionMode::kIncludePrototypes,
14697+
include_symbols_filter,
14698+
v8::IndexFilter::kSkipIndices)
14699+
.ToLocalChecked();
14700+
const char* expected_properties2_1[] = {
14701+
"a", "b", "4294967296", "4294967295", nullptr, "c", "d"};
14702+
CheckStringArray(isolate, properties, 7, expected_properties2_1);
14703+
CheckIsSymbolAt(isolate, properties, 4, "symbol");
14704+
14705+
properties =
14706+
object
14707+
->GetPropertyNames(context.local(), v8::KeyCollectionMode::kOwnOnly,
14708+
default_filter, v8::IndexFilter::kIncludeIndices)
14709+
.ToLocalChecked();
14710+
const char* expected_properties3[] = {"0", "1", "4294967294", "a",
14711+
"b", "4294967296", "4294967295"};
14712+
CheckStringArray(isolate, properties, 7, expected_properties3);
14713+
14714+
properties = object
14715+
->GetPropertyNames(
14716+
context.local(), v8::KeyCollectionMode::kOwnOnly,
14717+
include_symbols_filter, v8::IndexFilter::kIncludeIndices)
14718+
.ToLocalChecked();
14719+
const char* expected_properties3_1[] = {
14720+
"0", "1", "4294967294", "a", "b", "4294967296", "4294967295", nullptr};
14721+
CheckStringArray(isolate, properties, 8, expected_properties3_1);
14722+
CheckIsSymbolAt(isolate, properties, 7, "symbol");
14723+
14724+
properties =
14725+
object
14726+
->GetPropertyNames(context.local(), v8::KeyCollectionMode::kOwnOnly,
14727+
default_filter, v8::IndexFilter::kSkipIndices)
14728+
.ToLocalChecked();
14729+
const char* expected_properties4[] = {"a", "b", "4294967296", "4294967295"};
14730+
CheckStringArray(isolate, properties, 4, expected_properties4);
14731+
14732+
properties = object
14733+
->GetPropertyNames(
14734+
context.local(), v8::KeyCollectionMode::kOwnOnly,
14735+
include_symbols_filter, v8::IndexFilter::kSkipIndices)
14736+
.ToLocalChecked();
14737+
const char* expected_properties4_1[] = {"a", "b", "4294967296", "4294967295",
14738+
nullptr};
14739+
CheckStringArray(isolate, properties, 5, expected_properties4_1);
14740+
CheckIsSymbolAt(isolate, properties, 4, "symbol");
14741+
}
14742+
1463914743
THREADED_TEST(AccessChecksReenabledCorrectly) {
1464014744
LocalContext context;
1464114745
v8::Isolate* isolate = context->GetIsolate();

0 commit comments

Comments
 (0)