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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // This file relies on the fact that the following declarations have been made 5 // This file relies on the fact that the following declarations have been made
6 // in runtime.js: 6 // in runtime.js:
7 // var $Object = global.Object; 7 // var $Object = global.Object;
8 // var $Boolean = global.Boolean; 8 // var $Boolean = global.Boolean;
9 // var $Number = global.Number; 9 // var $Number = global.Number;
10 // var $Function = global.Function; 10 // var $Function = global.Function;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 "parseFloat", GlobalParseFloat, 207 "parseFloat", GlobalParseFloat,
208 "eval", GlobalEval 208 "eval", GlobalEval
209 )); 209 ));
210 } 210 }
211 211
212 SetUpGlobal(); 212 SetUpGlobal();
213 213
214 214
215 // ---------------------------------------------------------------------------- 215 // ----------------------------------------------------------------------------
216 // Object 216 // Object
217 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
218 "Arguments": "[object ~Arguments]",
219 "Array": "[object ~Array]",
220 "Boolean": "[object ~Boolean]",
221 "Date": "[object ~Date]",
222 "Error": "[object ~Error]",
223 "Function": "[object ~Function]",
224 "Number": "[object ~Number]",
225 "RegExp": "[object ~RegExp]",
226 "String": "[object ~String]"
227 };
217 228
218 // ECMA-262 - 15.2.4.2 229 // ECMA-262 - 15.2.4.2
230 // ES6 draft 08-24-14, section 19.1.3.6
219 function ObjectToString() { 231 function ObjectToString() {
220 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; 232 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
221 if (IS_NULL(this)) return "[object Null]"; 233 if (IS_NULL(this)) return "[object Null]";
222 return "[object " + %_ClassOf(ToObject(this)) + "]"; 234 var O = ToObject(this);
235 var builtinTag = %_ClassOf(O);
236 var tag = O[symbolToStringTag];
rossberg 2014/10/17 11:19:30 We need some way of putting this new behaviour beh
237 if (IS_UNDEFINED(tag)) tag = builtinTag;
rossberg 2014/10/17 11:19:30 Style nit: new line if there is an 'else'.
238 else {
239 if (!IS_STRING(tag)) return "[object ???]";
rossberg 2014/10/17 11:19:30 Same here. Can also merge into an 'else if' with t
240 else if (tag !== builtinTag && IS_STRING(kBuiltinStringTags[tag])) {
241 return kBuiltinStringTags[tag];
arv (Not doing code reviews) 2014/10/17 14:40:51 Maybe make the kBuiltinStringTags a "set" and then
242 }
243 }
244 return "[object " + tag + "]";
223 } 245 }
224 246
225 247
226 // ECMA-262 - 15.2.4.3 248 // ECMA-262 - 15.2.4.3
227 function ObjectToLocaleString() { 249 function ObjectToLocaleString() {
228 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); 250 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString");
229 return this.toString(); 251 return this.toString();
230 } 252 }
231 253
232 254
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 } 1928 }
1907 if (!IS_SPEC_FUNCTION(method)) { 1929 if (!IS_SPEC_FUNCTION(method)) {
1908 throw MakeTypeError('not_iterable', [obj]); 1930 throw MakeTypeError('not_iterable', [obj]);
1909 } 1931 }
1910 var iterator = %_CallFunction(obj, method); 1932 var iterator = %_CallFunction(obj, method);
1911 if (!IS_SPEC_OBJECT(iterator)) { 1933 if (!IS_SPEC_OBJECT(iterator)) {
1912 throw MakeTypeError('not_an_iterator', [iterator]); 1934 throw MakeTypeError('not_an_iterator', [iterator]);
1913 } 1935 }
1914 return iterator; 1936 return iterator;
1915 } 1937 }
OLDNEW
« 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