Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: src/harmony-tostring.js

Issue 546803003: Update ObjectToString to Harmony-draft algorithm (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebase, rename ObjectToString Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/generator.js ('k') | src/heap/heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « src/generator.js ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698