Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 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 | var 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 | |
| 25 | DefaultObjectToString = ObjectToStringHarmony; |
| 26 | // ES6 draft 08-24-14, section 19.1.3.6 |
| 27 | function 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 | |
| 43 | function HarmonyToStringExtendSymbolPrototype() { |
| 44 | %CheckIsBootstrapping(); |
| 45 | |
| 46 | InstallConstants($Symbol, $Array( |
| 47 | // TODO(dslomov, caitp): Move to symbol.js when shipping |
| 48 | "toStringTag", symbolToStringTag |
| 49 | )); |
| 50 | } |
| 51 | |
| 52 | HarmonyToStringExtendSymbolPrototype(); |
| 53 | |
| 54 | function 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 | |
| 72 | HarmonyToStringExtendObjectPrototype(); |