Commit 8798ef2d authored by littledan's avatar littledan Committed by Commit bot

Ensure Array.prototype.indexOf returns +0 rather than -0

A recent ES2016 draft spec clarification indicates that, if -0 is
passed into Array.prototype.indexOf or Array.prototype.lastIndexOf
as the starting index, and the result is found at index 0, then +0
rather than -0 should be returned. This patch ensures that V8 has
that result, which is consistent with what some other browsers
return. The patch allows a couple test262 tests to pass.

R=adamk
LOG=Y

Review URL: https://codereview.chromium.org/1729653002

Cr-Commit-Position: refs/heads/master@{#34229}
parent c8c5b3fd
......@@ -1347,7 +1347,7 @@ function InnerArrayIndexOf(array, element, index, length) {
if (IS_UNDEFINED(index)) {
index = 0;
} else {
index = TO_INTEGER(index);
index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0
// If index is negative, index from the end of the array.
if (index < 0) {
index = length + index;
......@@ -1409,7 +1409,7 @@ function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) {
if (argumentsLength < 2) {
index = length - 1;
} else {
index = TO_INTEGER(index);
index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0
// If index is negative, index from end of the array.
if (index < 0) index += length;
// If index is still negative, do not search the array.
......
......@@ -331,11 +331,6 @@
'intl402/Collator/prototype/compare/10.3.2_CS_d_NN': [PASS, FAIL_OK],
'intl402/Date/prototype/13.3.0_7': [PASS, FAIL_OK],
# Some tests are too strict, checking SameValue rather than ===
# https://github.com/tc39/test262/issues/435
'built-ins/Array/prototype/indexOf/15.4.4.14-5-9': [FAIL],
'built-ins/Array/prototype/lastIndexOf/15.4.4.15-5-9': [FAIL],
# https://github.com/tc39/test262/issues/489
# Test will pass in 0 or -GMT, but fail in +GMT
'language/statements/class/subclass/builtin-objects/Date/regular-subclassing': [PASS, FAIL_OK],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment