Index: src/harmony-tostring.js |
diff --git a/src/harmony-tostring.js b/src/harmony-tostring.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..282b3a0ffbd23c3a2aa3feaf72144aa07b4143b0 |
--- /dev/null |
+++ b/src/harmony-tostring.js |
@@ -0,0 +1,66 @@ |
+// Copyright 2013 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+'use strict'; |
+ |
+// This file relies on the fact that the following declaration has been made |
+// in runtime.js and symbol.js: |
+// var $Object = global.Object; |
+// var $Symbol = global.Symbol; |
+ |
+var symbolToStringTag = InternalSymbol("Symbol.toStringTag"); |
+ |
+var kBuiltinStringTags = { |
+ "__proto__": null, |
+ "Arguments": true, |
+ "Array": true, |
+ "Boolean": true, |
+ "Date": true, |
+ "Error": true, |
+ "Function": true, |
+ "Number": true, |
+ "RegExp": true, |
+ "String": true |
+}; |
+ |
+DefaultObjectToString = ObjectToStringHarmony; |
+// ES6 draft 08-24-14, section 19.1.3.6 |
+function ObjectToStringHarmony() { |
+ if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
+ if (IS_NULL(this)) return "[object Null]"; |
+ var O = ToObject(this); |
+ var builtinTag = %_ClassOf(O); |
+ var tag = O[symbolToStringTag]; |
+ if (IS_UNDEFINED(tag)) { |
+ tag = builtinTag; |
+ } else if (!IS_STRING(tag)) { |
+ return "[object ???]" |
+ } else if (tag !== builtinTag && kBuiltinStringTags[tag]) { |
+ return "[object ~" + tag + "]"; |
+ } |
+ return "[object " + tag + "]"; |
+} |
+ |
+function HarmonyToStringExtendSymbolPrototype() { |
+ %CheckIsBootstrapping(); |
+ |
+ InstallConstants($Symbol, $Array( |
+ // TODO(dslomov, caitp): Move to symbol.js when shipping |
+ "toStringTag", symbolToStringTag |
+ )); |
+} |
+ |
+HarmonyToStringExtendSymbolPrototype(); |
+ |
+function HarmonyToStringExtendObjectPrototype() { |
+ %CheckIsBootstrapping(); |
+ |
+ // Set up the non-enumerable functions on the Array prototype object. |
+ var desc = ToPropertyDescriptor({ |
+ value: ObjectToStringHarmony |
+ }); |
+ DefineOwnProperty($Object.prototype, "toString", desc, false); |
+} |
+ |
+HarmonyToStringExtendObjectPrototype(); |