Commit 858b9b6a authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

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}
parent a6d0e6a7
......@@ -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 + "]";
}
......
......@@ -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();
......
......@@ -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();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment