From 3d744c958f658a5edf2075c02f54de39d366b31c Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Tue, 11 Jul 2017 14:09:29 +0200 Subject: [PATCH] Shifting array element down in the tree must be finished even if an error occurs Fixes #1671 JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- .../ecma-builtin-array-prototype.c | 16 ++++++++-------- tests/jerry/fail/regression-test-issue-1671.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 tests/jerry/fail/regression-test-issue-1671.js diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c index ef10f84b5..d4997697a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c @@ -1113,16 +1113,16 @@ ecma_builtin_array_prototype_object_array_to_heap_helper (ecma_value_t array[], } } + /* + * Loop ended, either current child does not exist, or is less than swap. + * This means that 'swap' should be placed in the parent node. + */ + int parent = (child - 1) / 2; + JERRY_ASSERT (parent >= 0 && parent <= right); + array[parent] = swap; + if (ecma_is_value_empty (ret_value)) { - /* - * Loop ended, either current child does not exist, or is less than swap. - * This means that 'swap' should be placed in the parent node. - */ - int parent = (child - 1) / 2; - JERRY_ASSERT (parent >= 0 && parent <= right); - array[parent] = swap; - ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); } diff --git a/tests/jerry/fail/regression-test-issue-1671.js b/tests/jerry/fail/regression-test-issue-1671.js new file mode 100644 index 000000000..00931145f --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-1671.js @@ -0,0 +1,16 @@ +// 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. + +Array.prototype.push("A", "B", 0, 1) +Array.prototype.sort(JSON.parse)