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
@@ -24,6 +24,7 @@
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-objects-arguments.h"
#include "ecma-proxy-object.h"
#include "ecma-try-catch-macro.h"
#include "jcontext.h"
@@ -75,6 +76,13 @@ ecma_op_object_is_callable (ecma_object_t *obj_p) /**< ecma object */
{
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
return ecma_op_is_callable (((ecma_proxy_object_t *) obj_p)->target);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
return ecma_get_object_type (obj_p) >= ECMA_OBJECT_TYPE_FUNCTION;
} /* ecma_op_object_is_callable */
@@ -104,6 +112,13 @@ ecma_object_is_constructor (ecma_object_t *obj_p) /**< ecma object */
{
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
return ecma_is_constructor (((ecma_proxy_object_t *) obj_p)->target);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_object_type_t type = ecma_get_object_type (obj_p);
if (type == ECMA_OBJECT_TYPE_FUNCTION)
@@ -523,7 +538,27 @@ ecma_op_implicit_class_constructor_has_instance (ecma_object_t *func_obj_p, /**<
while (true)
{
jmem_cpointer_t v_obj_cp = v_obj_p->u2.prototype_cp;
jmem_cpointer_t v_obj_cp;
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (v_obj_p))
{
ecma_value_t parent = ecma_proxy_object_get_prototype_of (v_obj_p);
if (ECMA_IS_VALUE_ERROR (parent))
{
ecma_deref_object (prototype_obj_p);
return parent;
}
v_obj_cp = ecma_proxy_object_prototype_to_cp (parent);
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
v_obj_cp = ecma_op_ordinary_object_get_prototype_of (v_obj_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (v_obj_cp == JMEM_CP_NULL)
{
@@ -611,14 +646,40 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
ecma_object_t *prototype_obj_p = ecma_get_object_from_value (prototype_obj_value);
JERRY_ASSERT (prototype_obj_p != NULL);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
ecma_value_t result = ECMA_VALUE_ERROR;
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t result = ECMA_VALUE_FALSE;
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
while (true)
{
jmem_cpointer_t v_obj_cp = v_obj_p->u2.prototype_cp;
jmem_cpointer_t v_obj_cp;
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (v_obj_p))
{
ecma_value_t parent = ecma_proxy_object_get_prototype_of (v_obj_p);
if (ECMA_IS_VALUE_ERROR (parent))
{
break;
}
v_obj_cp = ecma_proxy_object_prototype_to_cp (parent);
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
v_obj_cp = ecma_op_ordinary_object_get_prototype_of (v_obj_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (v_obj_cp == JMEM_CP_NULL)
{
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
result = ECMA_VALUE_FALSE;
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
break;
}
@@ -1119,7 +1180,17 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
{
JERRY_ASSERT (func_obj_p != NULL
&& !ecma_is_lexical_environment (func_obj_p));
JERRY_ASSERT (ecma_op_is_callable (ecma_make_object_value (func_obj_p)));
JERRY_ASSERT (ecma_op_object_is_callable (func_obj_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (func_obj_p))
{
return ecma_proxy_object_call (func_obj_p,
this_arg_value,
arguments_list_p,
arguments_list_len);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION
@@ -1275,6 +1346,16 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
JERRY_ASSERT (ecma_is_value_object (this_arg_value)
|| this_arg_value == ECMA_VALUE_UNDEFINED);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (func_obj_p))
{
return ecma_proxy_object_construct (func_obj_p,
arguments_list_p,
arguments_list_len,
ecma_make_object_value (func_obj_p));
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_object_t *target_func_obj_p = NULL;
while (JERRY_UNLIKELY (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION))
@@ -90,6 +90,11 @@ ecma_op_get_value_lex_env_base (ecma_object_t *lex_env_p, /**< lexical environme
ecma_value_t result = ecma_op_object_find (binding_obj_p, name_p);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
if (ecma_is_value_found (result))
{
*ref_base_lex_env_p = lex_env_p;
@@ -272,7 +277,16 @@ ecma_op_put_value_lex_env_base (ecma_object_t *lex_env_p, /**< lexical environme
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
if (ecma_op_object_has_property (binding_obj_p, name_p))
ecma_value_t has_property = ecma_op_object_has_property (binding_obj_p, name_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (has_property))
{
return has_property;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_true (has_property))
{
ecma_value_t completion = ecma_op_object_put (binding_obj_p,
name_p,
+14 -11
View File
@@ -124,7 +124,7 @@ ecma_get_global_scope (void)
*
* @return true / false
*/
bool
ecma_value_t
ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p) /**< argument N */
{
@@ -137,16 +137,14 @@ ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */
{
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
return (property_p != NULL);
return ecma_make_boolean_value (property_p != NULL);
}
else
{
JERRY_ASSERT (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
JERRY_ASSERT (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
return ecma_op_object_has_property (binding_obj_p, name_p);
}
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
return ecma_op_object_has_property (binding_obj_p, name_p);
} /* ecma_op_has_binding */
/**
@@ -186,7 +184,7 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
if (!ecma_get_object_extensible (binding_obj_p))
if (!ecma_op_ordinary_object_is_extensible (binding_obj_p))
{
return ECMA_VALUE_EMPTY;
}
@@ -299,6 +297,11 @@ ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_value_t result = ecma_op_object_find (binding_obj_p, name_p);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
if (!ecma_is_value_found (result))
{
if (is_strict)
@@ -321,8 +324,8 @@ ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */
* See also: ECMA-262 v5, 10.2.1
*
* @return ecma value
* Return value is simple and so need not be freed.
* However, ecma_free_value may be called for it, but it is a no-op.
* Return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the binding can be deleted
*/
ecma_value_t
ecma_op_delete_binding (ecma_object_t *lex_env_p, /**< lexical environment */
+1 -1
View File
@@ -55,7 +55,7 @@ ecma_value_t ecma_op_put_value_lex_env_base (ecma_object_t *lex_env_p, ecma_stri
bool is_strict, ecma_value_t value);
/* ECMA-262 v5, Table 17. Abstract methods of Environment Records */
bool ecma_op_has_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p);
ecma_value_t ecma_op_has_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p);
ecma_value_t ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p, bool is_deletable);
ecma_value_t ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p, ecma_value_t value,
bool is_strict);
@@ -22,6 +22,7 @@
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-proxy-object.h"
#include "ecma-try-catch-macro.h"
/** \addtogroup ecma ECMA
@@ -362,6 +363,13 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
const ecma_property_descriptor_t *property_desc_p) /**< property
* descriptor */
{
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (object_p))
{
return ecma_proxy_object_define_own_property (object_p, property_name_p, property_desc_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
JERRY_ASSERT (object_p != NULL
&& !ecma_is_lexical_environment (object_p));
JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p));
@@ -403,7 +411,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
if (current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND || current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
{
/* 3. */
if (!ecma_get_object_extensible (object_p))
if (!ecma_op_ordinary_object_is_extensible (object_p))
{
/* 2. */
return ecma_reject (property_desc_p->flags & ECMA_PROP_IS_THROW);
+274 -67
View File
@@ -26,6 +26,7 @@
#include "ecma-objects-arguments.h"
#include "ecma-objects-general.h"
#include "ecma-objects.h"
#include "ecma-proxy-object.h"
#include "jcontext.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
@@ -75,8 +76,13 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
{
JERRY_ASSERT (object_p != NULL
&& !ecma_is_lexical_environment (object_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
JERRY_ASSERT (property_name_p != NULL);
JERRY_ASSERT (options == ECMA_PROPERTY_GET_NO_OPTIONS || property_ref_p != NULL);
JERRY_ASSERT (options == ECMA_PROPERTY_GET_NO_OPTIONS
|| options == ECMA_PROPERTY_GET_HAS_OWN_PROP
|| property_ref_p != NULL);
ecma_object_type_t type = ecma_get_object_type (object_p);
@@ -287,7 +293,7 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
}
}
else if (type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY
&& property_ref_p != NULL)
&& (options & ECMA_PROPERTY_GET_HAS_OWN_PROP))
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
@@ -378,39 +384,43 @@ ecma_op_object_get_property (ecma_object_t *object_p, /**< the object */
} /* ecma_op_object_get_property */
/**
* Checks whether an object (excluding prototypes) has a named property
* Generic [[HasProperty]] operation
*
* @return true - if property is found
* false - otherwise
*/
inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_op_object_has_own_property (ecma_object_t *object_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
ecma_property_ref_t property_ref;
ecma_property_t property = ecma_op_object_get_own_property (object_p,
property_name_p,
&property_ref,
ECMA_PROPERTY_GET_NO_OPTIONS);
return property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP;
} /* ecma_op_object_has_own_property */
/**
* Checks whether an object (including prototypes) has a named property
* See also:
* ECMAScript v6, 9.1.7.1
*
* @return true - if property is found
* false - otherwise
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE_FALSE} - whether the property is found
*/
inline bool JERRY_ATTR_ALWAYS_INLINE
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
ecma_op_object_has_property (ecma_object_t *object_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
ecma_property_t property = ecma_op_object_get_property (object_p,
property_name_p,
NULL,
ECMA_PROPERTY_GET_NO_OPTIONS);
return property != ECMA_PROPERTY_TYPE_NOT_FOUND;
while (true)
{
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (object_p))
{
return ecma_proxy_object_has (object_p, property_name_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/* 2 - 3. */
if (ecma_op_ordinary_object_has_own_property (object_p, property_name_p))
{
return ECMA_VALUE_TRUE;
}
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (object_p);
/* 7. */
if (proto_cp == JMEM_CP_NULL)
{
return ECMA_VALUE_FALSE;
}
object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
}
} /* ecma_op_object_has_property */
/**
@@ -430,6 +440,7 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
JERRY_ASSERT (object_p != NULL
&& !ecma_is_lexical_environment (object_p));
JERRY_ASSERT (property_name_p != NULL);
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
ecma_object_type_t type = ecma_get_object_type (object_p);
@@ -705,6 +716,13 @@ ecma_op_object_find (ecma_object_t *object_p, /**< the object */
while (true)
{
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (object_p))
{
return ecma_proxy_object_find (object_p, property_name_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t value = ecma_op_object_find_own (base_value, object_p, property_name_p);
if (ecma_is_value_found (value))
@@ -770,30 +788,11 @@ ecma_op_object_get_own_data_prop (ecma_object_t *object_p, /**< the object */
* @return ecma value
* Returned value must be freed with ecma_free_value
*/
ecma_value_t
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
ecma_op_object_get (ecma_object_t *object_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
ecma_value_t base_value = ecma_make_object_value (object_p);
while (true)
{
ecma_value_t value = ecma_op_object_find_own (base_value, object_p, property_name_p);
if (ecma_is_value_found (value))
{
return value;
}
if (object_p->u2.prototype_cp == JMEM_CP_NULL)
{
break;
}
object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, object_p->u2.prototype_cp);
}
return ECMA_VALUE_UNDEFINED;
return ecma_op_object_get_with_receiver (object_p, property_name_p, ecma_make_object_value (object_p));
} /* ecma_op_object_get */
/**
@@ -817,6 +816,13 @@ ecma_op_object_get_with_receiver (ecma_object_t *object_p, /**< the object */
{
while (true)
{
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (object_p))
{
return ecma_proxy_object_get (object_p, property_name_p, receiver);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_value_t value = ecma_op_object_find_own (receiver, object_p, property_name_p);
if (ecma_is_value_found (value))
@@ -824,12 +830,14 @@ ecma_op_object_get_with_receiver (ecma_object_t *object_p, /**< the object */
return value;
}
if (object_p->u2.prototype_cp == JMEM_CP_NULL)
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (object_p);
if (proto_cp == JMEM_CP_NULL)
{
break;
}
object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, object_p->u2.prototype_cp);
object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
}
return ECMA_VALUE_UNDEFINED;
@@ -1149,6 +1157,13 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
&& !ecma_is_lexical_environment (object_p));
JERRY_ASSERT (property_name_p != NULL);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (object_p))
{
return ecma_proxy_object_set (object_p, property_name_p, value, receiver);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_object_type_t type = ecma_get_object_type (object_p);
switch (type)
@@ -1169,7 +1184,7 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
if (JERRY_LIKELY (ecma_op_array_is_fast_array (ext_object_p)))
{
if (JERRY_UNLIKELY (!ecma_get_object_extensible (object_p)))
if (JERRY_UNLIKELY (!ecma_op_ordinary_object_is_extensible (object_p)))
{
return ecma_reject (is_throw);
}
@@ -1354,10 +1369,12 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
{
bool create_new_property = true;
if (object_p->u2.prototype_cp != JMEM_CP_NULL)
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (object_p);
if (proto_cp != JMEM_CP_NULL)
{
ecma_property_ref_t property_ref = { NULL };
ecma_object_t *proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, object_p->u2.prototype_cp);
ecma_object_t *proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
ecma_property_t inherited_property = ecma_op_object_get_property (proto_p,
property_name_p,
@@ -1379,7 +1396,7 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
}
if (create_new_property
&& ecma_get_object_extensible (object_p))
&& ecma_op_ordinary_object_is_extensible (object_p))
{
const ecma_object_type_t obj_type = ecma_get_object_type (object_p);
@@ -1526,6 +1543,13 @@ ecma_op_object_delete (ecma_object_t *obj_p, /**< the object */
}
}
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
return ecma_proxy_object_delete_property (obj_p, property_name_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
JERRY_ASSERT_OBJECT_TYPE_IS_VALID (ecma_get_object_type (obj_p));
return ecma_op_general_object_delete (obj_p,
@@ -1591,6 +1615,13 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
const ecma_object_type_t type = ecma_get_object_type (obj_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
return ecma_proxy_object_define_own_property (obj_p, property_name_p, property_desc_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
switch (type)
{
case ECMA_OBJECT_TYPE_GENERAL:
@@ -1691,11 +1722,18 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
* @return true - if property found
* false - otherwise
*/
bool
ecma_value_t
ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the object */
ecma_string_t *property_name_p, /**< property name */
ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */
{
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (object_p))
{
return ecma_proxy_object_get_own_property_descriptor (object_p, property_name_p, prop_desc_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
ecma_property_ref_t property_ref;
ecma_property_t property = ecma_op_object_get_own_property (object_p,
@@ -1705,7 +1743,7 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
{
return false;
return ECMA_VALUE_FALSE;
}
*prop_desc_p = ecma_make_empty_property_descriptor ();
@@ -1760,7 +1798,7 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob
}
}
return true;
return ECMA_VALUE_TRUE;
} /* ecma_op_object_get_own_property_descriptor */
/**
@@ -1795,27 +1833,46 @@ ecma_op_object_has_instance (ecma_object_t *obj_p, /**< the object */
* See also:
* ECMA-262 v5, 15.2.4.6; 3
*
* @return true - if the target object is prototype of the base object
* false - if the target object is not prototype of the base object
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_TRUE - if the target object is prototype of the base object
* ECMA_VALUE_FALSE - if the target object is not prototype of the base object
*/
bool
ecma_value_t
ecma_op_object_is_prototype_of (ecma_object_t *base_p, /**< base object */
ecma_object_t *target_p) /**< target object */
{
do
{
jmem_cpointer_t target_cp = target_p->u2.prototype_cp;
jmem_cpointer_t target_cp;
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (target_p))
{
ecma_value_t target_proto = ecma_proxy_object_get_prototype_of (target_p);
if (ECMA_IS_VALUE_ERROR (target_proto))
{
return target_proto;
}
target_cp = ecma_proxy_object_prototype_to_cp (target_proto);
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
target_cp = ecma_op_ordinary_object_get_prototype_of (target_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (target_cp == JMEM_CP_NULL)
{
return false;
return ECMA_VALUE_FALSE;
}
target_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, target_cp);
if (target_p == base_p)
{
return true;
return ECMA_VALUE_TRUE;
}
} while (true);
} /* ecma_op_object_is_prototype_of */
@@ -1832,7 +1889,8 @@ ecma_op_object_is_prototype_of (ecma_object_t *base_p, /**< base object */
* property list, and the list is not reordered (in other words, properties are stored in order that is reversed
* to the properties' addition order).
*
* @return collection of strings - property names
* @return NULL - if the Proxy.[[OwnPropertyKeys]] operation raises error
* collection of property names - otherwise
*/
ecma_collection_t *
ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
@@ -1841,6 +1899,13 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
JERRY_ASSERT (obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (obj_p))
{
return ecma_proxy_object_own_property_keys (obj_p);
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_op_object_is_fast_array (obj_p))
{
return ecma_fast_array_get_property_names (obj_p, opts);
@@ -2480,7 +2545,7 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
}
default:
{
JERRY_ASSERT (type == ECMA_OBJECT_TYPE_GENERAL);
JERRY_ASSERT (type == ECMA_OBJECT_TYPE_GENERAL || type == ECMA_OBJECT_TYPE_PROXY);
if (ecma_get_object_is_builtin (obj_p))
{
@@ -2524,6 +2589,12 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
{
return LIT_MAGIC_STRING_ERROR_UL;
}
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
case ECMA_BUILTIN_ID_PROXY:
{
return LIT_MAGIC_STRING_FUNCTION_UL;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
default:
{
JERRY_ASSERT (ecma_object_check_class_name_is_object (obj_p));
@@ -2766,6 +2837,142 @@ ecma_op_invoke (ecma_value_t object, /**< Object value */
return call_result;
} /* ecma_op_invoke */
/**
* Ordinary object [[GetPrototypeOf]] operation
*
* See also:
* ECMAScript v6, 9.1.1
*
* @return the value of the [[Prototype]] internal slot of the given object.
*/
inline jmem_cpointer_t JERRY_ATTR_ALWAYS_INLINE
ecma_op_ordinary_object_get_prototype_of (ecma_object_t *obj_p) /**< object */
{
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (obj_p));
return obj_p->u2.prototype_cp;
} /* ecma_op_ordinary_object_get_prototype_of */
/**
* Ordinary object [[SetPrototypeOf]] operation
*
* See also:
* ECMAScript v6, 9.1.2
*
* @return ECMA_VALUE_FALSE - if the operation fails
* ECMA_VALUE_TRUE - otherwise
*/
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
ecma_op_ordinary_object_set_prototype_of (ecma_object_t *obj_p, /**< base object */
ecma_value_t proto) /**< prototype object */
{
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (obj_p));
/* 1. */
JERRY_ASSERT (ecma_is_value_object (proto) || ecma_is_value_null (proto));
/* 3. */
ecma_object_t *current_proto_p = ECMA_GET_POINTER (ecma_object_t, ecma_op_ordinary_object_get_prototype_of (obj_p));
ecma_object_t *new_proto_p = ecma_is_value_null (proto) ? NULL : ecma_get_object_from_value (proto);
/* 4. */
if (new_proto_p == current_proto_p)
{
return ECMA_VALUE_TRUE;
}
/* 2 - 5. */
if (!ecma_op_ordinary_object_is_extensible (obj_p))
{
return ECMA_VALUE_FALSE;
}
/* 6. */
ecma_object_t *iter_p = new_proto_p;
/* 7 - 8. */
while (true)
{
/* 8.a */
if (iter_p == NULL)
{
break;
}
/* 8.b */
if (obj_p == iter_p)
{
return ECMA_VALUE_FALSE;
}
/* 8.c.i */
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_OBJECT_IS_PROXY (iter_p))
{
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/* 8.c.ii */
iter_p = ECMA_GET_POINTER (ecma_object_t, ecma_op_ordinary_object_get_prototype_of (iter_p));
}
/* 9. */
ECMA_SET_POINTER (obj_p->u2.prototype_cp, new_proto_p);
/* 10. */
return ECMA_VALUE_TRUE;
} /* ecma_op_ordinary_object_set_prototype_of */
/**
* [[IsExtensible]] operation for Ordinary object.
*
* See also:
* ECMAScript v6, 9.1.2
*
* @return true - if object is extensible
* false - otherwise
*/
inline bool JERRY_ATTR_PURE
ecma_op_ordinary_object_is_extensible (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
return (object_p->type_flags_refs & ECMA_OBJECT_FLAG_EXTENSIBLE) != 0;
} /* ecma_op_ordinary_object_is_extensible */
/**
* Set value of [[Extensible]] object's internal property.
*/
void JERRY_ATTR_NOINLINE
ecma_op_ordinary_object_prevent_extensions (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs & ~ECMA_OBJECT_FLAG_EXTENSIBLE);
} /* ecma_op_ordinary_object_prevent_extensions */
/**
* Checks whether an object (excluding prototypes) has a named property
*
* @return true - if property is found
* false - otherwise
*/
inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
ecma_property_t property = ecma_op_object_get_own_property (object_p,
property_name_p,
NULL,
ECMA_PROPERTY_GET_HAS_OWN_PROP);
return property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP;
} /* ecma_op_ordinary_object_has_own_property */
/**
* @}
* @}
+12 -5
View File
@@ -29,8 +29,8 @@
ecma_property_t ecma_op_object_get_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p,
ecma_property_ref_t *property_ref_p, uint32_t options);
bool ecma_op_object_has_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p);
bool ecma_op_object_has_property (ecma_object_t *object_p, ecma_string_t *property_name_p);
bool ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_has_property (ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_find_own (ecma_value_t base_value, ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_find (ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_find_by_uint32_index (ecma_object_t *object_p, uint32_t index);
@@ -52,6 +52,8 @@ ecma_value_t ecma_op_object_put_with_receiver (ecma_object_t *object_p, ecma_str
ecma_value_t value, ecma_value_t receiver, bool is_throw);
ecma_value_t ecma_op_object_put (ecma_object_t *object_p, ecma_string_t *property_name_p, ecma_value_t value,
bool is_throw);
ecma_value_t ecma_op_object_put_with_receiver (ecma_object_t *object_p, ecma_string_t *property_name_p,
ecma_value_t value, ecma_value_t receiver, bool is_throw);
ecma_value_t ecma_op_object_put_by_uint32_index (ecma_object_t *object_p, uint32_t index,
ecma_value_t value, bool is_throw);
ecma_value_t ecma_op_object_put_by_number_index (ecma_object_t *object_p, ecma_number_t index,
@@ -62,10 +64,10 @@ ecma_value_t ecma_op_object_delete_by_number_index (ecma_object_t *obj_p, ecma_n
ecma_value_t ecma_op_object_default_value (ecma_object_t *obj_p, ecma_preferred_type_hint_t hint);
ecma_value_t ecma_op_object_define_own_property (ecma_object_t *obj_p, ecma_string_t *property_name_p,
const ecma_property_descriptor_t *property_desc_p);
bool ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, ecma_string_t *property_name_p,
ecma_property_descriptor_t *prop_desc_p);
ecma_value_t ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, ecma_string_t *property_name_p,
ecma_property_descriptor_t *prop_desc_p);
ecma_value_t ecma_op_object_has_instance (ecma_object_t *obj_p, ecma_value_t value);
bool ecma_op_object_is_prototype_of (ecma_object_t *base_p, ecma_object_t *target_p);
ecma_value_t ecma_op_object_is_prototype_of (ecma_object_t *base_p, ecma_object_t *target_p);
ecma_collection_t * ecma_op_object_get_property_names (ecma_object_t *obj_p, uint32_t opts);
lit_magic_string_id_t ecma_object_get_class_name (ecma_object_t *obj_p);
@@ -81,6 +83,11 @@ ecma_value_t ecma_op_invoke (ecma_value_t object, ecma_string_t *property_name_p
ecma_value_t ecma_op_invoke_by_magic_id (ecma_value_t object, lit_magic_string_id_t magic_string_id,
ecma_value_t *args_p, ecma_length_t args_len);
jmem_cpointer_t ecma_op_ordinary_object_get_prototype_of (ecma_object_t *obj_p);
ecma_value_t ecma_op_ordinary_object_set_prototype_of (ecma_object_t *base_p, ecma_value_t proto);
bool JERRY_ATTR_PURE ecma_op_ordinary_object_is_extensible (ecma_object_t *object_p);
void ecma_op_ordinary_object_prevent_extensions (ecma_object_t *object_p);
/**
* @}
* @}
@@ -0,0 +1,552 @@
/* 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-function-object.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-proxy-object.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaproxyobject ECMA Proxy object related routines
* @{
*/
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
/**
* Check whether the argument satifies the requrements of [[ProxyTarget]] or [[ProxyHandler]]
*
* See also:
* ES2015 9.5.15.1-2
* ES2015 9.5.15.3-4
*
* @return true - if the arguments can be a valid [[ProxyTarget]] or [[ProxyHandler]]
* false - otherwise
*/
static bool
ecma_proxy_validate (ecma_value_t argument) /**< argument to validate */
{
if (ecma_is_value_object (argument))
{
ecma_object_t *obj_p = ecma_get_object_from_value (argument);
return (!ECMA_OBJECT_IS_PROXY (obj_p)
|| !ecma_is_value_null (((ecma_proxy_object_t *) obj_p)->handler));
}
return false;
} /* ecma_proxy_validate */
/**
* ProxyCreate operation for create a new proxy object
*
* See also:
* ES2015 9.5.15
*
* @return created Proxy object as an ecma-value - if success
* raised error - otherwise
*/
ecma_object_t *
ecma_proxy_create (ecma_value_t target, /**< proxy target */
ecma_value_t handler) /**< proxy handler */
{
/* 1 - 4. */
if (!ecma_proxy_validate (target) || !ecma_proxy_validate (handler))
{
ecma_raise_type_error (ECMA_ERR_MSG ("Cannot create proxy with a non-object target or handler"));
return NULL;
}
/* 5 - 6. */
ecma_object_t *obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE),
sizeof (ecma_proxy_object_t),
ECMA_OBJECT_TYPE_PROXY);
ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p;
/* 8. */
proxy_obj_p->target = target;
/* 9. */
proxy_obj_p->handler = handler;
/* 10. */
return obj_p;
} /* ecma_proxy_create */
/**
* Definition of Proxy Revocation Function
*
* See also:
* ES2015 26.2.2.1.1
*
* @return ECMA_VALUE_UNDEFINED
*/
ecma_value_t
ecma_proxy_revoke_cb (const ecma_value_t function_obj, /**< the function itself */
const ecma_value_t this_val, /**< this_arg of the function */
const ecma_value_t args_p[], /**< argument list */
const ecma_length_t args_count) /**< argument number */
{
JERRY_UNUSED_3 (this_val, args_p, args_count);
ecma_object_t *func_obj_p = ecma_get_object_from_value (function_obj);
/* 1. */
ecma_revocable_proxy_object_t *rev_proxy_p = (ecma_revocable_proxy_object_t *) func_obj_p;
/* 2. */
if (ecma_is_value_null (rev_proxy_p->proxy))
{
return ECMA_VALUE_UNDEFINED;
}
/* 4. */
ecma_proxy_object_t *proxy_p = (ecma_proxy_object_t *) ecma_get_object_from_value (rev_proxy_p->proxy);
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY ((ecma_object_t *) proxy_p));
/* 3. */
rev_proxy_p->proxy = ECMA_VALUE_NULL;
/* 5. */
proxy_p->target = ECMA_VALUE_NULL;
/* 6. */
proxy_p->handler = ECMA_VALUE_NULL;
/* 7. */
return ECMA_VALUE_UNDEFINED;
} /* ecma_proxy_revoke_cb */
/**
* Proxy.revocable operation for create a new revocable proxy object
*
* See also:
* ES2015 26.2.2.1
*
* @return NULL - if the operation fails
* pointer to the newly created revocable proxy object - otherwise
*/
ecma_object_t *
ecma_proxy_create_revocable (ecma_value_t target, /**< target argument */
ecma_value_t handler) /**< handler argument */
{
/* 1. */
ecma_object_t *proxy_p = ecma_proxy_create (target, handler);
/* 2. */
if (proxy_p == NULL)
{
return proxy_p;
}
ecma_value_t proxy_value = ecma_make_object_value (proxy_p);
/* 3. */
ecma_object_t *func_obj_p;
func_obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE),
sizeof (ecma_revocable_proxy_object_t),
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION);
ecma_revocable_proxy_object_t *rev_proxy_p = (ecma_revocable_proxy_object_t *) func_obj_p;
rev_proxy_p->header.u.external_handler_cb = ecma_proxy_revoke_cb;
/* 4. */
rev_proxy_p->proxy = proxy_value;
ecma_property_value_t *prop_value_p;
ecma_value_t revoker = ecma_make_object_value (func_obj_p);
/* 5. */
ecma_object_t *obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE),
0,
ECMA_OBJECT_TYPE_GENERAL);
/* 6. */
prop_value_p = ecma_create_named_data_property (obj_p,
ecma_get_magic_string (LIT_MAGIC_STRING_PROXY),
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
NULL);
prop_value_p->value = proxy_value;
/* 7. */
prop_value_p = ecma_create_named_data_property (obj_p,
ecma_get_magic_string (LIT_MAGIC_STRING_REVOKE),
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
NULL);
prop_value_p->value = revoker;
ecma_deref_object (proxy_p);
ecma_deref_object (func_obj_p);
/* 8. */
return obj_p;
} /* ecma_proxy_create_revocable */
/**
* Internal find property operation for Proxy object
*
* Note: Returned value must be freed with ecma_free_value.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_NOT_FOUND - if the property is not found
* value of the property - otherwise
*/
ecma_value_t
ecma_proxy_object_find (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p) /**< property name */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
ecma_value_t has_result = ecma_proxy_object_has (obj_p, prop_name_p);
if (ECMA_IS_VALUE_ERROR (has_result))
{
return has_result;
}
if (ecma_is_value_false (has_result))
{
return ECMA_VALUE_NOT_FOUND;
}
return ecma_proxy_object_get (obj_p, prop_name_p, ecma_make_object_value (obj_p));
} /* ecma_proxy_object_find */
/**
* Convert the result of the ecma_proxy_object_get_prototype_of to compressed pointer
*
* Note: if `proto` is non-null, the reference from the object is released
*
* @return compressed pointer to the `proto` value
*/
jmem_cpointer_t
ecma_proxy_object_prototype_to_cp (ecma_value_t proto) /**< ECMA_VALUE_NULL or object */
{
JERRY_ASSERT (ecma_is_value_null (proto) || ecma_is_value_object (proto));
if (ecma_is_value_null (proto))
{
return JMEM_CP_NULL;
}
jmem_cpointer_t proto_cp;
ecma_object_t *proto_obj_p = ecma_get_object_from_value (proto);
ECMA_SET_POINTER (proto_cp, proto_obj_p);
ecma_deref_object (proto_obj_p);
return proto_cp;
} /* ecma_proxy_object_prototype_to_cp */
/* Interal operations */
/**
* The Proxy object [[GetPrototypeOf]] internal routine
*
* See also:
* ECMAScript v6, 9.5.1
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_NULL or valid object (prototype) otherwise
*/
ecma_value_t
ecma_proxy_object_get_prototype_of (ecma_object_t *obj_p) /**< proxy object */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED (obj_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[GetPrototypeOf]]"));
} /* ecma_proxy_object_get_prototype_of */
/**
* The Proxy object [[SetPrototypeOf]] internal routine
*
* See also:
* ECMAScript v6, 9.5.2
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the new prototype can be set for the given object
*/
ecma_value_t
ecma_proxy_object_set_prototype_of (ecma_object_t *obj_p, /**< proxy object */
ecma_value_t proto) /**< new prototype object */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_ASSERT (ecma_is_value_object (proto) || ecma_is_value_null (proto));
JERRY_UNUSED_2 (obj_p, proto);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[SetPrototypeOf]]"));
} /* ecma_proxy_object_set_prototype_of */
/**
* The Proxy object [[isExtensible]] internal routine
*
* See also:
* ECMAScript v6, 9.5.3
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the object is extensible
*/
ecma_value_t
ecma_proxy_object_is_extensible (ecma_object_t *obj_p) /**< proxy object */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED (obj_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[IsExtensible]]"));
} /* ecma_proxy_object_is_extensible */
/**
* The Proxy object [[PreventExtensions]] internal routine
*
* See also:
* ECMAScript v6, 9.5.4
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the object can be set as inextensible
*/
ecma_value_t
ecma_proxy_object_prevent_extensions (ecma_object_t *obj_p) /**< proxy object */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED (obj_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[PreventExtensions]]"));
} /* ecma_proxy_object_prevent_extensions */
/**
* The Proxy object [[GetOwnProperty]] internal routine
*
* See also:
* ECMAScript v6, 9.5.5
*
* Note: - Returned value is always a simple value so freeing it is unnecessary.
* - If the operation does not fail, freeing the filled property descriptor is the caller's responsibility
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE_FALSE} - depends on whether object has property with the given name
*/
ecma_value_t
ecma_proxy_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p, /**< property name */
ecma_property_descriptor_t *prop_desc_p) /**< [out] property
* descriptor */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_3 (obj_p, prop_name_p, prop_desc_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[GetOwnProperty]]"));
} /* ecma_proxy_object_get_own_property_descriptor */
/**
* The Proxy object [[DefineOwnProperty]] internal routine
*
* See also:
* ECMAScript v6, 9.5.6
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE_FALSE} - depends on whether the property can be defined for the given object
*/
ecma_value_t
ecma_proxy_object_define_own_property (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p, /**< property name */
const ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_3 (obj_p, prop_name_p, prop_desc_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[DefineOwnProperty]]"));
} /* ecma_proxy_object_define_own_property */
/**
* The Proxy object [[HasProperty]] internal routine
*
* See also:
* ECMAScript v6, 9.5.7
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE_FALSE} - depends on whether the property is found
*/
ecma_value_t
ecma_proxy_object_has (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p) /**< property name */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_2 (obj_p, prop_name_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[HasProperty]]"));
} /* ecma_proxy_object_has */
/**
* The Proxy object [[Get]] internal routine
*
* See also:
* ECMAScript v6, 9.5.8
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* value of the given nameddata property or the result of the getter function call - otherwise
*/
ecma_value_t
ecma_proxy_object_get (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p, /**< property name */
ecma_value_t receiver) /**< receiver to invoke getter function */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_3 (obj_p, prop_name_p, receiver);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Get]]"));
} /* ecma_proxy_object_get */
/**
* The Proxy object [[Set]] internal routine
*
* See also:
* ECMAScript v6, 9.5.9
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the propety can be set to the given object
*/
ecma_value_t
ecma_proxy_object_set (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p, /**< property name */
ecma_value_t value, /**< value to set */
ecma_value_t receiver) /**< receiver to invoke setter function */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_4 (obj_p, prop_name_p, value, receiver);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Set]]"));
} /* ecma_proxy_object_set */
/**
* The Proxy object [[Delete]] internal routine
*
* See also:
* ECMAScript v6, 9.5.10
*
* Note: Returned value is always a simple value so freeing it is unnecessary.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the propety can be deleted
*/
ecma_value_t
ecma_proxy_object_delete_property (ecma_object_t *obj_p, /**< proxy object */
ecma_string_t *prop_name_p) /**< property name */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_2 (obj_p, prop_name_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Delete]]"));
} /* ecma_proxy_object_delete_property */
/**
* The Proxy object [[Enumerate]] internal routine
*
* See also:
* ECMAScript v6, 9.5.11
*
* Note: Returned value must be freed with ecma_free_value.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* ecma-object - otherwise
*/
ecma_value_t
ecma_proxy_object_enumerate (ecma_object_t *obj_p) /**< proxy object */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED (obj_p);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Enumerate]]"));
} /* ecma_proxy_object_enumerate */
/**
* The Proxy object [[OwnPropertyKeys]] internal routine
*
* See also:
* ECMAScript v6, 9.5.12
*
* Note: If the returned collection is not NULL, it must be freed with
* ecma_collection_free if it is no longer needed
*
* @return NULL - if the operation fails
* pointer to a newly allocated list of property names - otherwise
*/
ecma_collection_t *
ecma_proxy_object_own_property_keys (ecma_object_t *obj_p) /**< proxy object */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED (obj_p);
ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[OwnPropertyKeys]]"));
return NULL;
} /* ecma_proxy_object_own_property_keys */
/**
* The Proxy object [[Call]] internal routine
*
* See also:
* ECMAScript v6, 9.5.13
*
* Note: Returned value must be freed with ecma_free_value.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* result of the function call - otherwise
*/
ecma_value_t
ecma_proxy_object_call (ecma_object_t *obj_p, /**< proxy object */
ecma_value_t this_argument, /**< this argument to invoke the function */
const ecma_value_t *args_p, /**< argument list */
ecma_length_t argc) /**< number of arguments */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_4 (obj_p, this_argument, args_p, argc);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Call]]"));
} /* ecma_proxy_object_call */
/**
* The Proxy object [[Construct]] internal routine
*
* See also:
* ECMAScript v6, 9.5.14
*
* Note: Returned value must be freed with ecma_free_value.
*
* @return ECMA_VALUE_ERROR - if the operation fails
* result of the construct call - otherwise
*/
ecma_value_t
ecma_proxy_object_construct (ecma_object_t *obj_p, /**< proxy object */
const ecma_value_t *args_p, /**< argument list */
ecma_length_t argc, /**< number of arguments */
ecma_value_t new_target) /**< this argument to invoke the function */
{
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
JERRY_UNUSED_4 (obj_p, args_p, argc, new_target);
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Construct]]"));
} /* ecma_proxy_object_construct */
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/**
* @}
* @}
*/
@@ -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.
*/
#ifndef ECMA_PROXY_OBJECT_H
#define ECMA_PROXY_OBJECT_H
#include "ecma-globals.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaproxyobject ECMA Proxy object related routines
* @{
*/
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
ecma_object_t *
ecma_proxy_create (ecma_value_t target,
ecma_value_t handler);
ecma_object_t *
ecma_proxy_create_revocable (ecma_value_t target,
ecma_value_t handler);
ecma_value_t
ecma_proxy_revoke_cb (const ecma_value_t function_obj,
const ecma_value_t this_val,
const ecma_value_t args_p[],
const ecma_length_t args_count);
jmem_cpointer_t
ecma_proxy_object_prototype_to_cp (ecma_value_t proto);
ecma_value_t
ecma_proxy_object_find (ecma_object_t *obj_p,
ecma_string_t *prop_name_p);
/* Interal operations */
ecma_value_t
ecma_proxy_object_get_prototype_of (ecma_object_t *obj_p);
ecma_value_t
ecma_proxy_object_set_prototype_of (ecma_object_t *obj_p,
ecma_value_t proto);
ecma_value_t
ecma_proxy_object_is_extensible (ecma_object_t *obj_p);
ecma_value_t
ecma_proxy_object_prevent_extensions (ecma_object_t *obj_p);
ecma_value_t
ecma_proxy_object_get_own_property_descriptor (ecma_object_t *obj_p,
ecma_string_t *prop_name_p,
ecma_property_descriptor_t *prop_desc_p);
ecma_value_t
ecma_proxy_object_define_own_property (ecma_object_t *obj_p,
ecma_string_t *prop_name_p,
const ecma_property_descriptor_t *prop_desc_p);
ecma_value_t
ecma_proxy_object_has (ecma_object_t *obj_p,
ecma_string_t *prop_name_p);
ecma_value_t
ecma_proxy_object_get (ecma_object_t *obj_p,
ecma_string_t *prop_name_p,
ecma_value_t receiver);
ecma_value_t
ecma_proxy_object_set (ecma_object_t *obj_p,
ecma_string_t *prop_name_p,
ecma_value_t name,
ecma_value_t receiver);
ecma_value_t
ecma_proxy_object_delete_property (ecma_object_t *obj_p,
ecma_string_t *prop_name_p);
ecma_value_t
ecma_proxy_object_enumerate (ecma_object_t *obj_p);
ecma_collection_t *
ecma_proxy_object_own_property_keys (ecma_object_t *obj_p);
ecma_value_t
ecma_proxy_object_call (ecma_object_t *obj_p,
ecma_value_t this_argument,
const ecma_value_t *args_p,
ecma_length_t argc);
ecma_value_t
ecma_proxy_object_construct (ecma_object_t *obj_p,
const ecma_value_t *args_p,
ecma_length_t argc,
ecma_value_t new_target);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
/**
* @}
* @}
*/
#endif /* !ECMA_PROXY_OBJECT_H */
+18 -4
View File
@@ -34,9 +34,9 @@
/**
* Resolve syntactic reference.
*
* @return if reference was resolved successfully,
* pointer to lexical environment - reference's base,
* else - NULL.
* @return ECMA_OBJECT_POINTER_ERROR - if the operation fails
* pointer to lexical environment - if the reference's base is resolved sucessfully,
* NULL - otherwise.
*/
ecma_object_t *
ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical environment */
@@ -54,7 +54,16 @@ ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical
}
#endif /* ENABLED (JERRY_ES2015) */
if (ecma_op_has_binding (lex_env_p, name_p))
ecma_value_t has_binding = ecma_op_has_binding (lex_env_p, name_p);
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (has_binding))
{
return ECMA_OBJECT_POINTER_ERROR;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
if (ecma_is_value_true (has_binding))
{
return lex_env_p;
}
@@ -221,6 +230,11 @@ ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, /**< starting lexical
ecma_value_t prop_value = ecma_op_object_find (binding_obj_p, name_p);
if (ECMA_IS_VALUE_ERROR (prop_value))
{
return prop_value;
}
if (ecma_is_value_found (prop_value))
{
#if ENABLED (JERRY_ES2015)