From 156510e174f3acfc3bec7182ab968b855ec7b289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Tue, 4 Aug 2015 13:00:03 +0200 Subject: [PATCH] Fix array index normalize in case index is negative zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com --- jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp | 6 +++++- tests/jerry/array-prototype-indexof.js | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp index c48021ebe..3f011041d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp @@ -298,7 +298,11 @@ ecma_builtin_helper_array_index_normalize (ecma_number_t index, /**< index */ if (!ecma_number_is_nan (index)) { - if (ecma_number_is_infinity (index)) + if (ecma_number_is_zero (index)) + { + norm_index = 0; + } + else if (ecma_number_is_infinity (index)) { norm_index = ecma_number_is_negative (index) ? 0 : length; } diff --git a/tests/jerry/array-prototype-indexof.js b/tests/jerry/array-prototype-indexof.js index 9577de266..10ac68f85 100644 --- a/tests/jerry/array-prototype-indexof.js +++ b/tests/jerry/array-prototype-indexof.js @@ -37,6 +37,8 @@ assert(array.indexOf("foo", NaN) === 0); assert(array.indexOf("foo", Infinity) === -1); assert(array.indexOf("foo", -Infinity) === 0); +assert([true].indexOf(true, -0) === 0); + // Checking behavior when length is zero var obj = { indexOf : Array.prototype.indexOf, length : 0 }; assert(obj.indexOf("foo") === -1);