diff --git a/jerry-core/ecma/operations/ecma-promise-object.c b/jerry-core/ecma/operations/ecma-promise-object.c index 35bbc7c72..990488596 100644 --- a/jerry-core/ecma/operations/ecma-promise-object.c +++ b/jerry-core/ecma/operations/ecma-promise-object.c @@ -218,7 +218,6 @@ ecma_promise_reject_handler (const ecma_value_t function, /**< the function itse const ecma_length_t argc) /**< argument number */ { JERRY_UNUSED (this); - JERRY_UNUSED (argc); ecma_string_t str_promise; ecma_string_t str_already_resolved; @@ -242,8 +241,10 @@ ecma_promise_reject_handler (const ecma_value_t function, /**< the function itse /* 5. */ ecma_set_already_resolved_value (already_resolved, true); + /* 6. */ - ecma_reject_promise (promise, argv[0]); + ecma_value_t reject_value = (argc == 0) ? ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED) : argv[0]; + ecma_reject_promise (promise, reject_value); ecma_free_value (promise); ecma_free_value (already_resolved); return ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); @@ -263,7 +264,6 @@ ecma_promise_resolve_handler (const ecma_value_t function, /**< the function its const ecma_length_t argc) /**< argument number */ { JERRY_UNUSED (this); - JERRY_UNUSED (argc); ecma_string_t str_promise; ecma_string_t str_already_resolved; @@ -286,6 +286,13 @@ ecma_promise_resolve_handler (const ecma_value_t function, /**< the function its /* 5. */ ecma_set_already_resolved_value (already_resolved, true); + /* If the argc is 0, then fulfill the `undefined`. */ + if (argc == 0) + { + ecma_fulfill_promise (promise, ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED)); + goto end_of_resolve_function; + } + /* 6. */ if (argv[0] == promise) { diff --git a/tests/jerry/es2015/regression-test-issue-1996.js b/tests/jerry/es2015/regression-test-issue-1996.js new file mode 100644 index 000000000..4cd2b2f68 --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-1996.js @@ -0,0 +1,21 @@ +// 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. + +new Promise(function(f) { + f.apply() +}); + +new Promise(function(f, r) { + r.apply() +});