Don't use property list pointer to store Proxy flags (#4415)
Proxy flags (IsCallable, IsConstructor) can't be stored on the property list compressed pointer. As adding a Proxy to a WeakSet would add a property to the Proxy object causing failures down the line. The prototype internal "slot" can be used to store there flags as it is not used in case of Proxies (as per standard). JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com
This commit is contained in:
@@ -685,6 +685,12 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
|
||||
|
||||
/**
|
||||
* Have the object's prototype here so the object could set it to JMEM_CP_NULL
|
||||
* if the prototype should be ignored (like in case of PROXY).
|
||||
*/
|
||||
jmem_cpointer_t proto_cp = object_p->u2.prototype_cp;
|
||||
|
||||
switch (object_type)
|
||||
{
|
||||
#if !ENABLED (JERRY_BUILTIN_REALMS)
|
||||
@@ -852,8 +858,6 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
}
|
||||
}
|
||||
|
||||
jmem_cpointer_t proto_cp = object_p->u2.prototype_cp;
|
||||
|
||||
if (proto_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp));
|
||||
@@ -866,18 +870,11 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
case ECMA_OBJECT_TYPE_PROXY:
|
||||
{
|
||||
ecma_gc_mark_proxy_object (object_p);
|
||||
/* No need to free the properties of a proxy (there should be none).
|
||||
* Aside from the tag bits every other bit should be zero,
|
||||
*/
|
||||
JERRY_ASSERT ((object_p->u1.property_list_cp & ~JMEM_TAG_MASK) == 0);
|
||||
|
||||
jmem_cpointer_t proto_cp = object_p->u2.prototype_cp;
|
||||
|
||||
if (proto_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp));
|
||||
}
|
||||
return;
|
||||
/* The protoype of the proxy should be "empty" (aside from the tag bits every other bit should be zero). */
|
||||
JERRY_ASSERT ((object_p->u2.prototype_cp & ~JMEM_TAG_MASK) == 0);
|
||||
/* Make sure that the prototype is not checked below. */
|
||||
proto_cp = JMEM_CP_NULL;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
@@ -1033,8 +1030,6 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
}
|
||||
}
|
||||
|
||||
jmem_cpointer_t proto_cp = object_p->u2.prototype_cp;
|
||||
|
||||
if (proto_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp));
|
||||
@@ -1649,12 +1644,10 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
case ECMA_OBJECT_TYPE_PROXY:
|
||||
{
|
||||
/* No need to free the properties of a proxy (there should be none).
|
||||
* Aside from the tag bits every other bit should be zero,
|
||||
*/
|
||||
JERRY_ASSERT ((object_p->u1.property_list_cp & ~JMEM_TAG_MASK) == 0);
|
||||
ecma_dealloc_extended_object (object_p, sizeof (ecma_proxy_object_t));
|
||||
return;
|
||||
/* The protoype of the proxy should be "empty" (aside from the tag bits every other bit should be zero). */
|
||||
JERRY_ASSERT ((object_p->u2.prototype_cp & ~JMEM_TAG_MASK) == 0);
|
||||
ext_object_size = sizeof (ecma_proxy_object_t);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
|
||||
@@ -2166,8 +2166,8 @@ do \
|
||||
* Description of Proxy objects.
|
||||
*
|
||||
* A Proxy object's property list is used to store extra information:
|
||||
* * The "header.u1.property_list_cp" 1st tag bit stores the IsCallable information.
|
||||
* * The "header.u1.property_list_cp" 2nd tag bit stores the IsConstructor information.
|
||||
* * The "header.u2.prototype_cp" 1st tag bit stores the IsCallable information.
|
||||
* * The "header.u2.prototype_cp" 2nd tag bit stores the IsConstructor information.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
|
||||
@@ -106,7 +106,7 @@ ecma_op_object_is_callable (ecma_object_t *obj_p) /**< ecma object */
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_TYPE_IS_PROXY (type))
|
||||
{
|
||||
return ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (obj_p->u1.property_list_cp) != 0;
|
||||
return ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (obj_p->u2.prototype_cp) != 0;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
@@ -215,7 +215,7 @@ ecma_object_check_constructor (ecma_object_t *obj_p) /**< ecma object */
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_TYPE_IS_PROXY (type))
|
||||
{
|
||||
if (ECMA_GET_SECOND_BIT_FROM_POINTER_TAG (obj_p->u1.property_list_cp) == 0)
|
||||
if (ECMA_GET_SECOND_BIT_FROM_POINTER_TAG (obj_p->u2.prototype_cp) == 0)
|
||||
{
|
||||
return ECMA_ERR_MSG ("Proxy target is not a constructor.");
|
||||
}
|
||||
|
||||
@@ -60,9 +60,8 @@ ecma_proxy_create (ecma_value_t target, /**< proxy target */
|
||||
|
||||
/* ES2015: 5 - 6. */
|
||||
/* ES11+: 3 - 4. */
|
||||
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);
|
||||
/* A Proxy does not have [[Prototype]] value as per standard */
|
||||
ecma_object_t *obj_p = ecma_create_object (NULL, sizeof (ecma_proxy_object_t), ECMA_OBJECT_TYPE_PROXY);
|
||||
|
||||
ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p;
|
||||
|
||||
@@ -70,13 +69,13 @@ ecma_proxy_create (ecma_value_t target, /**< proxy target */
|
||||
/* ES11+: 5. */
|
||||
if (ecma_op_is_callable (target))
|
||||
{
|
||||
ECMA_SET_FIRST_BIT_TO_POINTER_TAG (obj_p->u1.property_list_cp);
|
||||
ECMA_SET_FIRST_BIT_TO_POINTER_TAG (obj_p->u2.prototype_cp);
|
||||
|
||||
/* ES2015: 7.b. */
|
||||
/* ES11+: 5.b. */
|
||||
if (ecma_is_constructor (target))
|
||||
{
|
||||
ECMA_SET_SECOND_BIT_TO_POINTER_TAG (obj_p->u1.property_list_cp);
|
||||
ECMA_SET_SECOND_BIT_TO_POINTER_TAG (obj_p->u2.prototype_cp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user