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

Unified Diff: src/v8natives.js

Issue 546803003: Update ObjectToString to Harmony-draft algorithm (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add @@toStringTag to some objects + tests 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
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 1d2e03000763062f3777e1a565e1792227f3e634..7a1f25bdd9292641a96f4a614d1ff5fb5e2b5aa2 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -214,12 +214,34 @@ SetUpGlobal();
// ----------------------------------------------------------------------------
// Object
+var kBuiltinStringTags = {
caitp (gmail) 2014/10/10 14:56:28 ObjectCreate(null) would be better, I guess
rossberg 2014/10/17 11:19:30 Yes, the prototype has to be null, otherwise the c
+ "Arguments": "[object ~Arguments]",
+ "Array": "[object ~Array]",
+ "Boolean": "[object ~Boolean]",
+ "Date": "[object ~Date]",
+ "Error": "[object ~Error]",
+ "Function": "[object ~Function]",
+ "Number": "[object ~Number]",
+ "RegExp": "[object ~RegExp]",
+ "String": "[object ~String]"
+};
// ECMA-262 - 15.2.4.2
+// ES6 draft 08-24-14, section 19.1.3.6
function ObjectToString() {
if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
if (IS_NULL(this)) return "[object Null]";
- return "[object " + %_ClassOf(ToObject(this)) + "]";
+ var O = ToObject(this);
+ var builtinTag = %_ClassOf(O);
+ var tag = O[symbolToStringTag];
rossberg 2014/10/17 11:19:30 We need some way of putting this new behaviour beh
+ if (IS_UNDEFINED(tag)) tag = builtinTag;
rossberg 2014/10/17 11:19:30 Style nit: new line if there is an 'else'.
+ else {
+ if (!IS_STRING(tag)) return "[object ???]";
rossberg 2014/10/17 11:19:30 Same here. Can also merge into an 'else if' with t
+ else if (tag !== builtinTag && IS_STRING(kBuiltinStringTags[tag])) {
+ return kBuiltinStringTags[tag];
arv (Not doing code reviews) 2014/10/17 14:40:51 Maybe make the kBuiltinStringTags a "set" and then
+ }
+ }
+ return "[object " + tag + "]";
}
« no previous file with comments | « src/symbol.js ('k') | src/weak-collection.js » ('j') | test/mjsunit/class-of-builtins.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698