v8/src/harmony-tostring.js
caitpotter88 858b9b6a7e 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}
2015-02-03 17:45:20 +00:00

56 lines
1.6 KiB
JavaScript

// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js and symbol.js:
// var $Object = global.Object;
// var $Symbol = global.Symbol;
DefaultObjectToString = ObjectToStringHarmony;
// ES6 draft 08-24-14, section 19.1.3.6
function ObjectToStringHarmony() {
if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
if (IS_NULL(this)) return "[object Null]";
var O = ToObject(this);
var builtinTag = %_ClassOf(O);
var tag = O[symbolToStringTag];
if (!IS_STRING(tag)) {
tag = builtinTag;
}
return "[object " + tag + "]";
}
function HarmonyToStringExtendSymbolPrototype() {
%CheckIsBootstrapping();
InstallConstants($Symbol, $Array(
// TODO(dslomov, caitp): Move to symbol.js when shipping
"toStringTag", symbolToStringTag
));
}
HarmonyToStringExtendSymbolPrototype();
function HarmonyToStringExtendObjectPrototype() {
%CheckIsBootstrapping();
// Can't use InstallFunctions() because will fail in Debug mode.
// Emulate InstallFunctions() here.
%FunctionSetName(ObjectToStringHarmony, "toString");
%FunctionRemovePrototype(ObjectToStringHarmony);
%SetNativeFlag(ObjectToStringHarmony);
// Set up the non-enumerable functions on the Array prototype object.
var desc = ToPropertyDescriptor({
value: ObjectToStringHarmony
});
DefineOwnProperty($Object.prototype, "toString", desc, false);
%ToFastProperties($Object.prototype);
}
HarmonyToStringExtendObjectPrototype();