diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c b/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c index a2474b57e..105f1868c 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c @@ -213,11 +213,9 @@ ecma_builtin_intrinsic_dispatch_routine (uint16_t builtin_routine_id, /**< built case ECMA_INTRINSIC_STRING_TRIM_START: case ECMA_INTRINSIC_STRING_TRIM_END: { - ecma_value_t coercible = ecma_op_check_object_coercible (this_arg); - - if (ECMA_IS_VALUE_ERROR (coercible)) + if (!ecma_op_require_object_coercible (this_arg)) { - return coercible; + return ECMA_VALUE_ERROR; } ecma_string_t *to_str_p = ecma_op_to_string (this_arg); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c index 1a3e45dd0..a4989857f 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c @@ -182,7 +182,7 @@ ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's f ecma_value_t arg2) /**< routine's second argument */ { /* 1., 2. */ - if (ECMA_IS_VALUE_ERROR (ecma_op_check_object_coercible (arg1))) + if (!ecma_op_require_object_coercible (arg1)) { return ECMA_VALUE_ERROR; } @@ -246,7 +246,7 @@ ecma_builtin_object_object_set_proto (ecma_value_t arg1, /**< routine's first ar ecma_value_t arg2) /**< routine's second argument */ { /* 1., 2. */ - if (ECMA_IS_VALUE_ERROR (ecma_op_check_object_coercible (arg1))) + if (!ecma_op_require_object_coercible (arg1)) { return ECMA_VALUE_ERROR; } @@ -1174,7 +1174,7 @@ ecma_builtin_object_object_is (ecma_value_t arg1, /**< routine's first argument static ecma_value_t ecma_builtin_object_from_entries (ecma_value_t iterator) /**< object's iterator */ { - JERRY_ASSERT (ecma_op_check_object_coercible (iterator)); + JERRY_ASSERT (ecma_op_require_object_coercible (iterator)); /* 2 */ ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); ecma_object_t *obj_p = ecma_create_object (object_prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index 55152b4de..94030d05d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -454,12 +454,10 @@ ecma_builtin_string_prototype_object_replace_helper (ecma_value_t this_value, /* return get_flags; } - ecma_value_t coercible = ecma_op_check_object_coercible (get_flags); - - if (ECMA_IS_VALUE_ERROR (coercible)) + if (!ecma_op_require_object_coercible (get_flags)) { ecma_free_value (get_flags); - return coercible; + return ECMA_VALUE_ERROR; } ecma_string_t *flags = ecma_op_to_string (get_flags); @@ -1381,11 +1379,9 @@ ecma_builtin_string_prototype_dispatch_routine (uint16_t builtin_routine_id, /** return ecma_builtin_string_prototype_object_to_string (this_arg); } - ecma_value_t coercible = ecma_op_check_object_coercible (this_arg); - - if (ECMA_IS_VALUE_ERROR (coercible)) + if (!ecma_op_require_object_coercible (this_arg)) { - return coercible; + return ECMA_VALUE_ERROR; } ecma_value_t arg1 = arguments_list_p[0]; diff --git a/jerry-core/ecma/operations/ecma-conversion.c b/jerry-core/ecma/operations/ecma-conversion.c index cabee3c14..93919a017 100644 --- a/jerry-core/ecma/operations/ecma-conversion.c +++ b/jerry-core/ecma/operations/ecma-conversion.c @@ -44,29 +44,27 @@ */ /** - * CheckObjectCoercible operation. + * RequireObjectCoercible operation. * * See also: - * ECMA-262 v5, 9.10 + * ECMA-262 v11, 7.2.1 * - * @return ecma value - * Returned value must be freed with ecma_free_value + * @return true - if the value can be coerced to object without any exceptions + * false - otherwise */ -ecma_value_t -ecma_op_check_object_coercible (ecma_value_t value) /**< ecma value */ +bool +ecma_op_require_object_coercible (ecma_value_t value) /**< ecma value */ { ecma_check_value_type_is_spec_defined (value); - if (ecma_is_value_undefined (value) - || ecma_is_value_null (value)) + if (ecma_is_value_undefined (value) || ecma_is_value_null (value)) { - return ecma_raise_type_error (ECMA_ERR_MSG ("Argument cannot be converted to an object.")); + ecma_raise_type_error (ECMA_ERR_MSG ("Argument cannot be converted to an object.")); + return false; } - else - { - return ECMA_VALUE_EMPTY; - } -} /* ecma_op_check_object_coercible */ + + return true; +} /* ecma_op_require_object_coercible */ /** * SameValue operation. diff --git a/jerry-core/ecma/operations/ecma-conversion.h b/jerry-core/ecma/operations/ecma-conversion.h index 503eb79a7..8580b1b6b 100644 --- a/jerry-core/ecma/operations/ecma-conversion.h +++ b/jerry-core/ecma/operations/ecma-conversion.h @@ -46,7 +46,7 @@ typedef enum ECMA_TO_NUMERIC_ALLOW_BIGINT = (1 << 0), /**< allow BigInt values (ignored if BigInts are disabled) */ } ecma_to_numeric_options_t; -ecma_value_t ecma_op_check_object_coercible (ecma_value_t value); +bool ecma_op_require_object_coercible (ecma_value_t value); bool ecma_op_same_value (ecma_value_t x, ecma_value_t y); #if ENABLED (JERRY_BUILTIN_MAP) bool ecma_op_same_value_zero (ecma_value_t x, ecma_value_t y, bool strict_equality); diff --git a/jerry-core/vm/opcodes.c b/jerry-core/vm/opcodes.c index 1bc46dffc..6a56d468e 100644 --- a/jerry-core/vm/opcodes.c +++ b/jerry-core/vm/opcodes.c @@ -255,12 +255,10 @@ vm_op_delete_prop (ecma_value_t object, /**< base object */ } #endif /* !ENABLED (JERRY_ESNEXT) */ - ecma_value_t check_coercible = ecma_op_check_object_coercible (object); - if (ECMA_IS_VALUE_ERROR (check_coercible)) + if (!ecma_op_require_object_coercible (object)) { - return check_coercible; + return ECMA_VALUE_ERROR; } - JERRY_ASSERT (check_coercible == ECMA_VALUE_EMPTY); ecma_string_t *name_string_p = ecma_op_to_property_key (property); @@ -270,7 +268,7 @@ vm_op_delete_prop (ecma_value_t object, /**< base object */ } ecma_value_t obj_value = ecma_op_to_object (object); - /* The ecma_op_check_object_coercible call already checked the op_to_object error cases. */ + /* The ecma_op_require_object_coercible call already checked the op_to_object error cases. */ JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_value)); JERRY_ASSERT (ecma_is_value_object (obj_value)); ecma_object_t *obj_p = ecma_get_object_from_value (obj_value); @@ -1394,7 +1392,7 @@ opfunc_form_super_reference (ecma_value_t **vm_stack_top_p, /**< current vm stac return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot invoke nullable super method.")); } - if (ECMA_IS_VALUE_ERROR (ecma_op_check_object_coercible (parent))) + if (!ecma_op_require_object_coercible (parent)) { return ECMA_VALUE_ERROR; } diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index 9744bece9..73989dbaf 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -2478,10 +2478,9 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ } case VM_OC_REQUIRE_OBJECT_COERCIBLE: { - result = ecma_op_check_object_coercible (stack_top_p[-1]); - - if (ECMA_IS_VALUE_ERROR (result)) + if (!ecma_op_require_object_coercible (stack_top_p[-1])) { + result = ECMA_VALUE_ERROR; goto error; } continue;