Revert "Make toLocaleString on arrays always call toLocaleString on its elements."
This reverts commit 457c02573c
because it caused a
regression in SunSpider/string-fasta and possibly AreWeFastYet/Life. Need to
implement this in a smarter way.
TBR=littledan@chromium.org
BUG=chromium:627729,v8:5113
Review-Url: https://codereview.chromium.org/2149303003
Cr-Commit-Position: refs/heads/master@{#37793}
This commit is contained in:
parent
9f859c66a1
commit
f47e722403
@ -151,7 +151,8 @@ function DoJoin(array, length, is_array, separator, convert) {
|
||||
|
||||
// Fast case for one-element arrays.
|
||||
if (length === 1) {
|
||||
return convert(array[0]);
|
||||
var e = array[0];
|
||||
return IS_STRING(e) ? e : convert(e);
|
||||
}
|
||||
|
||||
// Construct an array for the elements.
|
||||
@ -160,14 +161,31 @@ function DoJoin(array, length, is_array, separator, convert) {
|
||||
// We pull the empty separator check outside the loop for speed!
|
||||
if (separator === '') {
|
||||
for (var i = 0; i < length; i++) {
|
||||
elements[i] = convert(array[i]);
|
||||
var e = array[i];
|
||||
elements[i] = IS_STRING(e) ? e : convert(e);
|
||||
}
|
||||
return %StringBuilderConcat(elements, length, '');
|
||||
}
|
||||
// Non-empty separator case.
|
||||
elements[0] = convert(array[0]);
|
||||
for (var i = 1; i < length; i++) {
|
||||
elements[i] = convert(array[i]);
|
||||
// If the first element is a number then use the heuristic that the
|
||||
// remaining elements are also likely to be numbers.
|
||||
var e = array[0];
|
||||
if (IS_NUMBER(e)) {
|
||||
elements[0] = %_NumberToString(e);
|
||||
for (var i = 1; i < length; i++) {
|
||||
e = array[i];
|
||||
if (IS_NUMBER(e)) {
|
||||
elements[i] = %_NumberToString(e);
|
||||
} else {
|
||||
elements[i] = IS_STRING(e) ? e : convert(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elements[0] = IS_STRING(e) ? e : convert(e);
|
||||
for (var i = 1; i < length; i++) {
|
||||
e = array[i];
|
||||
elements[i] = IS_STRING(e) ? e : convert(e);
|
||||
}
|
||||
}
|
||||
return %StringBuilderJoin(elements, length, separator);
|
||||
}
|
||||
|
@ -125,9 +125,7 @@ var la1 = [1, [2, 3], 4];
|
||||
assertEquals("1,2,3,4", la1.toLocaleString());
|
||||
|
||||
// Used on a string (which looks like an array of characters).
|
||||
String.prototype.toLocaleString = function() {
|
||||
return (this.length == 1) ? this : Array.prototype.toLocaleString.call(this);
|
||||
}
|
||||
String.prototype.toLocaleString = Array.prototype.toLocaleString;
|
||||
assertEquals("1,2,3,4", "1234".toLocaleString());
|
||||
|
||||
// If toLocaleString of element is not callable, throw a TypeError.
|
||||
@ -159,23 +157,3 @@ for (var i = 0; i < 3; i++) {
|
||||
}
|
||||
Number.prototype.arrayToLocaleString = Array.prototype.toLocaleString;
|
||||
assertEquals("42,42,42", (42).arrayToLocaleString());
|
||||
|
||||
|
||||
(function TestToLocaleStringCalls() {
|
||||
let log = [];
|
||||
let pushArgs = (label) => (...args) => log.push(label, args);
|
||||
|
||||
let NumberToLocaleString = Number.prototype.toLocaleString;
|
||||
let StringToLocaleString = String.prototype.toLocaleString;
|
||||
let ObjectToLocaleString = Object.prototype.toLocaleString;
|
||||
Number.prototype.toLocaleString = pushArgs("Number");
|
||||
String.prototype.toLocaleString = pushArgs("String");
|
||||
Object.prototype.toLocaleString = pushArgs("Object");
|
||||
|
||||
[42, "foo", {}].toLocaleString();
|
||||
assertEquals(["Number", [], "String", [], "Object", []], log);
|
||||
|
||||
Number.prototype.toLocaleString = NumberToLocaleString;
|
||||
String.prototype.toLocaleString = StringToLocaleString;
|
||||
Object.prototype.toLocaleString = ObjectToLocaleString;
|
||||
})();
|
||||
|
@ -83,17 +83,4 @@ for (var constructor of typedArrayConstructors) {
|
||||
assertEquals("1,2", Array.prototype.join.call(a5));
|
||||
assertEquals("1,2,3", Array.prototype.toString.call(a5));
|
||||
assertEquals("1,2", Array.prototype.toLocaleString.call(a5));
|
||||
|
||||
(function TestToLocaleStringCalls() {
|
||||
let log = [];
|
||||
let pushArgs = (label) => (...args) => log.push(label, args);
|
||||
|
||||
let NumberToLocaleString = Number.prototype.toLocaleString;
|
||||
Number.prototype.toLocaleString = pushArgs("Number");
|
||||
|
||||
(new constructor([1, 2])).toLocaleString();
|
||||
assertEquals(["Number", [], "Number", []], log);
|
||||
|
||||
Number.prototype.toLocaleString = NumberToLocaleString;
|
||||
})();
|
||||
}
|
||||
|
@ -335,6 +335,17 @@
|
||||
# https://bugs.chromium.org/p/v8/issues/detail?id=5012
|
||||
'intl402/Intl/getCanonicalLocales/*': [FAIL],
|
||||
|
||||
# https://bugs.chromium.org/p/v8/issues/detail?id=5113
|
||||
'built-ins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring': [FAIL],
|
||||
'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof': [FAIL],
|
||||
|
||||
# https://bugs.chromium.org/p/v8/issues/detail?id=5115
|
||||
'language/statements/class/subclass/class-definition-null-proto-missing-return-override': [FAIL],
|
||||
'language/statements/class/subclass/class-definition-null-proto-this': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user