Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: test/mjsunit/array-tostring.js

Issue 2164923002: Make toLocaleString on arrays always call toLocaleString on its elements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/array.js ('k') | test/mjsunit/es6/typedarray-tostring.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/array-tostring.js
diff --git a/test/mjsunit/array-tostring.js b/test/mjsunit/array-tostring.js
index 5be3d5045c87e8eecc8398b275b5669e5dea38d6..382bf8d7a0268c23bf08870d336a5ea9a8257be6 100644
--- a/test/mjsunit/array-tostring.js
+++ b/test/mjsunit/array-tostring.js
@@ -125,7 +125,9 @@ 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 = Array.prototype.toLocaleString;
+String.prototype.toLocaleString = function() {
+ return (this.length == 1) ? this : Array.prototype.toLocaleString.call(this);
+}
assertEquals("1,2,3,4", "1234".toLocaleString());
// If toLocaleString of element is not callable, throw a TypeError.
@@ -157,3 +159,23 @@ 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;
+})();
« no previous file with comments | « src/js/array.js ('k') | test/mjsunit/es6/typedarray-tostring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698