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

Unified Diff: src/harmony-tostring.js

Issue 835753002: Implement ES6 Array.prototype.toString behind --harmony-tostring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fallback on harmony ObjectToString, rather than NoSideEffectsObjectToString Created 5 years, 12 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 | « no previous file | test/mjsunit/es6/array-tostring.js » ('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
index 0336456bb2827c13c75bd5f823731a2223e65540..e36ef0d111d7e4015a16327e4b4ef0ceb05d296a 100644
--- a/src/harmony-tostring.js
+++ b/src/harmony-tostring.js
@@ -33,13 +33,25 @@ function ObjectToStringHarmony() {
if (IS_UNDEFINED(tag)) {
tag = builtinTag;
} else if (!IS_STRING(tag)) {
- return "[object ???]"
+ return "[object ???]";
} else if (tag !== builtinTag && kBuiltinStringTags[tag]) {
return "[object ~" + tag + "]";
}
return "[object " + tag + "]";
}
+// ES6 draft 12-06-14, section 22.1.3.27
+function ArrayToStringHarmony() {
+ if (IS_ARRAY(this) && this.join === ArrayJoin) {
arv (Not doing code reviews) 2015/01/12 15:46:40 It looks like we are doing Get(object, 'join') twi
+ return Join(this, this.length, ',', ConvertToString);
+ }
+
+ var O = ToObject(this);
+ var join = O.join;
+ if (IS_SPEC_FUNCTION(join)) return %_CallFunction(O, join);
+ return %_CallFunction(O, ObjectToStringHarmony);
arv (Not doing code reviews) 2015/01/12 15:46:40 Could we just change ArrayToString to use DefaultO
caitp (gmail) 2015/01/12 15:53:16 hmm, that's a good point
+}
+
function HarmonyToStringExtendSymbolPrototype() {
%CheckIsBootstrapping();
@@ -70,3 +82,23 @@ function HarmonyToStringExtendObjectPrototype() {
}
HarmonyToStringExtendObjectPrototype();
+
+function HarmonyToStringExtendArrayPrototype() {
+ %CheckIsBootstrapping();
+
+ // Can't use InstallFunctions() because will fail in Debug mode.
+ // Emulate InstallFunctions here.
+ %FunctionSetName(ArrayToStringHarmony, "toString");
+ %FunctionRemovePrototype(ArrayToStringHarmony);
+ %SetNativeFlag(ArrayToStringHarmony);
+
+ // Set up the non-enumerable functions on the Array prototype object.
+ var desc = ToPropertyDescriptor({
+ value: ArrayToStringHarmony
+ });
+ DefineOwnProperty($Array.prototype, "toString", desc, false);
arv (Not doing code reviews) 2015/01/12 15:46:40 DefineOwnProperty takes a descriptor... can we use
caitp (gmail) 2015/01/12 15:53:16 Sort of --- Runtime_AddOwnProperty (used by Instal
+
+ %ToFastProperties($Array.prototype);
+}
+
+HarmonyToStringExtendArrayPrototype();
« no previous file with comments | « no previous file | test/mjsunit/es6/array-tostring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698