diff --git a/jerry-core/ecma/operations/ecma-jobqueue.c b/jerry-core/ecma/operations/ecma-jobqueue.c index 05a88ad47..6dd2bdc62 100644 --- a/jerry-core/ecma/operations/ecma-jobqueue.c +++ b/jerry-core/ecma/operations/ecma-jobqueue.c @@ -232,14 +232,20 @@ ecma_process_promise_resolve_thenable_job (void *obj_p) /**< the job to be opera { ecma_job_promise_resolve_thenable_t *job_p = (ecma_job_promise_resolve_thenable_t *) obj_p; ecma_object_t *promise_p = ecma_get_object_from_value (job_p->promise); + ecma_promise_resolving_functions_t *funcs = ecma_promise_create_resolving_functions (promise_p); ecma_string_t str_resolve, str_reject; ecma_init_ecma_magic_string (&str_resolve, LIT_INTERNAL_MAGIC_STRING_RESOLVE_FUNCTION); ecma_init_ecma_magic_string (&str_reject, LIT_INTERNAL_MAGIC_STRING_REJECT_FUNCTION); + ecma_op_object_put (promise_p, + &str_resolve, + funcs->resolve, + false); + ecma_op_object_put (promise_p, + &str_reject, + funcs->reject, + false); - ecma_value_t resolve = ecma_op_object_get (promise_p, &str_resolve); - ecma_value_t reject = ecma_op_object_get (promise_p, &str_reject); - - ecma_value_t argv[] = { resolve, reject }; + ecma_value_t argv[] = { funcs->resolve, funcs->reject }; ecma_value_t ret; ecma_value_t then_call_result = ecma_op_function_call (ecma_get_object_from_value (job_p->then), job_p->thenable, @@ -250,7 +256,7 @@ ecma_process_promise_resolve_thenable_job (void *obj_p) /**< the job to be opera if (ECMA_IS_VALUE_ERROR (then_call_result)) { - ret = ecma_op_function_call (ecma_get_object_from_value (reject), + ret = ecma_op_function_call (ecma_get_object_from_value (funcs->reject), ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), &then_call_result, 1); @@ -258,8 +264,7 @@ ecma_process_promise_resolve_thenable_job (void *obj_p) /**< the job to be opera ecma_free_value (then_call_result); } - ecma_free_value (resolve); - ecma_free_value (reject); + ecma_promise_free_resolving_functions (funcs); ecma_free_promise_resolve_thenable_job (job_p); return ret; diff --git a/jerry-core/ecma/operations/ecma-promise-object.c b/jerry-core/ecma/operations/ecma-promise-object.c index ac22b4ed1..3a075870d 100644 --- a/jerry-core/ecma/operations/ecma-promise-object.c +++ b/jerry-core/ecma/operations/ecma-promise-object.c @@ -412,7 +412,7 @@ ecma_call_builtin_executor (ecma_object_t *executor_p, /**< the executor object * * @return pointer to the resolving functions */ -static ecma_promise_resolving_functions_t * +ecma_promise_resolving_functions_t * ecma_promise_create_resolving_functions (ecma_object_t *object_p) /**< the promise object */ { /* 1. */ @@ -463,7 +463,7 @@ ecma_promise_create_resolving_functions (ecma_object_t *object_p) /**< the promi /** * Free the heap and the member of the resolving functions. */ -static void +void ecma_promise_free_resolving_functions (ecma_promise_resolving_functions_t *funcs) /**< points to the functions */ { ecma_free_value (funcs->resolve); diff --git a/jerry-core/ecma/operations/ecma-promise-object.h b/jerry-core/ecma/operations/ecma-promise-object.h index c4422bd57..d688be1dc 100644 --- a/jerry-core/ecma/operations/ecma-promise-object.h +++ b/jerry-core/ecma/operations/ecma-promise-object.h @@ -97,6 +97,9 @@ ecma_value_t ecma_promise_then (ecma_value_t promise, ecma_value_t on_fulfilled, ecma_value_t on_rejected); +ecma_promise_resolving_functions_t * +ecma_promise_create_resolving_functions (ecma_object_t *object_p); +void ecma_promise_free_resolving_functions (ecma_promise_resolving_functions_t *funcs); /** * @} diff --git a/tests/jerry-test-suite/es2015/25/25.04/25.04.05/25.04.05-006.js b/tests/jerry-test-suite/es2015/25/25.04/25.04.05/25.04.05-006.js new file mode 100644 index 000000000..6b2ff98f1 --- /dev/null +++ b/tests/jerry-test-suite/es2015/25/25.04/25.04.05/25.04.05-006.js @@ -0,0 +1,26 @@ +/* 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. + */ + +// Test the thenable job. + +var p = Promise.resolve(1).then(function(x) { + assert(x === 1); + return Promise.resolve(2); +}).then(function(x) { + assert(x === 2); + return Promise.reject(3); +}).catch(function(x) { + assert(x === 3); +});