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