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

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

Issue 835753002: Implement ES6 Array.prototype.toString behind --harmony-tostring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Simplify CL Created 5 years, 11 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/harmony-tostring.js ('k') | test/mjsunit/es6/object-tostring.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/array-tostring.js
diff --git a/test/mjsunit/es6/object-tostring.js b/test/mjsunit/es6/array-tostring.js
similarity index 68%
copy from test/mjsunit/es6/object-tostring.js
copy to test/mjsunit/es6/array-tostring.js
index 26dff14b9d29519e24bdc38c6e8d26ae83dc2336..625011f4387cc79b7ffd6df6eef8a44a3a269cd0 100644
--- a/test/mjsunit/es6/object-tostring.js
+++ b/test/mjsunit/es6/array-tostring.js
@@ -9,7 +9,6 @@ var global = this;
var funs = {
Object: [ Object ],
Function: [ Function ],
- Array: [ Array ],
String: [ String ],
Boolean: [ Boolean ],
Number: [ Number ],
@@ -21,20 +20,21 @@ var funs = {
for (f in funs) {
for (i in funs[f]) {
assertEquals("[object " + f + "]",
- Object.prototype.toString.call(new funs[f][i]),
+ Array.prototype.toString.call(new funs[f][i]),
funs[f][i]);
assertEquals("[object Function]",
- Object.prototype.toString.call(funs[f][i]),
+ Array.prototype.toString.call(funs[f][i]),
funs[f][i]);
}
}
+
function testToStringTag(className) {
// Using builtin toStringTags
var obj = {};
obj[Symbol.toStringTag] = className;
assertEquals("[object ~" + className + "]",
- Object.prototype.toString.call(obj));
+ Array.prototype.toString.call(obj));
// Getter throws
obj = {};
@@ -42,7 +42,7 @@ function testToStringTag(className) {
get: function() { throw className; }
});
assertThrows(function() {
- Object.prototype.toString.call(obj);
+ Array.prototype.toString.call(obj);
}, className);
// Getter does not throw
@@ -51,13 +51,13 @@ function testToStringTag(className) {
get: function() { return className; }
});
assertEquals("[object ~" + className + "]",
- Object.prototype.toString.call(obj));
+ Array.prototype.toString.call(obj));
// Custom, non-builtin toStringTags
obj = {};
obj[Symbol.toStringTag] = "X" + className;
assertEquals("[object X" + className + "]",
- Object.prototype.toString.call(obj));
+ Array.prototype.toString.call(obj));
// With getter
obj = {};
@@ -65,14 +65,14 @@ function testToStringTag(className) {
get: function() { return "X" + className; }
});
assertEquals("[object X" + className + "]",
- Object.prototype.toString.call(obj));
+ Array.prototype.toString.call(obj));
// Undefined toStringTag should return [object className]
var obj = className === "Arguments" ?
(function() { return arguments; })() : new global[className];
obj[Symbol.toStringTag] = undefined;
assertEquals("[object " + className + "]",
- Object.prototype.toString.call(obj));
+ Array.prototype.toString.call(obj));
// With getter
var obj = className === "Arguments" ?
@@ -81,12 +81,12 @@ function testToStringTag(className) {
get: function() { return undefined; }
});
assertEquals("[object " + className + "]",
- Object.prototype.toString.call(obj));
+ Array.prototype.toString.call(obj));
}
+
[
"Arguments",
- "Array",
"Boolean",
"Date",
"Error",
@@ -96,19 +96,21 @@ function testToStringTag(className) {
"String"
].forEach(testToStringTag);
+
function testToStringTagNonString(value) {
var obj = {};
obj[Symbol.toStringTag] = value;
- assertEquals("[object ???]", Object.prototype.toString.call(obj));
+ assertEquals("[object ???]", Array.prototype.toString.call(obj));
// With getter
obj = {};
Object.defineProperty(obj, Symbol.toStringTag, {
get: function() { return value; }
});
- assertEquals("[object ???]", Object.prototype.toString.call(obj));
+ assertEquals("[object ???]", Array.prototype.toString.call(obj));
}
+
[
null,
function() {},
@@ -124,10 +126,32 @@ function testToStringTagNonString(value) {
new String("str")
].forEach(testToStringTagNonString);
-function testObjectToStringPropertyDesc() {
+
+function testArrayToStringPropertyDesc() {
var desc = Object.getOwnPropertyDescriptor(Object.prototype, "toString");
assertTrue(desc.writable);
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
}
-testObjectToStringPropertyDesc();
+testArrayToStringPropertyDesc();
+
+
+function testArrayToStringOwnNonStringValue() {
+ var obj = Object.defineProperty({}, Symbol.toStringTag, { value: 1 });
+ assertEquals("[object ???]", ([]).toString.call(obj));
+}
+testArrayToStringOwnNonStringValue();
+
+
+function testArrayToStringBasic() {
+ assertEquals("1,2,3", [1,2,3].toString());
+ assertEquals(",,3", [,,3].toString());
+}
+testArrayToStringBasic();
+
+
+function testArrayToStringObjectWithCallableJoin() {
+ var obj = { join: function() { return "CallableJoin"; } };
+ assertEquals("CallableJoin", Array.prototype.toString.call(obj));
+}
+testArrayToStringObjectWithCallableJoin();
« no previous file with comments | « src/harmony-tostring.js ('k') | test/mjsunit/es6/object-tostring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698