Skip to content

Commit c04fe24

Browse files
authored
Ensure that Map/Set object keys can always have MAP_KEY_STRING internal property (#3065)
This patch fixes #3062. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 9fbd0cc commit c04fe24

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

jerry-core/ecma/operations/ecma-container-object.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include "ecma-alloc.h"
17+
#include "ecma-array-object.h"
1718
#include "ecma-builtins.h"
1819
#include "ecma-builtin-helpers.h"
1920
#include "ecma-exceptions.h"
@@ -246,28 +247,27 @@ ecma_op_container_to_key (ecma_value_t key_arg) /**< key argument */
246247
ecma_object_t *obj_p = ecma_get_object_from_value (key_arg);
247248
ecma_string_t *key_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_MAP_KEY);
248249

249-
ecma_property_ref_t property_ref;
250-
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
251-
key_string_p,
252-
&property_ref,
253-
ECMA_PROPERTY_GET_NO_OPTIONS);
250+
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY
251+
&& ((ecma_extended_object_t *) obj_p)->u.array.is_fast_mode)
252+
{
253+
ecma_fast_array_convert_to_normal (obj_p);
254+
}
254255

256+
ecma_property_t *property_p = ecma_find_named_property (obj_p, key_string_p);
255257
ecma_string_t *object_key_string;
256258

257-
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
259+
if (property_p == NULL)
258260
{
259261
object_key_string = ecma_new_map_key_string (key_arg);
260-
ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p,
261-
key_string_p,
262-
ecma_make_string_value (object_key_string),
263-
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
264-
265-
JERRY_ASSERT (ecma_is_value_true (put_comp));
266-
ecma_deref_ecma_string (object_key_string);
262+
ecma_property_value_t *value_p = ecma_create_named_data_property (obj_p,
263+
key_string_p,
264+
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
265+
NULL);
266+
value_p->value = ecma_make_string_value (object_key_string);
267267
}
268268
else
269269
{
270-
object_key_string = ecma_get_string_from_value (property_ref.value_p->value);
270+
object_key_string = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
271271
}
272272

273273
ecma_ref_ecma_string (object_key_string);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var map = new Map();
16+
var obj = Object.freeze({});
17+
map.set(obj, 1);
18+
assert(map.has(obj));

0 commit comments

Comments
 (0)