| Index: src/harmony-tostring.js
|
| diff --git a/src/harmony-tostring.js b/src/harmony-tostring.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6988f89a624ecb43b3c3c1446fe5955b611363be
|
| --- /dev/null
|
| +++ b/src/harmony-tostring.js
|
| @@ -0,0 +1,64 @@
|
| +// 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
|
| +};
|
| +
|
| +// 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: Move to symbol.js when shipping
|
| + "toStringTag", symbolToStringTag
|
| + ));
|
| +}
|
| +
|
| +HarmonyToStringExtendSymbolPrototype();
|
| +
|
| +function HarmonyToStringExtendObjectPrototype() {
|
| + %CheckIsBootstrapping();
|
| +
|
| + // Set up the non-enumerable functions on the Array prototype object.
|
| + InstallFunctions($Object.prototype, DONT_ENUM, $Array(
|
| + "toString", ObjectToStringHarmony
|
| + ));
|
| +}
|
| +
|
| +HarmonyToStringExtendObjectPrototype();
|
|
|