Commit 76cab5ff authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

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/1027832Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52786}
parent 52f07582
...@@ -278,7 +278,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries( ...@@ -278,7 +278,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
object_enum_length, IntPtrConstant(kInvalidEnumCacheSentinel)); object_enum_length, IntPtrConstant(kInvalidEnumCacheSentinel));
// In case, we found enum_cache in object, // In case, we found enum_cache in object,
// we use it as array_length becuase it has same size for // we use it as array_length because it has same size for
// Object.(entries/values) result array object length. // Object.(entries/values) result array object length.
// So object_enum_length use less memory space than // So object_enum_length use less memory space than
// NumberOfOwnDescriptorsBits value. // NumberOfOwnDescriptorsBits value.
...@@ -295,7 +295,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries( ...@@ -295,7 +295,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
INTPTR_PARAMETERS, kAllowLargeObjectAllocation)); INTPTR_PARAMETERS, kAllowLargeObjectAllocation));
// If in case we have enum_cache, // If in case we have enum_cache,
// we can't detect accessor of object until loop through descritpros. // we can't detect accessor of object until loop through descriptors.
// So if object might have accessor, // So if object might have accessor,
// we will remain invalid addresses of FixedArray. // we will remain invalid addresses of FixedArray.
// Because in that case, we need to jump to runtime call. // Because in that case, we need to jump to runtime call.
...@@ -309,7 +309,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries( ...@@ -309,7 +309,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
Variable* vars[] = {&var_descriptor_number, &var_result_index}; Variable* vars[] = {&var_descriptor_number, &var_result_index};
// Let desc be ? O.[[GetOwnProperty]](key). // Let desc be ? O.[[GetOwnProperty]](key).
TNode<DescriptorArray> descriptors = LoadMapDescriptors(map); TNode<DescriptorArray> descriptors = LoadMapDescriptors(map);
Label loop(this, 2, vars), after_loop(this), loop_condition(this); Label loop(this, 2, vars), after_loop(this), next_descriptor(this);
Branch(IntPtrEqual(var_descriptor_number.value(), object_enum_length), Branch(IntPtrEqual(var_descriptor_number.value(), object_enum_length),
&after_loop, &loop); &after_loop, &loop);
...@@ -326,7 +326,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries( ...@@ -326,7 +326,7 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
Node* next_key = GetKey(descriptors, descriptor_index); Node* next_key = GetKey(descriptors, descriptor_index);
// Skip Symbols. // Skip Symbols.
GotoIf(IsSymbol(next_key), &loop_condition); GotoIf(IsSymbol(next_key), &next_descriptor);
TNode<Uint32T> details = TNode<Uint32T>::UncheckedCast( TNode<Uint32T> details = TNode<Uint32T>::UncheckedCast(
DescriptorArrayGetDetails(descriptors, descriptor_index)); DescriptorArrayGetDetails(descriptors, descriptor_index));
...@@ -336,8 +336,9 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries( ...@@ -336,8 +336,9 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
GotoIf(IsPropertyKindAccessor(kind), if_call_runtime_with_fast_path); GotoIf(IsPropertyKindAccessor(kind), if_call_runtime_with_fast_path);
CSA_ASSERT(this, IsPropertyKindData(kind)); CSA_ASSERT(this, IsPropertyKindData(kind));
// If desc is not undefined and desc.[[Enumerable]] is true, then // If desc is not undefined and desc.[[Enumerable]] is true, then skip to
GotoIfNot(IsPropertyEnumerable(details), &loop_condition); // the next descriptor.
GotoIfNot(IsPropertyEnumerable(details), &next_descriptor);
VARIABLE(var_property_value, MachineRepresentation::kTagged, VARIABLE(var_property_value, MachineRepresentation::kTagged,
UndefinedConstant()); UndefinedConstant());
...@@ -367,12 +368,12 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries( ...@@ -367,12 +368,12 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
StoreFixedArrayElement(values_or_entries, var_result_index.value(), StoreFixedArrayElement(values_or_entries, var_result_index.value(),
value); value);
Increment(&var_result_index, 1); Increment(&var_result_index, 1);
Goto(&loop_condition); Goto(&next_descriptor);
BIND(&loop_condition); BIND(&next_descriptor);
{ {
Increment(&var_descriptor_number, 1); Increment(&var_descriptor_number, 1);
Branch(IntPtrEqual(var_descriptor_number.value(), object_enum_length), Branch(IntPtrEqual(var_result_index.value(), object_enum_length),
&after_loop, &loop); &after_loop, &loop);
} }
} }
......
...@@ -210,6 +210,24 @@ function TestPropertyFilter(withWarmup) { ...@@ -210,6 +210,24 @@ function TestPropertyFilter(withWarmup) {
TestPropertyFilter(); TestPropertyFilter();
TestPropertyFilter(true); TestPropertyFilter(true);
function TestPropertyFilter2(withWarmup) {
var object = { };
Object.defineProperty(object, "prop1", { value: 10 });
Object.defineProperty(object, "prop2", { value: 20 });
object.prop3 = 30;
if (withWarmup) {
for (const key in object) {}
}
values = Object.entries(object);
assertEquals(1, values.length);
assertEquals([
[ "prop3", 30 ],
], values);
}
TestPropertyFilter2();
TestPropertyFilter2(true);
function TestWithProxy(withWarmup) { function TestWithProxy(withWarmup) {
var obj1 = {prop1:10}; var obj1 = {prop1:10};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment