Update harmony Object.prototype.toString to 2/2/2015 spec
authorcaitpotter88 <caitpotter88@gmail.com>
Tue, 3 Feb 2015 17:45:06 +0000 (09:45 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 3 Feb 2015 17:45:20 +0000 (17:45 +0000)
- Removes special handling of non-string @@toStringTag values (use builtinTag)
- Removes special handling of @@toStringTags which match [[Class]] names (remove ~ prefix)

BUG=v8:3502
R=arv@chromium.org
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#26411}

src/harmony-tostring.js
test/mjsunit/es6/array-tostring.js
test/mjsunit/es6/object-tostring.js

index a5d892c..aed8ca0 100644 (file)
@@ -9,19 +9,6 @@
 // var $Object = global.Object;
 // var $Symbol = global.Symbol;
 
-var kBuiltinStringTags = {
-  "__proto__": null,
-  "Arguments": true,
-  "Array": true,
-  "Boolean": true,
-  "Date": true,
-  "Error": true,
-  "Function": true,
-  "Number": true,
-  "RegExp": true,
-  "String": true
-};
-
 DefaultObjectToString = ObjectToStringHarmony;
 // ES6 draft 08-24-14, section 19.1.3.6
 function ObjectToStringHarmony() {
@@ -30,12 +17,8 @@ function ObjectToStringHarmony() {
   var O = ToObject(this);
   var builtinTag = %_ClassOf(O);
   var tag = O[symbolToStringTag];
-  if (IS_UNDEFINED(tag)) {
+  if (!IS_STRING(tag)) {
     tag = builtinTag;
-  } else if (!IS_STRING(tag)) {
-    return "[object ???]";
-  } else if (tag !== builtinTag && kBuiltinStringTags[tag]) {
-    return "[object ~" + tag + "]";
   }
   return "[object " + tag + "]";
 }
index 625011f..8a9198c 100644 (file)
@@ -33,7 +33,7 @@ function testToStringTag(className) {
   // Using builtin toStringTags
   var obj = {};
   obj[Symbol.toStringTag] = className;
-  assertEquals("[object ~" + className + "]",
+  assertEquals("[object " + className + "]",
                Array.prototype.toString.call(obj));
 
   // Getter throws
@@ -50,7 +50,7 @@ function testToStringTag(className) {
   Object.defineProperty(obj, Symbol.toStringTag, {
     get: function() { return className; }
   });
-  assertEquals("[object ~" + className + "]",
+  assertEquals("[object " + className + "]",
                Array.prototype.toString.call(obj));
 
   // Custom, non-builtin toStringTags
@@ -100,14 +100,14 @@ function testToStringTag(className) {
 function testToStringTagNonString(value) {
   var obj = {};
   obj[Symbol.toStringTag] = value;
-  assertEquals("[object ???]", Array.prototype.toString.call(obj));
+  assertEquals("[object Object]", Array.prototype.toString.call(obj));
 
   // With getter
   obj = {};
   Object.defineProperty(obj, Symbol.toStringTag, {
     get: function() { return value; }
   });
-  assertEquals("[object ???]", Array.prototype.toString.call(obj));
+  assertEquals("[object Object]", Array.prototype.toString.call(obj));
 }
 
 
@@ -138,7 +138,7 @@ testArrayToStringPropertyDesc();
 
 function testArrayToStringOwnNonStringValue() {
   var obj = Object.defineProperty({}, Symbol.toStringTag, { value: 1 });
-  assertEquals("[object ???]", ([]).toString.call(obj));
+  assertEquals("[object Object]", ([]).toString.call(obj));
 }
 testArrayToStringOwnNonStringValue();
 
index 8999a18..064f2af 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --harmony-tostring
+// Flags: --harmony-tostring --allow-natives-syntax
 
 var global = this;
 
@@ -33,7 +33,7 @@ function testToStringTag(className) {
   // Using builtin toStringTags
   var obj = {};
   obj[Symbol.toStringTag] = className;
-  assertEquals("[object ~" + className + "]",
+  assertEquals("[object " + className + "]",
                Object.prototype.toString.call(obj));
 
   // Getter throws
@@ -50,7 +50,7 @@ function testToStringTag(className) {
   Object.defineProperty(obj, Symbol.toStringTag, {
     get: function() { return className; }
   });
-  assertEquals("[object ~" + className + "]",
+  assertEquals("[object " + className + "]",
                Object.prototype.toString.call(obj));
 
   // Custom, non-builtin toStringTags
@@ -99,14 +99,14 @@ function testToStringTag(className) {
 function testToStringTagNonString(value) {
   var obj = {};
   obj[Symbol.toStringTag] = value;
-  assertEquals("[object ???]", Object.prototype.toString.call(obj));
+  assertEquals("[object Object]", Object.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 Object]", Object.prototype.toString.call(obj));
 }
 
 [
@@ -134,6 +134,6 @@ testObjectToStringPropertyDesc();
 
 function testObjectToStringOwnNonStringValue() {
   var obj = Object.defineProperty({}, Symbol.toStringTag, { value: 1 });
-  assertEquals("[object ???]", ({}).toString.call(obj));
+  assertEquals("[object Object]", ({}).toString.call(obj));
 }
 testObjectToStringOwnNonStringValue();