Skip to content

Commit 76cab5f

Browse files
camillobruniCommit Bot
authored andcommitted
Fix Object.entries/.values with non-enumerable properties
Iterate over all descriptors instead of bailing out early and missing enumerable properties later. Bug: chromium:836145 Change-Id: I104f7ea89480383b6b4b9204942a166bdf8e0597 Reviewed-on: https://chromium-review.googlesource.com/1027832 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#52786}
1 parent 52f0758 commit 76cab5f

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/builtins/builtins-object-gen.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
278278
object_enum_length, IntPtrConstant(kInvalidEnumCacheSentinel));
279279

280280
// In case, we found enum_cache in object,
281-
// we use it as array_length becuase it has same size for
281+
// we use it as array_length because it has same size for
282282
// Object.(entries/values) result array object length.
283283
// So object_enum_length use less memory space than
284284
// NumberOfOwnDescriptorsBits value.
@@ -295,7 +295,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
295295
INTPTR_PARAMETERS, kAllowLargeObjectAllocation));
296296

297297
// If in case we have enum_cache,
298-
// we can't detect accessor of object until loop through descritpros.
298+
// we can't detect accessor of object until loop through descriptors.
299299
// So if object might have accessor,
300300
// we will remain invalid addresses of FixedArray.
301301
// Because in that case, we need to jump to runtime call.
@@ -309,7 +309,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
309309
Variable* vars[] = {&var_descriptor_number, &var_result_index};
310310
// Let desc be ? O.[[GetOwnProperty]](key).
311311
TNode<DescriptorArray> descriptors = LoadMapDescriptors(map);
312-
Label loop(this, 2, vars), after_loop(this), loop_condition(this);
312+
Label loop(this, 2, vars), after_loop(this), next_descriptor(this);
313313
Branch(IntPtrEqual(var_descriptor_number.value(), object_enum_length),
314314
&after_loop, &loop);
315315

@@ -326,7 +326,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
326326
Node* next_key = GetKey(descriptors, descriptor_index);
327327

328328
// Skip Symbols.
329-
GotoIf(IsSymbol(next_key), &loop_condition);
329+
GotoIf(IsSymbol(next_key), &next_descriptor);
330330

331331
TNode<Uint32T> details = TNode<Uint32T>::UncheckedCast(
332332
DescriptorArrayGetDetails(descriptors, descriptor_index));
@@ -336,8 +336,9 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
336336
GotoIf(IsPropertyKindAccessor(kind), if_call_runtime_with_fast_path);
337337
CSA_ASSERT(this, IsPropertyKindData(kind));
338338

339-
// If desc is not undefined and desc.[[Enumerable]] is true, then
340-
GotoIfNot(IsPropertyEnumerable(details), &loop_condition);
339+
// If desc is not undefined and desc.[[Enumerable]] is true, then skip to
340+
// the next descriptor.
341+
GotoIfNot(IsPropertyEnumerable(details), &next_descriptor);
341342

342343
VARIABLE(var_property_value, MachineRepresentation::kTagged,
343344
UndefinedConstant());
@@ -367,12 +368,12 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
367368
StoreFixedArrayElement(values_or_entries, var_result_index.value(),
368369
value);
369370
Increment(&var_result_index, 1);
370-
Goto(&loop_condition);
371+
Goto(&next_descriptor);
371372

372-
BIND(&loop_condition);
373+
BIND(&next_descriptor);
373374
{
374375
Increment(&var_descriptor_number, 1);
375-
Branch(IntPtrEqual(var_descriptor_number.value(), object_enum_length),
376+
Branch(IntPtrEqual(var_result_index.value(), object_enum_length),
376377
&after_loop, &loop);
377378
}
378379
}

test/mjsunit/es8/object-entries.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ function TestPropertyFilter(withWarmup) {
210210
TestPropertyFilter();
211211
TestPropertyFilter(true);
212212

213+
function TestPropertyFilter2(withWarmup) {
214+
var object = { };
215+
Object.defineProperty(object, "prop1", { value: 10 });
216+
Object.defineProperty(object, "prop2", { value: 20 });
217+
object.prop3 = 30;
218+
219+
if (withWarmup) {
220+
for (const key in object) {}
221+
}
222+
223+
values = Object.entries(object);
224+
assertEquals(1, values.length);
225+
assertEquals([
226+
[ "prop3", 30 ],
227+
], values);
228+
}
229+
TestPropertyFilter2();
230+
TestPropertyFilter2(true);
213231

214232
function TestWithProxy(withWarmup) {
215233
var obj1 = {prop1:10};

0 commit comments

Comments
 (0)