Reviewers: arv,
Message:
PTAL -- pretty trivial, might be some comments still need to be removed in
tests
though
Description:
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
[email protected]
LOG=N
Please review this at https://codereview.chromium.org/895633004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+12, -29 lines):
M src/harmony-tostring.js
M test/mjsunit/es6/array-tostring.js
M test/mjsunit/es6/object-tostring.js
Index: src/harmony-tostring.js
diff --git a/src/harmony-tostring.js b/src/harmony-tostring.js
index
a5d892c8e23af6ce90accaff70320114eae844e9..aed8ca03997120f266d6545f6f589759ac7796b0
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 + "]";
}
Index: test/mjsunit/es6/array-tostring.js
diff --git a/test/mjsunit/es6/array-tostring.js
b/test/mjsunit/es6/array-tostring.js
index
625011f4387cc79b7ffd6df6eef8a44a3a269cd0..8a9198ca16353905704876c2ff1442ceb2b9dc22
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();
Index: test/mjsunit/es6/object-tostring.js
diff --git a/test/mjsunit/es6/object-tostring.js
b/test/mjsunit/es6/object-tostring.js
index
8999a180821cf554e66f4fda4d9e80b74b590775..064f2af675f55071da291a087167f625afaf1af5
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();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.