// 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() {
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 + "]";
}
// Using builtin toStringTags
var obj = {};
obj[Symbol.toStringTag] = className;
- assertEquals("[object ~" + className + "]",
+ assertEquals("[object " + className + "]",
Array.prototype.toString.call(obj));
// Getter throws
Object.defineProperty(obj, Symbol.toStringTag, {
get: function() { return className; }
});
- assertEquals("[object ~" + className + "]",
+ assertEquals("[object " + className + "]",
Array.prototype.toString.call(obj));
// Custom, non-builtin toStringTags
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));
}
function testArrayToStringOwnNonStringValue() {
var obj = Object.defineProperty({}, Symbol.toStringTag, { value: 1 });
- assertEquals("[object ???]", ([]).toString.call(obj));
+ assertEquals("[object Object]", ([]).toString.call(obj));
}
testArrayToStringOwnNonStringValue();
// 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;
// Using builtin toStringTags
var obj = {};
obj[Symbol.toStringTag] = className;
- assertEquals("[object ~" + className + "]",
+ assertEquals("[object " + className + "]",
Object.prototype.toString.call(obj));
// Getter throws
Object.defineProperty(obj, Symbol.toStringTag, {
get: function() { return className; }
});
- assertEquals("[object ~" + className + "]",
+ assertEquals("[object " + className + "]",
Object.prototype.toString.call(obj));
// Custom, non-builtin toStringTags
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));
}
[
function testObjectToStringOwnNonStringValue() {
var obj = Object.defineProperty({}, Symbol.toStringTag, { value: 1 });
- assertEquals("[object ???]", ({}).toString.call(obj));
+ assertEquals("[object Object]", ({}).toString.call(obj));
}
testObjectToStringOwnNonStringValue();