Implement other routines of Promise (#1729)

Add Promise.resolve, Promise.reject, Promise.race, Promise.all and
Promise.prototype.catch

Also it fixes the issue 1763

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
Zidong Jiang
2017-04-26 19:47:51 +08:00
committed by GitHub
parent 9d4123c3c4
commit 078f6e101d
20 changed files with 1044 additions and 138 deletions
+22 -15
View File
@@ -136,13 +136,15 @@ ecma_process_promise_reaction_job (void *obj_p) /**< the job to be operated */
ecma_job_promise_reaction_t *job_p = (ecma_job_promise_reaction_t *) obj_p;
ecma_object_t *reaction_p = ecma_get_object_from_value (job_p->reaction);
ecma_string_t *str_0 = ecma_new_ecma_string_from_uint32 (0);
ecma_string_t *str_1 = ecma_new_ecma_string_from_uint32 (1);
ecma_string_t *str_2 = ecma_new_ecma_string_from_uint32 (2);
/* 2. string '0' indicates the [[Capability]] of reaction. */
ecma_value_t capability = ecma_op_object_get (reaction_p, str_0);
/* 3. string '1' indicates the [[Handler]] of reaction. */
ecma_value_t handler = ecma_op_object_get (reaction_p, str_1);
ecma_string_t *str_capability = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_CAPABILITY);
ecma_string_t *str_handler = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_HANDLER);
ecma_string_t *str_resolve = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
ecma_string_t *str_reject = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
/* 2. */
ecma_value_t capability = ecma_op_object_get (reaction_p, str_capability);
/* 3. */
ecma_value_t handler = ecma_op_object_get (reaction_p, str_handler);
JERRY_ASSERT (ecma_is_value_boolean (handler) || ecma_op_is_callable (handler));
@@ -166,9 +168,13 @@ ecma_process_promise_reaction_job (void *obj_p) /**< the job to be operated */
if (ecma_is_value_false (handler) || ECMA_IS_VALUE_ERROR (handler_result))
{
/* 7. String '2' indicates [[Reject]] of Capability. */
handler_result = ecma_get_value_from_error_value (handler_result);
ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability), str_2);
if (ECMA_IS_VALUE_ERROR (handler_result))
{
handler_result = ecma_get_value_from_error_value (handler_result);
}
/* 7. */
ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability), str_reject);
JERRY_ASSERT (ecma_op_is_callable (reject));
@@ -180,8 +186,8 @@ ecma_process_promise_reaction_job (void *obj_p) /**< the job to be operated */
}
else
{
/* 8. String '1' indicates [[Resolve]] of Capability. */
ecma_value_t resolve = ecma_op_object_get (ecma_get_object_from_value (capability), str_1);
/* 8. */
ecma_value_t resolve = ecma_op_object_get (ecma_get_object_from_value (capability), str_resolve);
JERRY_ASSERT (ecma_op_is_callable (resolve));
@@ -195,9 +201,10 @@ ecma_process_promise_reaction_job (void *obj_p) /**< the job to be operated */
ecma_free_value (handler_result);
ecma_free_value (handler);
ecma_free_value (capability);
ecma_deref_ecma_string (str_0);
ecma_deref_ecma_string (str_1);
ecma_deref_ecma_string (str_2);
ecma_deref_ecma_string (str_capability);
ecma_deref_ecma_string (str_handler);
ecma_deref_ecma_string (str_resolve);
ecma_deref_ecma_string (str_reject);
ecma_free_promise_reaction_job (job_p);
return status;