1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js and symbol.js:
9 // var $Object = global.Object;
10 // var $Symbol = global.Symbol;
12 DefaultObjectToString = ObjectToStringHarmony;
13 // ES6 draft 08-24-14, section 19.1.3.6
14 function ObjectToStringHarmony() {
15 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
16 if (IS_NULL(this)) return "[object Null]";
17 var O = ToObject(this);
18 var builtinTag = %_ClassOf(O);
19 var tag = O[symbolToStringTag];
20 if (!IS_STRING(tag)) {
23 return "[object " + tag + "]";
26 function HarmonyToStringExtendSymbolPrototype() {
27 %CheckIsBootstrapping();
29 InstallConstants($Symbol, $Array(
30 // TODO(dslomov, caitp): Move to symbol.js when shipping
31 "toStringTag", symbolToStringTag
35 HarmonyToStringExtendSymbolPrototype();
37 function HarmonyToStringExtendObjectPrototype() {
38 %CheckIsBootstrapping();
40 // Can't use InstallFunctions() because will fail in Debug mode.
41 // Emulate InstallFunctions() here.
42 %FunctionSetName(ObjectToStringHarmony, "toString");
43 %FunctionRemovePrototype(ObjectToStringHarmony);
44 %SetNativeFlag(ObjectToStringHarmony);
46 // Set up the non-enumerable functions on the Array prototype object.
47 var desc = ToPropertyDescriptor({
48 value: ObjectToStringHarmony
50 DefineOwnProperty($Object.prototype, "toString", desc, false);
52 %ToFastProperties($Object.prototype);
55 HarmonyToStringExtendObjectPrototype();