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

Unified Diff: src/v8natives.js

Issue 461453002: Implement well-known symbol `Symbol.toStringTag` Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 4 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/symbol.js ('k') | test/mjsunit/es6/symbol-tostringtag.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 8484150248a13a2ef01467da31603fab1db88b0c..9dad17643ddc840c289ebf18f92d623aa7fdf60b 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -215,11 +215,29 @@ SetUpGlobal();
// ----------------------------------------------------------------------------
// Object
-// ECMA-262 - 15.2.4.2
+// ES6 draft Rev 26 - 19.1.3.6
+var reservedTags = ["Arguments", "Array", "Boolean", "Date",
+ "Error", "Function", "Number", "RegExp", "String"];
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);
+ if(reservedTags.indexOf(builtinTag) === -1){
arv (Not doing code reviews) 2014/08/11 14:40:40 Can you change this to a switch? We do not want a
+ builtinTag = "Object";
+ }
+ var tag = builtinTag;
+ var hasTag = %HasProperty(O, symbolToStringTag);
+ if(hasTag){
+ tag = O[symbolToStringTag];
+ if(!IS_STRING(tag)){
+ tag = "???";
+ }
+ if(tag !== builtinTag && reservedTags.indexOf(tag) > -1){
+ tag = "~" + tag;
+ }
+ }
+ return "[object " + tag + "]";
}
« no previous file with comments | « src/symbol.js ('k') | test/mjsunit/es6/symbol-tostringtag.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698