diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c index d9c46c978..279ec850e 100644 --- a/jerry-core/ecma/operations/ecma-objects.c +++ b/jerry-core/ecma/operations/ecma-objects.c @@ -531,12 +531,10 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */ /* ES2015 9.4.5.4 */ if (ecma_object_is_typedarray (object_p)) { -#if ENABLED (JERRY_ESNEXT) if (ecma_prop_name_is_symbol (property_name_p)) { break; } -#endif /* ENABLED (JERRY_ESNEXT) */ uint32_t array_index = ecma_string_get_array_index (property_name_p); @@ -1320,12 +1318,10 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ /* ES2015 9.4.5.5 */ if (ecma_object_is_typedarray (object_p)) { -#if ENABLED (JERRY_ESNEXT) if (ecma_prop_name_is_symbol (property_name_p)) { break; } -#endif /* ENABLED (JERRY_ESNEXT) */ uint32_t array_index = ecma_string_get_array_index (property_name_p); @@ -1335,7 +1331,7 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ if (array_index >= info.length) { - return ecma_reject (is_throw); + return ECMA_VALUE_FALSE; } uint32_t byte_pos = array_index << info.shift; @@ -1344,15 +1340,13 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ ecma_number_t num = ecma_string_to_number (property_name_p); ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); - - if (ecma_compare_ecma_strings (property_name_p, num_to_str)) - { - ecma_deref_ecma_string (num_to_str); - - return ecma_reject (is_throw); - } - + bool is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); ecma_deref_ecma_string (num_to_str); + + if (is_same) + { + return ECMA_VALUE_FALSE; + } } #endif /* ENABLED (JERRY_BUILTIN_TYPEDARRAY) */ break; @@ -1794,14 +1788,12 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */ /* ES2015 9.4.5.3 */ if (ecma_object_is_typedarray (obj_p)) { -#if ENABLED (JERRY_ESNEXT) if (ecma_prop_name_is_symbol (property_name_p)) { return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p); } -#endif /* ENABLED (JERRY_ESNEXT) */ uint32_t array_index = ecma_string_get_array_index (property_name_p); if (array_index != ECMA_STRING_NOT_ARRAY_INDEX) @@ -1825,15 +1817,13 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */ ecma_number_t num = ecma_string_to_number (property_name_p); ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); + bool is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); + ecma_deref_ecma_string (num_to_str); - if (ecma_compare_ecma_strings (property_name_p, num_to_str)) + if (is_same) { - ecma_deref_ecma_string (num_to_str); - return ecma_reject (property_desc_p->flags & ECMA_PROP_IS_THROW); } - - ecma_deref_ecma_string (num_to_str); } return ecma_op_general_object_define_own_property (obj_p, diff --git a/tests/jerry/es.next/typedarray-put.js b/tests/jerry/es.next/typedarray-put.js new file mode 100644 index 000000000..8462bd1b8 --- /dev/null +++ b/tests/jerry/es.next/typedarray-put.js @@ -0,0 +1,47 @@ +// 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 typedarrays = [ + new Uint8ClampedArray([1]), + new Uint8Array([1]), + new Uint16Array([1]), + new Uint32Array([1]), + new Float32Array([1]), + new Float64Array([1]), + new Int8Array([1]), + new Int16Array([1]), + new Int32Array([1]), + new BigInt64Array([1n]), + new BigUint64Array([1n]), +]; + +for (let ta of typedarrays) { + for (let prop_name of [2, 5.1]) { + let set_value = 4.2; + (function () { + "use strict"; + let set_result = ta[prop_name] = set_value; + assert(set_result === set_value); + assert(!ta.hasOwnProperty(prop_name)); + assert(ta.length === 1); + })(); + + (function () { + let set_result = ta[prop_name] = set_value; + assert(set_result === set_value); + assert(!ta.hasOwnProperty(prop_name)); + assert(ta.length === 1); + })(); + } +} diff --git a/tests/unit-core/test-typedarray.c b/tests/unit-core/test-typedarray.c index d88c94e5d..8b07aada1 100644 --- a/tests/unit-core/test-typedarray.c +++ b/tests/unit-core/test-typedarray.c @@ -458,7 +458,7 @@ static void test_property_by_index (test_entry_t test_entries[]) } jerry_value_t set_undefined = jerry_set_property_by_index (typedarray, 100, jerry_create_number (50)); - TEST_ASSERT (jerry_value_is_error (set_undefined)); + TEST_ASSERT (jerry_value_is_boolean (set_undefined) && !jerry_get_boolean_value (set_undefined)); jerry_value_t get_undefined = jerry_get_property_by_index (typedarray, 100); TEST_ASSERT (jerry_value_is_undefined (get_undefined));