mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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 frobert@inf.u-szeged.hu
This commit is contained in:
parent
9fbd0cce6c
commit
c04fe24253
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ecma-alloc.h"
|
#include "ecma-alloc.h"
|
||||||
|
#include "ecma-array-object.h"
|
||||||
#include "ecma-builtins.h"
|
#include "ecma-builtins.h"
|
||||||
#include "ecma-builtin-helpers.h"
|
#include "ecma-builtin-helpers.h"
|
||||||
#include "ecma-exceptions.h"
|
#include "ecma-exceptions.h"
|
||||||
@ -246,28 +247,27 @@ ecma_op_container_to_key (ecma_value_t key_arg) /**< key argument */
|
|||||||
ecma_object_t *obj_p = ecma_get_object_from_value (key_arg);
|
ecma_object_t *obj_p = ecma_get_object_from_value (key_arg);
|
||||||
ecma_string_t *key_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_MAP_KEY);
|
ecma_string_t *key_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_MAP_KEY);
|
||||||
|
|
||||||
ecma_property_ref_t property_ref;
|
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY
|
||||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
&& ((ecma_extended_object_t *) obj_p)->u.array.is_fast_mode)
|
||||||
key_string_p,
|
{
|
||||||
&property_ref,
|
ecma_fast_array_convert_to_normal (obj_p);
|
||||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
}
|
||||||
|
|
||||||
|
ecma_property_t *property_p = ecma_find_named_property (obj_p, key_string_p);
|
||||||
ecma_string_t *object_key_string;
|
ecma_string_t *object_key_string;
|
||||||
|
|
||||||
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
if (property_p == NULL)
|
||||||
{
|
{
|
||||||
object_key_string = ecma_new_map_key_string (key_arg);
|
object_key_string = ecma_new_map_key_string (key_arg);
|
||||||
ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p,
|
ecma_property_value_t *value_p = ecma_create_named_data_property (obj_p,
|
||||||
key_string_p,
|
key_string_p,
|
||||||
ecma_make_string_value (object_key_string),
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
|
||||||
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
|
NULL);
|
||||||
|
value_p->value = ecma_make_string_value (object_key_string);
|
||||||
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
|
||||||
ecma_deref_ecma_string (object_key_string);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
object_key_string = ecma_get_string_from_value (property_ref.value_p->value);
|
object_key_string = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_ref_ecma_string (object_key_string);
|
ecma_ref_ecma_string (object_key_string);
|
||||||
|
|||||||
18
tests/jerry/es2015/regression-test-issue-3062.js
Normal file
18
tests/jerry/es2015/regression-test-issue-3062.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// 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 map = new Map();
|
||||||
|
var obj = Object.freeze({});
|
||||||
|
map.set(obj, 1);
|
||||||
|
assert(map.has(obj));
|
||||||
Loading…
x
Reference in New Issue
Block a user