Added new target support to Promise (#3707)

JerryScript-DCO-1.0-Signed-off-by: bence gabor kis kisbg@inf.u-szeged.hu
This commit is contained in:
kisbg
2020-05-04 15:03:12 +02:00
committed by GitHub
parent 132a2008c9
commit 8ccb95c31c
3 changed files with 48 additions and 3 deletions
+11 -1
View File
@@ -1616,7 +1616,17 @@ jerry_create_promise (void)
jerry_assert_api_available ();
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
return ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_PROMISE_EXECUTOR_EMPTY);
ecma_object_t * old_new_target_p = JERRY_CONTEXT (current_new_target);
if (old_new_target_p == NULL)
{
JERRY_CONTEXT (current_new_target) = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
}
ecma_value_t promise_value = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_PROMISE_EXECUTOR_EMPTY);
JERRY_CONTEXT (current_new_target) = old_new_target_p;
return promise_value;
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Promise not supported.")));
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
@@ -493,11 +493,20 @@ ecma_value_t
ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function or object */
ecma_promise_executor_type_t type) /**< indicates the type of executor */
{
JERRY_ASSERT (JERRY_CONTEXT (current_new_target) != NULL);
/* 3. */
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE_PROTOTYPE);
ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target),
ECMA_BUILTIN_ID_PROMISE_PROTOTYPE);
if (JERRY_UNLIKELY (proto_p == NULL))
{
return ECMA_VALUE_ERROR;
}
ecma_object_t *object_p = ecma_create_object (proto_p,
sizeof (ecma_promise_object_t),
ECMA_OBJECT_TYPE_CLASS);
ecma_deref_object (proto_p);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_PROMISE_UL;
ext_object_p->u.class_prop.u.value = ECMA_VALUE_UNDEFINED;