Reorganize property descriptor flags (#4622)
Furthermore rename JERRY_PROP_IS_THROW to JERRY_PROP_SHOULD_THROW and add more invalid descriptor checks. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -396,16 +396,18 @@ typedef enum
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_PROPERTY_FLAG_DELETED = 1u << 0, /**< property is deleted */
|
||||
ECMA_FAST_ARRAY_FLAG = 1u << 0, /**< array is fast array */
|
||||
ECMA_PROPERTY_FLAG_LCACHED = 1u << 1, /**< property is lcached */
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE = (1u << 0), /**< property is configurable */
|
||||
ECMA_PROPERTY_FLAG_ENUMERABLE = (1u << 1), /**< property is enumerable */
|
||||
ECMA_PROPERTY_FLAG_WRITABLE = (1u << 2), /**< property is writable */
|
||||
|
||||
ECMA_PROPERTY_FLAG_DELETED = (1u << 3), /**< property is deleted */
|
||||
ECMA_FAST_ARRAY_FLAG = (1u << 3), /**< array is fast array */
|
||||
ECMA_PROPERTY_FLAG_LCACHED = (1u << 4), /**< property is lcached */
|
||||
#if JERRY_ESNEXT
|
||||
ECMA_ARRAY_TEMPLATE_LITERAL = 1u << 1, /**< array is a template literal constructed by the parser */
|
||||
ECMA_ARRAY_TEMPLATE_LITERAL = (1u << 4), /**< array is a template literal constructed by the parser */
|
||||
#endif /* JERRY_ESNEXT */
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE = 1u << 2, /**< property is configurable */
|
||||
ECMA_PROPERTY_FLAG_ENUMERABLE = 1u << 3, /**< property is enumerable */
|
||||
ECMA_PROPERTY_FLAG_WRITABLE = 1u << 4, /**< property is writable */
|
||||
ECMA_PROPERTY_FLAG_DATA = 1u << 5, /**< property contains data */
|
||||
ECMA_PROPERTY_FLAG_DATA = (1u << 5), /**< property contains data */
|
||||
/* The last two bits contains an ECMA_DIRECT_STRING value. */
|
||||
} ecma_property_flags_t;
|
||||
|
||||
/**
|
||||
@@ -1181,18 +1183,19 @@ typedef struct
|
||||
typedef enum
|
||||
{
|
||||
ECMA_PROP_NO_OPTS = (0), /** empty property descriptor */
|
||||
ECMA_PROP_IS_GET_DEFINED = (1 << 0), /** Is [[Get]] defined? */
|
||||
ECMA_PROP_IS_SET_DEFINED = (1 << 1), /** Is [[Set]] defined? */
|
||||
ECMA_PROP_IS_CONFIGURABLE = (1 << 0), /** [[Configurable]] */
|
||||
ECMA_PROP_IS_ENUMERABLE = (1 << 1), /** [[Enumerable]] */
|
||||
ECMA_PROP_IS_WRITABLE = (1 << 2), /** [[Writable]] */
|
||||
|
||||
ECMA_PROP_IS_CONFIGURABLE = (1 << 2), /** [[Configurable]] */
|
||||
ECMA_PROP_IS_ENUMERABLE = (1 << 3), /** [[Enumerable]] */
|
||||
ECMA_PROP_IS_WRITABLE = (1 << 4), /** [[Writable]] */
|
||||
ECMA_PROP_IS_THROW = (1 << 5), /** Flag that controls failure handling */
|
||||
ECMA_PROP_IS_CONFIGURABLE_DEFINED = (1 << 3), /** is [[Configurable]] defined? */
|
||||
ECMA_PROP_IS_ENUMERABLE_DEFINED = (1 << 4), /** is [[Enumerable]] defined? */
|
||||
ECMA_PROP_IS_WRITABLE_DEFINED = (1 << 5), /** is [[Writable]] defined? */
|
||||
|
||||
ECMA_PROP_IS_VALUE_DEFINED = (1 << 6), /** Is [[Value]] defined? */
|
||||
ECMA_PROP_IS_CONFIGURABLE_DEFINED = (1 << 7), /** Is [[Configurable]] defined? */
|
||||
ECMA_PROP_IS_ENUMERABLE_DEFINED = (1 << 8), /** Is [[Enumerable]] defined? */
|
||||
ECMA_PROP_IS_WRITABLE_DEFINED = (1 << 9), /** Is [[Writable]] defined? */
|
||||
ECMA_PROP_IS_VALUE_DEFINED = (1 << 6), /** is [[Value]] defined? */
|
||||
ECMA_PROP_IS_GET_DEFINED = (1 << 7), /** is [[Get]] defined? */
|
||||
ECMA_PROP_IS_SET_DEFINED = (1 << 8), /** is [[Set]] defined? */
|
||||
|
||||
ECMA_PROP_SHOULD_THROW = (1 << 9), /** should throw on error, instead of returning with false */
|
||||
} ecma_property_descriptor_status_flags_t;
|
||||
|
||||
/**
|
||||
@@ -1203,7 +1206,7 @@ typedef enum
|
||||
* Note:
|
||||
* If a component of descriptor is undefined then corresponding
|
||||
* field should contain it's default value.
|
||||
* The struct members must be in this order or keep in sync with ecma_property_flags_t and ECMA_IS_THROW flag.
|
||||
* The struct members must be in this order or keep in sync with ecma_property_descriptor_status_flags_t.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@@ -1242,13 +1245,6 @@ typedef struct
|
||||
| ECMA_PROP_IS_ENUMERABLE \
|
||||
| ECMA_PROP_IS_WRITABLE))
|
||||
|
||||
/**
|
||||
* Flag that controls failure handling during defining property
|
||||
*
|
||||
* Note: This flags represents the [[DefineOwnProperty]] (P, Desc, Throw) 3rd argument
|
||||
*/
|
||||
#define ECMA_IS_THROW ((uint8_t) ECMA_PROP_IS_THROW)
|
||||
|
||||
#if !JERRY_NUMBER_TYPE_FLOAT64
|
||||
/**
|
||||
* Description of an ecma-number
|
||||
|
||||
@@ -934,7 +934,7 @@ ecma_builtin_array_prototype_object_slice (ecma_value_t arg1, /**< start */
|
||||
/* 10.c.ii */
|
||||
ecma_value_t put_comp;
|
||||
#if JERRY_ESNEXT
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
#else /* !JERRY_ESNEXT */
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE;
|
||||
#endif /* JERRY_ESNEXT */
|
||||
@@ -1328,7 +1328,7 @@ ecma_builtin_array_prototype_object_splice (const ecma_value_t args[], /**< argu
|
||||
if (ecma_is_value_found (from_present))
|
||||
{
|
||||
#if JERRY_ESNEXT
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
#else /* !JERRY_ESNEXT */
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE;
|
||||
#endif /* JERRY_ESNEXT */
|
||||
@@ -1982,7 +1982,7 @@ ecma_builtin_array_prototype_object_map (ecma_value_t arg1, /**< callbackfn */
|
||||
/* 8.c.iii */
|
||||
ecma_value_t put_comp;
|
||||
#if JERRY_ESNEXT
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
#else /* !JERRY_ESNEXT */
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE;
|
||||
#endif /* JERRY_ESNEXT */
|
||||
@@ -2039,7 +2039,7 @@ ecma_builtin_array_prototype_object_filter (ecma_value_t arg1, /**< callbackfn *
|
||||
}
|
||||
|
||||
/* ES11: 22.1.3.7. 7.c.iii.1 */
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
#else /* !JERRY_ESNEXT */
|
||||
ecma_object_t *new_array_p = ecma_op_new_array_object (0);
|
||||
|
||||
@@ -2749,7 +2749,7 @@ ecma_builtin_array_flatten_into_array (ecma_value_t target, /**< target will con
|
||||
}
|
||||
|
||||
/* vi. */
|
||||
const uint8_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
ecma_value_t element_temp = ecma_builtin_helper_def_prop_by_index (ecma_get_object_from_value (target),
|
||||
target_index,
|
||||
element,
|
||||
|
||||
@@ -239,7 +239,7 @@ ecma_builtin_array_object_from (ecma_value_t this_arg, /**< 'this' argument */
|
||||
}
|
||||
|
||||
/* 6.g.ix */
|
||||
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
ecma_value_t set_status = ecma_builtin_helper_def_prop_by_index (array_obj_p, k, mapped_value, flags);
|
||||
|
||||
ecma_free_value (mapped_value);
|
||||
@@ -359,7 +359,7 @@ iterator_cleanup:
|
||||
}
|
||||
|
||||
/* 16.f */
|
||||
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
ecma_value_t set_status = ecma_builtin_helper_def_prop_by_index (array_obj_p, k, mapped_value, flags);
|
||||
|
||||
ecma_free_value (mapped_value);
|
||||
@@ -433,7 +433,7 @@ ecma_builtin_array_object_of (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
uint32_t k = 0;
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (ret_val);
|
||||
const uint32_t prop_status_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t prop_status_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
while (k < arguments_list_len)
|
||||
{
|
||||
|
||||
@@ -346,7 +346,7 @@ ecma_builtin_helper_array_concat_value (ecma_object_t *array_obj_p, /**< array *
|
||||
|
||||
bool spread_object = is_spreadable == ECMA_VALUE_TRUE;
|
||||
/* ES11: 22.1.3.1.5.c.iv.3.b */
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
#else /* !JERRY_ESNEXT */
|
||||
/* ES5.1: 15.4.4.4.5.b.iii.3.b */
|
||||
const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE;
|
||||
@@ -831,8 +831,7 @@ ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *name_p, /**< name string */
|
||||
ecma_value_t value, /**< value */
|
||||
uint32_t opts) /**< any combination of ecma_property_flag_t bits
|
||||
* with the optional ECMA_IS_THROW flag */
|
||||
uint32_t opts) /**< any combination of ecma_property_descriptor_status_flags_t bits */
|
||||
{
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ ecma_builtin_object_prototype_define_getter_setter (ecma_value_t this_arg, /**<
|
||||
| ECMA_PROP_IS_CONFIGURABLE
|
||||
| ECMA_PROP_IS_ENUMERABLE_DEFINED
|
||||
| ECMA_PROP_IS_CONFIGURABLE_DEFINED
|
||||
| ECMA_PROP_IS_THROW);
|
||||
| ECMA_PROP_SHOULD_THROW);
|
||||
|
||||
if (define_getter)
|
||||
{
|
||||
|
||||
@@ -371,7 +371,7 @@ ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */
|
||||
}
|
||||
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
prop_desc.flags |= ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
/* 8.a.i */
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
@@ -422,7 +422,7 @@ ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */
|
||||
}
|
||||
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
prop_desc.flags |= ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
/* 9.3 */
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
@@ -881,7 +881,7 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
||||
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
|
||||
&property_descriptors[property_descriptor_number]);
|
||||
|
||||
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_IS_THROW;
|
||||
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
ecma_free_value (desc_obj);
|
||||
|
||||
@@ -1009,7 +1009,7 @@ ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's
|
||||
return conv_result;
|
||||
}
|
||||
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
prop_desc.flags |= ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
name_str_p,
|
||||
|
||||
@@ -314,7 +314,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this */
|
||||
ecma_value_t status = ecma_builtin_helper_def_prop (this_obj_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
|
||||
ecma_make_uint32_value (0),
|
||||
ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_IS_THROW);
|
||||
ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_SHOULD_THROW);
|
||||
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
|
||||
|
||||
|
||||
@@ -1165,7 +1165,7 @@ ecma_op_array_object_define_own_property (ecma_object_t *object_p, /**< the arra
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
prop_desc = *property_desc_p;
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_THROW;
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
ecma_value_t completition = ecma_op_general_object_define_own_property (object_p,
|
||||
property_name_p,
|
||||
|
||||
@@ -206,7 +206,7 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme
|
||||
}
|
||||
#endif /* JERRY_BUILTIN_PROXY && JERRY_BUILTIN_REALMS */
|
||||
|
||||
const uint32_t flags = ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||
const uint32_t flags = ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
|
||||
ecma_value_t completion = ecma_builtin_helper_def_prop (binding_obj_p,
|
||||
name_p,
|
||||
|
||||
@@ -367,7 +367,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
|
||||
if (!ecma_op_ordinary_object_is_extensible (object_p))
|
||||
{
|
||||
/* 2. */
|
||||
return ECMA_REJECT_WITH_FORMAT (property_desc_p->flags & ECMA_PROP_IS_THROW,
|
||||
return ECMA_REJECT_WITH_FORMAT (property_desc_p->flags & ECMA_PROP_SHOULD_THROW,
|
||||
"Cannot define property '%', object is not extensible",
|
||||
ecma_make_prop_name_value (property_name_p));
|
||||
}
|
||||
|
||||
@@ -1546,10 +1546,8 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS
|
||||
&& ext_object_p->u.pseudo_array.extra_info & ECMA_ARGUMENTS_OBJECT_MAPPED)
|
||||
{
|
||||
return ecma_builtin_helper_def_prop (object_p,
|
||||
property_name_p,
|
||||
value,
|
||||
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW);
|
||||
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROP_SHOULD_THROW;
|
||||
return ecma_builtin_helper_def_prop (object_p, property_name_p, value, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3321,7 +3319,7 @@ ecma_op_object_unref_weak (ecma_object_t *object_p, /**< this argument */
|
||||
/**
|
||||
* Raise property redefinition error
|
||||
*
|
||||
* @return ECMA_VALUE_FALSE - if ECMA_IS_THROW is not set
|
||||
* @return ECMA_VALUE_FALSE - if ECMA_PROP_SHOULD_THROW is not set
|
||||
* raised TypeError - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
@@ -3330,7 +3328,7 @@ ecma_raise_property_redefinition (ecma_string_t *property_name_p, /**< property
|
||||
{
|
||||
JERRY_UNUSED (property_name_p);
|
||||
|
||||
return ECMA_REJECT_WITH_FORMAT (flags & ECMA_PROP_IS_THROW,
|
||||
return ECMA_REJECT_WITH_FORMAT (flags & ECMA_PROP_SHOULD_THROW,
|
||||
"Cannot redefine property '%'",
|
||||
ecma_make_prop_name_value (property_name_p));
|
||||
} /* ecma_raise_property_redefinition */
|
||||
|
||||
@@ -249,7 +249,7 @@ ecma_op_regexp_alloc (ecma_object_t *ctr_obj_p) /**< constructor object pointer
|
||||
ecma_value_t status = ecma_builtin_helper_def_prop (new_object_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
|
||||
ecma_make_uint32_value (0),
|
||||
ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_IS_THROW);
|
||||
ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_SHOULD_THROW);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (status));
|
||||
|
||||
|
||||
@@ -1570,7 +1570,7 @@ ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedA
|
||||
* See also: ES2015 9.4.5.3
|
||||
*
|
||||
* @return ECMA_VALUE_TRUE - if the property is successfully defined
|
||||
* ECMA_VALUE_FALSE - if is ECMA_IS_THROW is not set
|
||||
* ECMA_VALUE_FALSE - if is ECMA_PROP_SHOULD_THROW is not set
|
||||
* raised TypeError - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
@@ -1601,7 +1601,7 @@ ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, /**< TypedArray ob
|
||||
|
||||
if (array_index >= info.length)
|
||||
{
|
||||
return ECMA_REJECT ((property_desc_p->flags & ECMA_PROP_IS_THROW), "Invalid typed array index");
|
||||
return ECMA_REJECT ((property_desc_p->flags & ECMA_PROP_SHOULD_THROW), "Invalid typed array index");
|
||||
}
|
||||
|
||||
if (property_desc_p->flags & ECMA_PROP_IS_VALUE_DEFINED)
|
||||
@@ -1625,7 +1625,7 @@ ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, /**< TypedArray ob
|
||||
|
||||
if (is_same)
|
||||
{
|
||||
return ECMA_REJECT ((property_desc_p->flags & ECMA_PROP_IS_THROW), "Invalid typed array index");
|
||||
return ECMA_REJECT ((property_desc_p->flags & ECMA_PROP_SHOULD_THROW), "Invalid typed array index");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user