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;
11 DefaultObjectToString = ObjectToStringHarmony;
12 // ES6 draft 08-24-14, section 19.1.3.6
13 function ObjectToStringHarmony() {
14 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
15 if (IS_NULL(this)) return "[object Null]";
16 var O = ToObject(this);
17 var builtinTag = %_ClassOf(O);
18 var tag = O[symbolToStringTag];
19 if (!IS_STRING(tag)) {
22 return "[object " + tag + "]";
25 function HarmonyToStringExtendSymbolPrototype() {
26 %CheckIsBootstrapping();
28 InstallConstants(global.Symbol, $Array(
29 // TODO(dslomov, caitp): Move to symbol.js when shipping
30 "toStringTag", symbolToStringTag
34 HarmonyToStringExtendSymbolPrototype();
36 function HarmonyToStringExtendObjectPrototype() {
37 %CheckIsBootstrapping();
39 // Can't use InstallFunctions() because will fail in Debug mode.
40 // Emulate InstallFunctions() here.
41 %FunctionSetName(ObjectToStringHarmony, "toString");
42 %FunctionRemovePrototype(ObjectToStringHarmony);
43 %SetNativeFlag(ObjectToStringHarmony);
45 // Set up the non-enumerable functions on the Array prototype object.
46 var desc = ToPropertyDescriptor({
47 value: ObjectToStringHarmony
49 DefineOwnProperty($Object.prototype, "toString", desc, false);
51 %ToFastProperties($Object.prototype);
54 HarmonyToStringExtendObjectPrototype();