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

Side by Side 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, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/es6/array-tostring.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js and symbol.js: 8 // in runtime.js and symbol.js:
9 // var $Object = global.Object; 9 // var $Object = global.Object;
10 // var $Symbol = global.Symbol; 10 // var $Symbol = global.Symbol;
(...skipping 15 matching lines...) Expand all
26 // ES6 draft 08-24-14, section 19.1.3.6 26 // ES6 draft 08-24-14, section 19.1.3.6
27 function ObjectToStringHarmony() { 27 function ObjectToStringHarmony() {
28 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; 28 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
29 if (IS_NULL(this)) return "[object Null]"; 29 if (IS_NULL(this)) return "[object Null]";
30 var O = ToObject(this); 30 var O = ToObject(this);
31 var builtinTag = %_ClassOf(O); 31 var builtinTag = %_ClassOf(O);
32 var tag = O[symbolToStringTag]; 32 var tag = O[symbolToStringTag];
33 if (IS_UNDEFINED(tag)) { 33 if (IS_UNDEFINED(tag)) {
34 tag = builtinTag; 34 tag = builtinTag;
35 } else if (!IS_STRING(tag)) { 35 } else if (!IS_STRING(tag)) {
36 return "[object ???]" 36 return "[object ???]";
37 } else if (tag !== builtinTag && kBuiltinStringTags[tag]) { 37 } else if (tag !== builtinTag && kBuiltinStringTags[tag]) {
38 return "[object ~" + tag + "]"; 38 return "[object ~" + tag + "]";
39 } 39 }
40 return "[object " + tag + "]"; 40 return "[object " + tag + "]";
41 } 41 }
42 42
43 // ES6 draft 12-06-14, section 22.1.3.27
44 function ArrayToStringHarmony() {
45 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
46 return Join(this, this.length, ',', ConvertToString);
47 }
48
49 var O = ToObject(this);
50 var join = O.join;
51 if (IS_SPEC_FUNCTION(join)) return %_CallFunction(O, join);
52 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
53 }
54
43 function HarmonyToStringExtendSymbolPrototype() { 55 function HarmonyToStringExtendSymbolPrototype() {
44 %CheckIsBootstrapping(); 56 %CheckIsBootstrapping();
45 57
46 InstallConstants($Symbol, $Array( 58 InstallConstants($Symbol, $Array(
47 // TODO(dslomov, caitp): Move to symbol.js when shipping 59 // TODO(dslomov, caitp): Move to symbol.js when shipping
48 "toStringTag", symbolToStringTag 60 "toStringTag", symbolToStringTag
49 )); 61 ));
50 } 62 }
51 63
52 HarmonyToStringExtendSymbolPrototype(); 64 HarmonyToStringExtendSymbolPrototype();
(...skipping 10 matching lines...) Expand all
63 // Set up the non-enumerable functions on the Array prototype object. 75 // Set up the non-enumerable functions on the Array prototype object.
64 var desc = ToPropertyDescriptor({ 76 var desc = ToPropertyDescriptor({
65 value: ObjectToStringHarmony 77 value: ObjectToStringHarmony
66 }); 78 });
67 DefineOwnProperty($Object.prototype, "toString", desc, false); 79 DefineOwnProperty($Object.prototype, "toString", desc, false);
68 80
69 %ToFastProperties($Object.prototype); 81 %ToFastProperties($Object.prototype);
70 } 82 }
71 83
72 HarmonyToStringExtendObjectPrototype(); 84 HarmonyToStringExtendObjectPrototype();
85
86 function HarmonyToStringExtendArrayPrototype() {
87 %CheckIsBootstrapping();
88
89 // Can't use InstallFunctions() because will fail in Debug mode.
90 // Emulate InstallFunctions here.
91 %FunctionSetName(ArrayToStringHarmony, "toString");
92 %FunctionRemovePrototype(ArrayToStringHarmony);
93 %SetNativeFlag(ArrayToStringHarmony);
94
95 // Set up the non-enumerable functions on the Array prototype object.
96 var desc = ToPropertyDescriptor({
97 value: ArrayToStringHarmony
98 });
99 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
100
101 %ToFastProperties($Array.prototype);
102 }
103
104 HarmonyToStringExtendArrayPrototype();
OLDNEW
« 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