blob: 0336456bb2827c13c75bd5f823731a2223e65540 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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
12var kBuiltinStringTags = {
13 "__proto__": null,
14 "Arguments": true,
15 "Array": true,
16 "Boolean": true,
17 "Date": true,
18 "Error": true,
19 "Function": true,
20 "Number": true,
21 "RegExp": true,
22 "String": true
23};
24
25DefaultObjectToString = ObjectToStringHarmony;
26// ES6 draft 08-24-14, section 19.1.3.6
27function ObjectToStringHarmony() {
28 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
29 if (IS_NULL(this)) return "[object Null]";
30 var O = ToObject(this);
31 var builtinTag = %_ClassOf(O);
32 var tag = O[symbolToStringTag];
33 if (IS_UNDEFINED(tag)) {
34 tag = builtinTag;
35 } else if (!IS_STRING(tag)) {
36 return "[object ???]"
37 } else if (tag !== builtinTag && kBuiltinStringTags[tag]) {
38 return "[object ~" + tag + "]";
39 }
40 return "[object " + tag + "]";
41}
42
43function HarmonyToStringExtendSymbolPrototype() {
44 %CheckIsBootstrapping();
45
46 InstallConstants($Symbol, $Array(
47 // TODO(dslomov, caitp): Move to symbol.js when shipping
48 "toStringTag", symbolToStringTag
49 ));
50}
51
52HarmonyToStringExtendSymbolPrototype();
53
54function HarmonyToStringExtendObjectPrototype() {
55 %CheckIsBootstrapping();
56
57 // Can't use InstallFunctions() because will fail in Debug mode.
58 // Emulate InstallFunctions() here.
59 %FunctionSetName(ObjectToStringHarmony, "toString");
60 %FunctionRemovePrototype(ObjectToStringHarmony);
61 %SetNativeFlag(ObjectToStringHarmony);
62
63 // Set up the non-enumerable functions on the Array prototype object.
64 var desc = ToPropertyDescriptor({
65 value: ObjectToStringHarmony
66 });
67 DefineOwnProperty($Object.prototype, "toString", desc, false);
68
69 %ToFastProperties($Object.prototype);
70}
71
72HarmonyToStringExtendObjectPrototype();