Skip to content

Commit

Permalink
Add fast array support for property name enumeration (#3053)
Browse files Browse the repository at this point in the history
Since fast access mode arrays can be part of the prototype chain these objects must be handed separately.
This patch fixes #3050.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
  • Loading branch information
rerobika authored Sep 5, 2019
1 parent 24196b6 commit 4afcc70
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 62 deletions.
179 changes: 117 additions & 62 deletions jerry-core/ecma/operations/ecma-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,104 +1812,159 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */

jmem_cpointer_t prop_iter_cp = prototype_chain_iter_p->u1.property_list_cp;

#if ENABLED (JERRY_PROPRETY_HASHMAP)
if (prop_iter_cp != JMEM_CP_NULL)
if (ecma_get_object_type (prototype_chain_iter_p) == ECMA_OBJECT_TYPE_ARRAY
&& ((ecma_extended_object_t *) prototype_chain_iter_p)->u.array.is_fast_mode
&& prop_iter_cp != JMEM_CP_NULL)
{
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) prototype_chain_iter_p;

if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP)
{
prop_iter_cp = prop_iter_p->next_property_cp;
}
}
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
uint32_t length = ext_obj_p->u.array.length;

while (prop_iter_cp != JMEM_CP_NULL)
{
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, prop_iter_cp);

for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
for (uint32_t i = 0; i < length; i++)
{
ecma_property_t *property_p = prop_iter_p->types + i;
if (ecma_is_value_array_hole (values_p[i]))
{
continue;
}

ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i);

uint8_t hash = (uint8_t) ecma_string_hash (index_str_p);
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);

bool is_add = true;

if (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
if ((own_names_hashes_bitmap[bitmap_row] & (1u << bitmap_column)) != 0)
{
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
ecma_value_p = ecma_collection_iterator_init (prop_names_p);

if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC
&& prop_pair_p->names_cp[i] >= LIT_NON_INTERNAL_MAGIC_STRING__COUNT
&& prop_pair_p->names_cp[i] < LIT_MAGIC_STRING__COUNT)
while (ecma_value_p != NULL)
{
/* Internal properties are never enumerated. */
continue;
ecma_string_t *current_name_p = ecma_get_prop_name_from_value (*ecma_value_p);
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);

if (ecma_compare_ecma_strings (index_str_p, current_name_p))
{
is_add = false;
break;
}
}
}

ecma_string_t *name_p = ecma_string_from_property_name (*property_p,
prop_pair_p->names_cp[i]);
if (is_add)
{
own_names_hashes_bitmap[bitmap_row] |= (1u << bitmap_column);

if (!(is_enumerable_only && !ecma_is_property_enumerable (*property_p)))
ecma_append_to_values_collection (prop_names_p,
ecma_make_string_value (index_str_p),
ECMA_COLLECTION_NO_COPY);
}
}
}
else
{
#if ENABLED (JERRY_PROPRETY_HASHMAP)
if (prop_iter_cp != JMEM_CP_NULL)
{
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);

if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP)
{
prop_iter_cp = prop_iter_p->next_property_cp;
}
}
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */

while (prop_iter_cp != JMEM_CP_NULL)
{
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));

for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
{
ecma_property_t *property_p = prop_iter_p->types + i;

if (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
{
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
/* If is_symbols_only is false and prop_name is symbol
we should skip the current property e.g. for-in.
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;

Also if is_symbols_only is true and prop_name is not symbol
we should skip the current property e.g. Object.getOwnPropertySymbols. */
if (JERRY_UNLIKELY (is_symbols_only != ecma_prop_name_is_symbol (name_p)))
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC
&& prop_pair_p->names_cp[i] >= LIT_NON_INTERNAL_MAGIC_STRING__COUNT
&& prop_pair_p->names_cp[i] < LIT_MAGIC_STRING__COUNT)
{
ecma_deref_ecma_string (name_p);
/* Internal properties are never enumerated. */
continue;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */

uint8_t hash = (uint8_t) ecma_string_hash (name_p);
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);
ecma_string_t *name_p = ecma_string_from_property_name (*property_p,
prop_pair_p->names_cp[i]);

bool is_add = true;

if ((own_names_hashes_bitmap[bitmap_row] & (1u << bitmap_column)) != 0)
if (!(is_enumerable_only && !ecma_is_property_enumerable (*property_p)))
{
ecma_value_p = ecma_collection_iterator_init (prop_names_p);
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
/* If is_symbols_only is false and prop_name is symbol
we should skip the current property e.g. for-in.
Also if is_symbols_only is true and prop_name is not symbol
we should skip the current property e.g. Object.getOwnPropertySymbols. */
if (JERRY_UNLIKELY (is_symbols_only != ecma_prop_name_is_symbol (name_p)))
{
ecma_deref_ecma_string (name_p);
continue;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */

uint8_t hash = (uint8_t) ecma_string_hash (name_p);
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);

bool is_add = true;

while (ecma_value_p != NULL)
if ((own_names_hashes_bitmap[bitmap_row] & (1u << bitmap_column)) != 0)
{
ecma_string_t *current_name_p = ecma_get_prop_name_from_value (*ecma_value_p);
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
ecma_value_p = ecma_collection_iterator_init (prop_names_p);

if (ecma_compare_ecma_strings (name_p, current_name_p))
while (ecma_value_p != NULL)
{
is_add = false;
break;
ecma_string_t *current_name_p = ecma_get_prop_name_from_value (*ecma_value_p);
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);

if (ecma_compare_ecma_strings (name_p, current_name_p))
{
is_add = false;
break;
}
}
}
}

if (is_add)
if (is_add)
{
own_names_hashes_bitmap[bitmap_row] |= (1u << bitmap_column);

ecma_append_to_values_collection (prop_names_p,
ecma_make_prop_name_value (name_p),
0);
}
}
else
{
own_names_hashes_bitmap[bitmap_row] |= (1u << bitmap_column);
JERRY_ASSERT (is_enumerable_only && !ecma_is_property_enumerable (*property_p));

ecma_append_to_values_collection (prop_names_p,
ecma_append_to_values_collection (skipped_non_enumerable_p,
ecma_make_prop_name_value (name_p),
0);
}
}
else
{
JERRY_ASSERT (is_enumerable_only && !ecma_is_property_enumerable (*property_p));

ecma_append_to_values_collection (skipped_non_enumerable_p,
ecma_make_prop_name_value (name_p),
0);
ecma_deref_ecma_string (name_p);
}

ecma_deref_ecma_string (name_p);
}
}

prop_iter_cp = prop_iter_p->next_property_cp;
prop_iter_cp = prop_iter_p->next_property_cp;
}
}

ecma_value_p = ecma_collection_iterator_init (prop_names_p);
Expand Down
27 changes: 27 additions & 0 deletions tests/jerry/es2015/regression-test-issue-3050.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var counter = 0;
var expected = [0];

var b = [$];
function dConstr () { }
dConstr.prototype = b;
var d = new dConstr()
for (var $ in d) {
counter++;
assert($ in expected);
}

assert(counter === 1);

0 comments on commit 4afcc70

Please sign in to comment.