Add new.target argument to Promise create (#4606)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -2195,16 +2195,8 @@ jerry_create_promise (void)
|
|||||||
jerry_assert_api_available ();
|
jerry_assert_api_available ();
|
||||||
|
|
||||||
#if JERRY_BUILTIN_PROMISE
|
#if JERRY_BUILTIN_PROMISE
|
||||||
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p);
|
ecma_value_t promise_value = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL);
|
||||||
|
|
||||||
if (old_new_target_p == NULL)
|
|
||||||
{
|
|
||||||
JERRY_CONTEXT (current_new_target_p) = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_value_t promise_value = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED);
|
|
||||||
|
|
||||||
JERRY_CONTEXT (current_new_target_p) = old_new_target_p;
|
|
||||||
return promise_value;
|
return promise_value;
|
||||||
#else /* !JERRY_BUILTIN_PROMISE */
|
#else /* !JERRY_BUILTIN_PROMISE */
|
||||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (error_promise_not_supported_p)));
|
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (error_promise_not_supported_p)));
|
||||||
|
|||||||
@@ -455,7 +455,9 @@ ecma_builtin_promise_dispatch_construct (const ecma_value_t *arguments_list_p, /
|
|||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("First parameter must be callable"));
|
return ecma_raise_type_error (ECMA_ERR_MSG ("First parameter must be callable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ecma_op_create_promise_object (arguments_list_p[0], ECMA_VALUE_UNDEFINED);
|
return ecma_op_create_promise_object (arguments_list_p[0],
|
||||||
|
ECMA_VALUE_UNDEFINED,
|
||||||
|
JERRY_CONTEXT (current_new_target_p));
|
||||||
} /* ecma_builtin_promise_dispatch_construct */
|
} /* ecma_builtin_promise_dispatch_construct */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -55,10 +55,7 @@ ecma_async_generator_enqueue (vm_executable_object_t *async_generator_object_p,
|
|||||||
task_p->operation_value = ecma_copy_value_if_not_object (value);
|
task_p->operation_value = ecma_copy_value_if_not_object (value);
|
||||||
task_p->operation_type = (uint8_t) operation;
|
task_p->operation_type = (uint8_t) operation;
|
||||||
|
|
||||||
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p);
|
ecma_value_t result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL);
|
||||||
JERRY_CONTEXT (current_new_target_p) = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
|
|
||||||
ecma_value_t result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED);
|
|
||||||
JERRY_CONTEXT (current_new_target_p) = old_new_target_p;
|
|
||||||
task_p->promise = result;
|
task_p->promise = result;
|
||||||
|
|
||||||
ecma_value_t head = async_generator_object_p->extended_object.u.class_prop.u.head;
|
ecma_value_t head = async_generator_object_p->extended_object.u.class_prop.u.head;
|
||||||
|
|||||||
@@ -424,13 +424,18 @@ ecma_promise_create_resolving_functions (ecma_promise_object_t *promise_p) /**<
|
|||||||
*/
|
*/
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function or ECMA_VALUE_EMPTY */
|
ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function or ECMA_VALUE_EMPTY */
|
||||||
ecma_value_t parent) /**< parent promise if available */
|
ecma_value_t parent, /**< parent promise if available */
|
||||||
|
ecma_object_t *new_target_p) /**< new.target value */
|
||||||
{
|
{
|
||||||
JERRY_UNUSED (parent);
|
JERRY_UNUSED (parent);
|
||||||
JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p) != NULL);
|
|
||||||
|
if (new_target_p == NULL)
|
||||||
|
{
|
||||||
|
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
|
||||||
|
}
|
||||||
|
|
||||||
/* 3. */
|
/* 3. */
|
||||||
ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p),
|
ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (new_target_p,
|
||||||
ECMA_BUILTIN_ID_PROMISE_PROTOTYPE);
|
ECMA_BUILTIN_ID_PROMISE_PROTOTYPE);
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (proto_p == NULL))
|
if (JERRY_UNLIKELY (proto_p == NULL))
|
||||||
@@ -679,12 +684,7 @@ ecma_promise_new_capability (ecma_value_t constructor, /**< constructor function
|
|||||||
|
|
||||||
if (constructor_obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE))
|
if (constructor_obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE))
|
||||||
{
|
{
|
||||||
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p);
|
promise = ecma_op_create_promise_object (executor, parent, constructor_obj_p);
|
||||||
JERRY_CONTEXT (current_new_target_p) = constructor_obj_p;
|
|
||||||
|
|
||||||
promise = ecma_op_create_promise_object (executor, parent);
|
|
||||||
|
|
||||||
JERRY_CONTEXT (current_new_target_p) = old_new_target_p;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
bool ecma_is_promise (ecma_object_t *obj_p);
|
bool ecma_is_promise (ecma_object_t *obj_p);
|
||||||
ecma_value_t ecma_op_create_promise_object (ecma_value_t executor, ecma_value_t parent);
|
ecma_value_t ecma_op_create_promise_object (ecma_value_t executor, ecma_value_t parent,
|
||||||
|
ecma_object_t *new_target_p);
|
||||||
uint16_t ecma_promise_get_flags (ecma_object_t *promise_p);
|
uint16_t ecma_promise_get_flags (ecma_object_t *promise_p);
|
||||||
ecma_value_t ecma_promise_get_result (ecma_object_t *promise_p);
|
ecma_value_t ecma_promise_get_result (ecma_object_t *promise_p);
|
||||||
void ecma_reject_promise (ecma_value_t promise, ecma_value_t reason);
|
void ecma_reject_promise (ecma_value_t promise, ecma_value_t reason);
|
||||||
|
|||||||
@@ -898,15 +898,11 @@ opfunc_async_create_and_await (vm_frame_ctx_t *frame_ctx_p, /**< frame context *
|
|||||||
ecma_deref_object ((ecma_object_t *) executable_object_p);
|
ecma_deref_object ((ecma_object_t *) executable_object_p);
|
||||||
ecma_free_value (result);
|
ecma_free_value (result);
|
||||||
|
|
||||||
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p);
|
result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, promise_p);
|
||||||
JERRY_CONTEXT (current_new_target_p) = promise_p;
|
|
||||||
|
|
||||||
result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED);
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_value_object (result));
|
JERRY_ASSERT (ecma_is_value_object (result));
|
||||||
executable_object_p->frame_ctx.block_result = result;
|
executable_object_p->frame_ctx.block_result = result;
|
||||||
|
|
||||||
JERRY_CONTEXT (current_new_target_p) = old_new_target_p;
|
|
||||||
return result;
|
return result;
|
||||||
} /* opfunc_async_create_and_await */
|
} /* opfunc_async_create_and_await */
|
||||||
|
|
||||||
|
|||||||
+1
-6
@@ -2716,12 +2716,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
|||||||
|
|
||||||
if (result == ECMA_VALUE_UNDEFINED)
|
if (result == ECMA_VALUE_UNDEFINED)
|
||||||
{
|
{
|
||||||
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p);
|
result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL);
|
||||||
JERRY_CONTEXT (current_new_target_p) = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
|
|
||||||
|
|
||||||
result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED);
|
|
||||||
|
|
||||||
JERRY_CONTEXT (current_new_target_p) = old_new_target_p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vm_stack_context_type_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]);
|
vm_stack_context_type_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user