diff --git a/jerry-core/ecma/base/ecma-property-hashmap.c b/jerry-core/ecma/base/ecma-property-hashmap.c index e9032a8a1..97c3fd234 100644 --- a/jerry-core/ecma/base/ecma-property-hashmap.c +++ b/jerry-core/ecma/base/ecma-property-hashmap.c @@ -138,6 +138,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */ hashmap_p->header.next_property_cp = object_p->property_list_or_bound_object_cp; hashmap_p->max_property_count = max_property_count; hashmap_p->null_count = max_property_count - named_property_count; + hashmap_p->unused_count = max_property_count - named_property_count; jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1); uint8_t *bits_p = (uint8_t *) (pair_list_p + max_property_count); @@ -312,6 +313,9 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */ hashmap_p->null_count--; JERRY_ASSERT (hashmap_p->null_count > 0); + hashmap_p->unused_count--; + JERRY_ASSERT (hashmap_p->unused_count > 0); + if (property_index == 0) { *bits_p = (uint8_t) ((*bits_p) & ~mask); @@ -345,10 +349,10 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */ JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP); - hashmap_p->null_count++; + hashmap_p->unused_count++; /* The NULLs are above 3/4 of the hashmap. */ - if (hashmap_p->null_count > ((hashmap_p->max_property_count * 3) >> 2)) + if (hashmap_p->unused_count > ((hashmap_p->max_property_count * 3) >> 2)) { return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP; } diff --git a/jerry-core/ecma/base/ecma-property-hashmap.h b/jerry-core/ecma/base/ecma-property-hashmap.h index 3ad4dbbd0..02d11a2a1 100644 --- a/jerry-core/ecma/base/ecma-property-hashmap.h +++ b/jerry-core/ecma/base/ecma-property-hashmap.h @@ -36,6 +36,7 @@ typedef struct ecma_property_header_t header; /**< header of the property */ uint32_t max_property_count; /**< maximum property count (power of 2) */ uint32_t null_count; /**< number of NULLs in the map */ + uint32_t unused_count; /**< number of unused entires in the map */ /* * The hash is followed by max_property_count ecma_cpointer_t diff --git a/tests/jerry/regression-test-issue-1552.js b/tests/jerry/regression-test-issue-1552.js new file mode 100644 index 000000000..9e1a6875e --- /dev/null +++ b/tests/jerry/regression-test-issue-1552.js @@ -0,0 +1,26 @@ +// 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 o = [] + +function add(i) +{ + delete o[i & 31]; + o[i] = 0; +} + +for (var i = 0; i < 130; i++) +{ + add(i) +}