diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array.c b/jerry-core/ecma/builtin-objects/ecma-builtin-array.c index b6638b596..cea68674a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array.c @@ -321,14 +321,12 @@ iterator_cleanup: while (k < len) { /* 16.b */ - ecma_string_t *pk = ecma_new_ecma_string_from_uint32 (k); - ecma_value_t k_value = ecma_op_object_get (array_like_obj_p, pk); - ecma_deref_ecma_string (pk); + ecma_value_t k_value = ecma_op_object_get_by_uint32_index (array_like_obj_p, k); /* 16.c */ if (ECMA_IS_VALUE_ERROR (k_value)) { - goto cleanup; + goto construct_cleanup; } ecma_value_t mapped_value; @@ -344,7 +342,7 @@ iterator_cleanup: /* 16.d.ii */ if (ECMA_IS_VALUE_ERROR (mapped_value)) { - goto cleanup; + goto construct_cleanup; } } else @@ -362,7 +360,7 @@ iterator_cleanup: /* 16.g */ if (ECMA_IS_VALUE_ERROR (set_status)) { - goto cleanup; + goto construct_cleanup; } /* 16.h */ @@ -380,12 +378,15 @@ iterator_cleanup: /* 18. */ if (ECMA_IS_VALUE_ERROR (set_status)) { - goto cleanup; + goto construct_cleanup; } /* 19. */ - ret_value = ecma_make_object_value (array_obj_p); + ecma_deref_object (array_like_obj_p); + return ecma_make_object_value (array_obj_p); +construct_cleanup: + ecma_deref_object (array_obj_p); cleanup: ecma_deref_object (array_like_obj_p); return ret_value; diff --git a/tests/jerry/es2015/regression-test-issue-3420.js b/tests/jerry/es2015/regression-test-issue-3420.js new file mode 100644 index 000000000..6612843b1 --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-3420.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. + +try { + Array.from.call(String, $); + function $() {} + assert(fasle); +} catch (e) { + assert(e instanceof TypeError); +}