aed8ca03997120f266d6545f6f589759ac7796b0
[platform/upstream/nodejs.git] / deps / v8 / src / harmony-tostring.js
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.
4
5 "use strict";
6
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;
11
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)) {
21     tag = builtinTag;
22   }
23   return "[object " + tag + "]";
24 }
25
26 function HarmonyToStringExtendSymbolPrototype() {
27   %CheckIsBootstrapping();
28
29   InstallConstants($Symbol, $Array(
30     // TODO(dslomov, caitp): Move to symbol.js when shipping
31    "toStringTag", symbolToStringTag
32   ));
33 }
34
35 HarmonyToStringExtendSymbolPrototype();
36
37 function HarmonyToStringExtendObjectPrototype() {
38   %CheckIsBootstrapping();
39
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);
45
46   // Set up the non-enumerable functions on the Array prototype object.
47   var desc = ToPropertyDescriptor({
48     value: ObjectToStringHarmony
49   });
50   DefineOwnProperty($Object.prototype, "toString", desc, false);
51
52   %ToFastProperties($Object.prototype);
53 }
54
55 HarmonyToStringExtendObjectPrototype();