Refactor ecma_op_check_object_coercible (#4169)

The method returns bool now instead of an ecma_value_t

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam 2020-08-28 13:12:50 +02:00 committed by GitHub
parent e98f5342f9
commit 9589771f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 39 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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];

View File

@ -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.

View File

@ -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);

View File

@ -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;
}

View File

@ -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;