Implement the core of Proxy object (#3562)

- Internal routines of the of the proxy object are unimplemented
 - For-in enumerate with proxy target is currently not supported

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2020-02-28 14:41:59 +01:00
committed by GitHub
parent 9b393ee2ea
commit 4e136c8973
57 changed files with 3017 additions and 397 deletions
@@ -426,7 +426,7 @@ ecma_builtin_array_prototype_object_pop (ecma_object_t *obj_p, /**< array object
if (ecma_op_object_is_fast_array (obj_p))
{
if (!ecma_get_object_extensible (obj_p))
if (!ecma_op_ordinary_object_is_extensible (obj_p))
{
ecma_free_value (get_value);
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));
@@ -479,7 +479,7 @@ ecma_builtin_array_prototype_object_push (const ecma_value_t *argument_list_p, /
if (ecma_op_object_is_fast_array (obj_p))
{
if (!ecma_get_object_extensible (obj_p))
if (!ecma_op_ordinary_object_is_extensible (obj_p))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));
}
@@ -554,7 +554,7 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
&& len != 0
&& ecma_get_object_extensible (obj_p))
&& ecma_op_ordinary_object_is_extensible (obj_p))
{
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
@@ -592,13 +592,30 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
if (ECMA_IS_VALUE_ERROR (upper_value))
{
upper_value = ECMA_VALUE_EMPTY;
goto clean_up;
}
/* 6.f and 6.g */
bool lower_exist = ecma_op_object_has_property (obj_p, lower_str_p);
bool upper_exist = ecma_op_object_has_property (obj_p, upper_str_p);
ecma_value_t has_lower = ecma_op_object_has_property (obj_p, lower_str_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (has_lower))
{
goto clean_up;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t has_upper = ecma_op_object_has_property (obj_p, upper_str_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (has_upper))
{
goto clean_up;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
bool lower_exist = ecma_is_value_true (has_lower);
bool upper_exist = ecma_is_value_true (has_upper);
/* 6.h */
if (lower_exist && upper_exist)
@@ -699,7 +716,7 @@ ecma_builtin_array_prototype_object_shift (ecma_object_t *obj_p, /**< array obje
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
&& len != 0
&& ecma_get_object_extensible (obj_p))
&& ecma_op_ordinary_object_is_extensible (obj_p))
{
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
ecma_value_t ret_value = buffer_p[0];
@@ -1069,6 +1086,13 @@ ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argum
ecma_collection_t *array_index_props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ARRAY_INDICES);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (array_index_props_p == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
uint32_t defined_prop_count = 0;
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
@@ -1482,7 +1506,7 @@ ecma_builtin_array_prototype_object_unshift (const ecma_value_t args[], /**< arg
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
&& len != 0
&& ecma_get_object_extensible (obj_p))
&& ecma_op_ordinary_object_is_extensible (obj_p))
{
if ((ecma_number_t) (len + args_number) > UINT32_MAX)
{
@@ -2236,12 +2260,8 @@ ecma_builtin_array_prototype_fill (ecma_value_t value, /**< value */
/* 11. */
while (k < final)
{
/* 11.a */
ecma_string_t *pk = ecma_new_ecma_string_from_number (k);
/* 11.b */
ecma_value_t put_val = ecma_op_object_put (obj_p, pk, value, true);
ecma_deref_ecma_string (pk);
/* 11.a - 11.b */
ecma_value_t put_val = ecma_op_object_put_by_number_index (obj_p, k, value, true);
/* 11. c */
if (ECMA_IS_VALUE_ERROR (put_val))
@@ -23,6 +23,7 @@
#include "ecma-helpers.h"
#include "ecma-function-object.h"
#include "ecma-objects.h"
#include "ecma-proxy-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#include "ecma-builtin-function-prototype.h"
@@ -210,11 +211,37 @@ ecma_builtin_function_prototype_object_bind (ecma_object_t *this_arg_obj_p , /**
/* 4. 11. 18. */
ecma_object_t *prototype_obj_p;
#if ENABLED (JERRY_ES2015)
prototype_obj_p = ECMA_GET_POINTER (ecma_object_t, this_arg_obj_p->u2.prototype_cp);
#else /* !ENABLED (JERRY_ES2015) */
#if !ENABLED (JERRY_ES2015)
prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
#endif /* ENABLED (JERRY_ES2015) */
#else /* ENABLED (JERRY_ES2015) */
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (this_arg_obj_p))
{
ecma_value_t proto = ecma_proxy_object_get_prototype_of (this_arg_obj_p);
if (ECMA_IS_VALUE_ERROR (proto))
{
return proto;
}
prototype_obj_p = ecma_is_value_null (proto) ? NULL : ecma_get_object_from_value (proto);
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (this_arg_obj_p);
if (proto_cp != JMEM_CP_NULL)
{
prototype_obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
ecma_ref_object (prototype_obj_p);
}
else
{
prototype_obj_p = NULL;
}
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
#endif /* !ENABLED (JERRY_ES2015) */
ecma_object_t *function_p;
ecma_extended_object_t *ext_function_p;
@@ -267,6 +294,13 @@ ecma_builtin_function_prototype_object_bind (ecma_object_t *this_arg_obj_p , /**
ext_function_p->u.bound_function.args_len_or_this = args_len_or_this;
}
#if ENABLED (JERRY_ES2015)
if (prototype_obj_p != NULL)
{
ecma_deref_object (prototype_obj_p);
}
#endif /* ENABLED (JERRY_ES2015) */
/*
* [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_FUNCTION type.
*
@@ -246,6 +246,13 @@ OBJECT_VALUE (LIT_MAGIC_STRING_DATAVIEW_UL,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
/* ECMA-262 v6, 26.2.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROXY_UL,
ECMA_BUILTIN_ID_PROXY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
@@ -280,26 +280,23 @@ ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
{
JERRY_ASSERT (obj_p != NULL);
ecma_value_t new_array = ecma_op_create_array_object (NULL, 0, false);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
ecma_object_t *new_array_p = ecma_get_object_from_value (new_array);
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (props_p == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (props_p->item_count == 0)
{
ecma_collection_destroy (props_p);
return new_array;
return ecma_op_create_array_object (NULL, 0, false);
}
JERRY_ASSERT (ecma_op_object_is_fast_array (new_array_p));
ecma_value_t *buffer_p = props_p->buffer_p;
ecma_value_t *values_p = ecma_fast_array_extend (new_array_p, props_p->item_count);
memcpy (values_p, buffer_p, props_p->item_count * sizeof (ecma_value_t));
ecma_collection_free_objects (props_p);
ecma_value_t new_array = ecma_op_create_array_object (props_p->buffer_p, props_p->item_count, false);
ecma_collection_free (props_p);
return new_array;
} /* ecma_builtin_helper_object_get_properties */
@@ -904,6 +904,13 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
else
{
property_keys_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (property_keys_p == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
}
/* 8. */
@@ -23,6 +23,7 @@
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-proxy-object.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
@@ -143,7 +144,23 @@ static ecma_value_t
ecma_builtin_object_prototype_object_has_own_property (ecma_object_t *obj_p, /**< this argument */
ecma_string_t *prop_name_p) /**< first argument */
{
return ecma_make_boolean_value (ecma_op_object_has_own_property (obj_p, prop_name_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
ecma_property_descriptor_t prop_desc;
ecma_value_t status = ecma_proxy_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
if (ecma_is_value_true (status))
{
ecma_free_property_descriptor (&prop_desc);
}
return status;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
return ecma_make_boolean_value (ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p));
} /* ecma_builtin_object_prototype_object_has_own_property */
/**
@@ -169,7 +186,7 @@ ecma_builtin_object_prototype_object_is_prototype_of (ecma_object_t *obj_p, /**<
ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value);
ecma_value_t ret_value = ecma_make_boolean_value (ecma_op_object_is_prototype_of (obj_p, v_obj_p));
ecma_value_t ret_value = ecma_op_object_is_prototype_of (obj_p, v_obj_p);
ecma_deref_object (v_obj_p);
@@ -189,19 +206,19 @@ static ecma_value_t
ecma_builtin_object_prototype_object_property_is_enumerable (ecma_object_t *obj_p, /**< this argument */
ecma_string_t *prop_name_p) /**< first argument */
{
/* 3. */
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
prop_name_p,
NULL,
ECMA_PROPERTY_GET_NO_OPTIONS);
ecma_property_descriptor_t prop_desc;
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
/* 4. */
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
if (!ecma_is_value_true (status))
{
return ecma_make_boolean_value (ecma_is_property_enumerable (property));
return status;
}
return ECMA_VALUE_FALSE;
bool is_enumerable = (prop_desc.flags & ECMA_PROP_IS_ENUMERABLE);
ecma_free_property_descriptor (&prop_desc);
return ecma_make_boolean_value (is_enumerable);
} /* ecma_builtin_object_prototype_object_property_is_enumerable */
/**
@@ -22,6 +22,7 @@
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-proxy-object.h"
#include "ecma-objects-general.h"
#include "jrt.h"
#include "ecma-builtin-object.h"
@@ -136,11 +137,18 @@ ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /*
ecma_value_t
ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p) /**< routine's argument */
{
jmem_cpointer_t prototype_cp = obj_p->u2.prototype_cp;
if (prototype_cp != JMEM_CP_NULL)
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, prototype_cp);
return ecma_proxy_object_get_prototype_of (obj_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (obj_p);
if (proto_cp != JMEM_CP_NULL)
{
ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
ecma_ref_object (prototype_p);
return ecma_make_object_value (prototype_p);
}
@@ -149,77 +157,6 @@ ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p) /**< routine'
} /* ecma_builtin_object_object_get_prototype_of */
#if ENABLED (JERRY_ES2015)
/**
* [[SetPrototypeOf]]
*
* See also:
* ES2015 9.1.2
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_set_prototype_of (ecma_value_t o_value, /**< O */
ecma_value_t v_value) /**< V */
{
/* 1. */
JERRY_ASSERT (ecma_is_value_object (o_value));
JERRY_ASSERT (ecma_is_value_object (v_value) || ecma_is_value_null (v_value));
ecma_object_t *o_p = ecma_get_object_from_value (o_value);
jmem_cpointer_t v_cp;
if (ecma_is_value_null (v_value))
{
v_cp = JMEM_CP_NULL;
}
else
{
ECMA_SET_NON_NULL_POINTER (v_cp, ecma_get_object_from_value (v_value));
}
/* 3., 4. */
if (v_cp == o_p->u2.prototype_cp)
{
ecma_ref_object (o_p);
return ecma_make_object_value (o_p);
}
/* 2., 5. */
if (!ecma_get_object_extensible (o_p))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("cannot set prototype."));
}
/* 6., 7., 8. */
jmem_cpointer_t p_cp = v_cp;
while (p_cp != JMEM_CP_NULL)
{
ecma_object_t *p_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, p_cp);
/* b. */
if (p_p == o_p)
{
return ecma_raise_type_error (ECMA_ERR_MSG ("cannot set prototype."));
}
/* c.i. TODO: es2015-subset profile does not support having a different
* [[GetPrototypeOf]] internal method */
/* c.ii. */
p_cp = p_p->u2.prototype_cp;
}
/* 9. */
o_p->u2.prototype_cp = v_cp;
/* 10. */
ecma_ref_object (o_p);
return ecma_make_object_value (o_p);
} /* ecma_set_prototype_of */
/**
* The Object object's 'setPrototypeOf' routine
*
@@ -251,11 +188,37 @@ ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's f
return ecma_copy_value (arg1);
}
/* 6. TODO: es2015-subset profile does not support having a different
* [[SetPrototypeOf]] internal method */
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
ecma_value_t status;
/* 5-8. */
return ecma_set_prototype_of (arg1, arg2);
/* 5. */
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
status = ecma_proxy_object_set_prototype_of (obj_p, arg2);
if (ECMA_IS_VALUE_ERROR (status))
{
return status;
}
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
status = ecma_op_ordinary_object_set_prototype_of (obj_p, arg2);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_false (status))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot set [[Prototype]]."));
}
JERRY_ASSERT (ecma_is_value_true (status));
ecma_ref_object (obj_p);
return arg1;
} /* ecma_builtin_object_object_set_prototype_of */
#endif /* ENABLED (JERRY_ES2015) */
@@ -294,6 +257,150 @@ ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**<
#endif /* ENABLED (JERRY_ES2015) */
/**
* SetIntegrityLevel operation
*
* See also:
* ECMA-262 v6, 7.3.14
*
* @return ECMA_VALUE_ERROR - if the operation raised an error
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the integrity level has been set sucessfully
*/
static ecma_value_t
ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */
bool is_seal) /**< true - set "sealed"
* false - set "frozen" */
{
/* 3. */
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
ecma_value_t status = ecma_proxy_object_prevent_extensions (obj_p);
if (!ecma_is_value_true (status))
{
return status;
}
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_op_ordinary_object_prevent_extensions (obj_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/* 6. */
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (props_p == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t *buffer_p = props_p->buffer_p;
if (is_seal)
{
/* 8.a */
for (uint32_t i = 0; i < props_p->item_count; i++)
{
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
ecma_property_descriptor_t prop_desc;
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (status))
{
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_false (status))
{
continue;
}
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
prop_desc.flags |= ECMA_PROP_IS_THROW;
/* 8.a.i */
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
property_name_p,
&prop_desc);
ecma_free_property_descriptor (&prop_desc);
/* 8.a.ii */
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
{
ecma_collection_free (props_p);
return define_own_prop_ret;
}
ecma_free_value (define_own_prop_ret);
}
}
else
{
/* 9.a */
for (uint32_t i = 0; i < props_p->item_count; i++)
{
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
/* 9.1 */
ecma_property_descriptor_t prop_desc;
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (status))
{
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_false (status))
{
continue;
}
/* 9.2 */
if ((prop_desc.flags & (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
== (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
{
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_WRITABLE;
}
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
prop_desc.flags |= ECMA_PROP_IS_THROW;
/* 9.3 */
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
property_name_p,
&prop_desc);
ecma_free_property_descriptor (&prop_desc);
/* 9.4 */
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
{
ecma_collection_free (props_p);
return define_own_prop_ret;
}
ecma_free_value (define_own_prop_ret);
}
}
ecma_collection_free (props_p);
return ECMA_VALUE_TRUE;
} /* ecma_builtin_object_set_integrity_level */
/**
* The Object object's 'seal' routine
*
@@ -306,46 +413,19 @@ ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**<
static ecma_value_t
ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument */
{
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
ecma_value_t status = ecma_builtin_object_set_integrity_level (obj_p, true);
ecma_value_t *buffer_p = props_p->buffer_p;
for (uint32_t i = 0; i < props_p->item_count; i++)
if (ECMA_IS_VALUE_ERROR (status))
{
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
/* 2.a */
ecma_property_descriptor_t prop_desc;
if (!ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc))
{
continue;
}
/* 2.b */
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
prop_desc.flags |= ECMA_PROP_IS_THROW;
/* 2.c */
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
property_name_p,
&prop_desc);
ecma_free_property_descriptor (&prop_desc);
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
{
ecma_collection_free (props_p);
return define_own_prop_ret;
}
ecma_free_value (define_own_prop_ret);
return status;
}
ecma_collection_free (props_p);
/* 3. */
ecma_set_object_extensible (obj_p, false);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ecma_is_value_false (status))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Object cannot be sealed."));
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/* 4. */
ecma_ref_object (obj_p);
@@ -364,53 +444,19 @@ ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument *
static ecma_value_t
ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument */
{
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
ecma_value_t status = ecma_builtin_object_set_integrity_level (obj_p, false);
ecma_value_t *buffer_p = props_p->buffer_p;
for (uint32_t i = 0; i < props_p->item_count; i++)
if (ECMA_IS_VALUE_ERROR (status))
{
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
/* 2.a */
ecma_property_descriptor_t prop_desc;
if (!ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc))
{
continue;
}
/* 2.b */
if ((prop_desc.flags & (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
== (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
{
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_WRITABLE;
}
/* 2.c */
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
prop_desc.flags |= ECMA_PROP_IS_THROW;
/* 2.d */
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
property_name_p,
&prop_desc);
ecma_free_property_descriptor (&prop_desc);
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
{
ecma_collection_free (props_p);
return define_own_prop_ret;
}
ecma_free_value (define_own_prop_ret);
return status;
}
ecma_collection_free (props_p);
/* 3. */
ecma_set_object_extensible (obj_p, false);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ecma_is_value_false (status))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Object cannot be frozen."));
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/* 4. */
ecma_ref_object (obj_p);
@@ -429,7 +475,30 @@ ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument
ecma_value_t
ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routine's argument */
{
ecma_set_object_extensible (obj_p, false);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
ecma_value_t status = ecma_proxy_object_prevent_extensions (obj_p);
if (ECMA_IS_VALUE_ERROR (status))
{
return status;
}
if (ecma_is_value_false (status))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot set [[Extensible]] property of the object."));
}
JERRY_ASSERT (ecma_is_value_true (status));
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_op_ordinary_object_prevent_extensions (obj_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_ref_object (obj_p);
return ecma_make_object_value (obj_p);
@@ -446,13 +515,34 @@ ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routin
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine's argument */
int mode) /**< routine mode */
ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's argument */
int mode) /**< routine mode */
{
JERRY_ASSERT (mode == ECMA_OBJECT_ROUTINE_IS_FROZEN || mode == ECMA_OBJECT_ROUTINE_IS_SEALED);
/* 3. */
if (ecma_get_object_extensible (obj_p))
bool is_extensible;
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
ecma_value_t status = ecma_proxy_object_is_extensible (obj_p);
if (ECMA_IS_VALUE_ERROR (status))
{
return status;
}
is_extensible = ecma_is_value_true (status);
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
is_extensible = ecma_op_ordinary_object_is_extensible (obj_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (is_extensible)
{
return ECMA_VALUE_FALSE;
}
@@ -463,6 +553,13 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
/* 2. */
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (props_p == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t *buffer_p = props_p->buffer_p;
for (uint32_t i = 0; i < props_p->item_count; i++)
@@ -470,22 +567,32 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
/* 2.a */
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
property_name_p,
NULL,
ECMA_PROPERTY_GET_NO_OPTIONS);
ecma_property_descriptor_t prop_desc;
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc);
/* 2.b for isFrozen */
if (mode == ECMA_OBJECT_ROUTINE_IS_FROZEN
&& ECMA_PROPERTY_GET_TYPE (property) != ECMA_PROPERTY_TYPE_NAMEDACCESSOR
&& ecma_is_property_writable (property))
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (status))
{
ret_value = ECMA_VALUE_FALSE;
ret_value = status;
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_false (status))
{
continue;
}
bool is_writable_data = ((prop_desc.flags & (ECMA_PROP_IS_VALUE_DEFINED | ECMA_PROP_IS_WRITABLE))
== (ECMA_PROP_IS_VALUE_DEFINED | ECMA_PROP_IS_WRITABLE));
bool is_configurable = (prop_desc.flags & ECMA_PROP_IS_CONFIGURABLE);
ecma_free_property_descriptor (&prop_desc);
/* 2.b for isFrozen */
/* 2.b for isSealed, 2.c for isFrozen */
if (ecma_is_property_configurable (property))
if ((mode == ECMA_OBJECT_ROUTINE_IS_FROZEN && is_writable_data)
|| is_configurable)
{
ret_value = ECMA_VALUE_FALSE;
break;
@@ -495,7 +602,7 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
ecma_collection_free (props_p);
return ret_value;
} /* ecma_builtin_object_frozen_or_sealed_helper */
} /* ecma_builtin_object_test_integrity_level */
/**
* The Object object's 'isExtensible' routine
@@ -509,7 +616,14 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
ecma_value_t
ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p) /**< routine's argument */
{
return ecma_make_boolean_value (ecma_get_object_extensible (obj_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
return ecma_proxy_object_is_extensible (obj_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
return ecma_make_boolean_value (ecma_op_ordinary_object_is_extensible (obj_p));
} /* ecma_builtin_object_object_is_extensible */
/**
@@ -543,7 +657,16 @@ ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, /*
/* 3. */
ecma_property_descriptor_t prop_desc;
if (ecma_op_object_get_own_property_descriptor (obj_p, name_str_p, &prop_desc))
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, name_str_p, &prop_desc);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (status))
{
return status;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_true (status))
{
/* 4. */
ecma_object_t *desc_obj_p = ecma_op_from_property_descriptor (&prop_desc);
@@ -583,6 +706,14 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
| ECMA_LIST_ENUMERABLE);
ecma_value_t ret_value = ECMA_VALUE_ERROR;
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (prop_names_p == NULL)
{
ecma_deref_object (props_p);
return ret_value;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t *buffer_p = prop_names_p->buffer_p;
/* 4. */
@@ -783,6 +914,13 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
| ECMA_LIST_ENUMERABLE
| ECMA_LIST_SYMBOLS);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (props_p == NULL)
{
ecma_deref_object (from_obj_p);
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t *buffer_p = props_p->buffer_p;
@@ -792,8 +930,17 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
/* 5.c.i-ii */
ecma_property_descriptor_t prop_desc;
ecma_value_t desc_status = ecma_op_object_get_own_property_descriptor (from_obj_p, property_name_p, &prop_desc);
if (!ecma_op_object_get_own_property_descriptor (from_obj_p, property_name_p, &prop_desc))
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (desc_status))
{
ret_value = desc_status;
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_false (desc_status))
{
continue;
}
@@ -1056,8 +1203,7 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
case ECMA_OBJECT_ROUTINE_IS_SEALED:
case ECMA_OBJECT_ROUTINE_IS_FROZEN:
{
return ecma_builtin_object_frozen_or_sealed_helper (obj_p,
builtin_routine_id);
return ecma_builtin_object_test_integrity_level (obj_p, builtin_routine_id);
}
case ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE:
{
@@ -0,0 +1,120 @@
/* 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.
*/
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-proxy-object.h"
#include "jrt.h"
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-proxy.inc.h"
#define BUILTIN_UNDERSCORED_ID proxy
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup proxy ECMA Proxy object built-in
* @{
*/
/**
* The Proxy object's 'revocable' routine
*
* See also:
* ES2015 26.2.2.1
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_proxy_object_revocable (ecma_value_t this_arg, /**< 'this' argument */
ecma_value_t target, /**< target argument */
ecma_value_t handler) /**< handler argument */
{
JERRY_UNUSED (this_arg);
ecma_object_t *rev_proxy_p = ecma_proxy_create_revocable (target, handler);
if (JERRY_UNLIKELY (rev_proxy_p == NULL))
{
return ECMA_VALUE_ERROR;
}
return ecma_make_object_value (rev_proxy_p);
} /* ecma_builtin_proxy_object_revocable */
/**
* Handle calling [[Call]] of built-in Proxy object
*
* See also:
* ES2015 26.2.2
*
* @return raised error
*/
ecma_value_t
ecma_builtin_proxy_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
/* 1. */
return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor Proxy requires 'new'"));
} /* ecma_builtin_proxy_dispatch_call */
/**
* Handle calling [[Construct]] of built-in proxy object
*
* See also:
* ES2015 26.2.2
*
* @return ECMA_VALUE_ERROR - if the operation fails
* new proxy object - otherwise
*/
ecma_value_t
ecma_builtin_proxy_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
/* 2. */
ecma_object_t *proxy_p = ecma_proxy_create (arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED,
arguments_list_len > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED);
if (JERRY_UNLIKELY (proxy_p == NULL))
{
return ECMA_VALUE_ERROR;
}
return ecma_make_object_value (proxy_p);
} /* ecma_builtin_proxy_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
@@ -0,0 +1,38 @@
/* 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.
*/
/*
* Proxy object built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
2,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_REVOCABLE, ecma_builtin_proxy_object_revocable, 2, 2)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -124,7 +124,7 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
case ECMA_REFLECT_OBJECT_HAS:
{
ret_value = ecma_make_boolean_value (ecma_op_object_has_property (target_p, name_str_p));
ret_value = ecma_op_object_has_property (target_p, name_str_p);
break;
}
@@ -384,7 +384,14 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, ext_object_size, obj_type);
ecma_set_object_extensible (obj_p, (obj_builtin_id != ECMA_BUILTIN_ID_TYPE_ERROR_THROWER));
if (JERRY_UNLIKELY (obj_builtin_id == ECMA_BUILTIN_ID_TYPE_ERROR_THROWER))
{
ecma_op_ordinary_object_prevent_extensions (obj_p);
}
else
{
ecma_op_ordinary_object_set_extensible (obj_p);
}
/*
* [[Class]] property of built-in object is not stored explicitly.
@@ -986,7 +993,7 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
uint32_t bit_for_index = (uint32_t) 1u << index;
if (!(*bitset_p & bit_for_index) || ecma_op_object_has_own_property (object_p, name_p))
if (!(*bitset_p & bit_for_index) || ecma_op_ordinary_object_has_own_property (object_p, name_p))
{
ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id);
@@ -507,6 +507,15 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_WEAKSET,
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
/* The Proxy routine (ECMA-262 v6, 26.2.1) */
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_PROXY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
true,
proxy)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
#if ENABLED (JERRY_ES2015)
/* Intrinsic hidden builtin object */