From: caitpotter88 Date: Tue, 3 Feb 2015 17:45:06 +0000 (-0800) Subject: Update harmony Object.prototype.toString to 2/2/2015 spec X-Git-Tag: upstream/4.7.83~4629 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=858b9b6a7e6c86464e7bb8ca87f8649ca9d1cdba;p=platform%2Fupstream%2Fv8.git Update harmony Object.prototype.toString to 2/2/2015 spec - 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} --- diff --git a/src/harmony-tostring.js b/src/harmony-tostring.js index a5d892c..aed8ca0 100644 --- a/src/harmony-tostring.js +++ b/src/harmony-tostring.js @@ -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 + "]"; } diff --git a/test/mjsunit/es6/array-tostring.js b/test/mjsunit/es6/array-tostring.js index 625011f..8a9198c 100644 --- a/test/mjsunit/es6/array-tostring.js +++ b/test/mjsunit/es6/array-tostring.js @@ -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(); diff --git a/test/mjsunit/es6/object-tostring.js b/test/mjsunit/es6/object-tostring.js index 8999a18..064f2af 100644 --- a/test/mjsunit/es6/object-tostring.js +++ b/test/mjsunit/es6/object-tostring.js @@ -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();