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

Side by Side Diff: src/runtime.js

Issue 1346893003: [es6] Use the correct ToPrimitive in the Date Constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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 | « src/macros.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 files contains runtime support implemented in JavaScript. 5 // This files contains runtime support implemented in JavaScript.
6 6
7 // CAUTION: Some of the functions specified in this file are called 7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in 8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this'. 9 // ALL CAPS. The compiled code passes the first argument in 'this'.
10 10
11 11
12 // The following declarations are shared with other native JS files. 12 // The following declarations are shared with other native JS files.
13 // They are all declared at this one spot to avoid redeclaration errors. 13 // They are all declared at this one spot to avoid redeclaration errors.
14 var $defaultString; 14 var $defaultString;
15 var $NaN; 15 var $NaN;
16 var $nonNumberToNumber; 16 var $nonNumberToNumber;
17 var $nonStringToString; 17 var $nonStringToString;
18 var $sameValue; 18 var $sameValue;
19 var $sameValueZero; 19 var $sameValueZero;
20 var $toInteger; 20 var $toInteger;
21 var $toLength; 21 var $toLength;
22 var $toNumber; 22 var $toNumber;
23 var $toPositiveInteger; 23 var $toPositiveInteger;
24 var $toPrimitive;
25 var $toString; 24 var $toString;
26 25
27 var harmony_tolength = false; 26 var harmony_tolength = false;
28 27
29 (function(global, utils) { 28 (function(global, utils) {
30 29
31 %CheckIsBootstrapping(); 30 %CheckIsBootstrapping();
32 31
33 var GlobalArray = global.Array; 32 var GlobalArray = global.Array;
34 var GlobalBoolean = global.Boolean; 33 var GlobalBoolean = global.Boolean;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 function CONCAT_ITERABLE_TO_ARRAY(iterable) { 168 function CONCAT_ITERABLE_TO_ARRAY(iterable) {
170 return %concat_iterable_to_array(this, iterable); 169 return %concat_iterable_to_array(this, iterable);
171 }; 170 };
172 171
173 172
174 /* ------------------------------------- 173 /* -------------------------------------
175 - - - C o n v e r s i o n s - - - 174 - - - C o n v e r s i o n s - - -
176 ------------------------------------- 175 -------------------------------------
177 */ 176 */
178 177
179 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
180 // (1) for number hint, and (2) for string hint.
181 function ToPrimitive(x, hint) {
182 if (!IS_SPEC_OBJECT(x)) return x;
183 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
184 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x);
185 }
186
187
188 // ECMA-262, section 9.2, page 30 178 // ECMA-262, section 9.2, page 30
189 function ToBoolean(x) { 179 function ToBoolean(x) {
190 if (IS_BOOLEAN(x)) return x; 180 if (IS_BOOLEAN(x)) return x;
191 if (IS_STRING(x)) return x.length != 0; 181 if (IS_STRING(x)) return x.length != 0;
192 if (x == null) return false; 182 if (x == null) return false;
193 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); 183 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
194 return true; 184 return true;
195 } 185 }
196 186
197 187
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 $defaultString = DefaultString; 360 $defaultString = DefaultString;
371 $NaN = %GetRootNaN(); 361 $NaN = %GetRootNaN();
372 $nonNumberToNumber = NonNumberToNumber; 362 $nonNumberToNumber = NonNumberToNumber;
373 $nonStringToString = NonStringToString; 363 $nonStringToString = NonStringToString;
374 $sameValue = SameValue; 364 $sameValue = SameValue;
375 $sameValueZero = SameValueZero; 365 $sameValueZero = SameValueZero;
376 $toInteger = ToInteger; 366 $toInteger = ToInteger;
377 $toLength = ToLength; 367 $toLength = ToLength;
378 $toNumber = ToNumber; 368 $toNumber = ToNumber;
379 $toPositiveInteger = ToPositiveInteger; 369 $toPositiveInteger = ToPositiveInteger;
380 $toPrimitive = ToPrimitive;
381 $toString = ToString; 370 $toString = ToString;
382 371
383 %InstallToContext([ 372 %InstallToContext([
384 "apply_prepare_builtin", APPLY_PREPARE, 373 "apply_prepare_builtin", APPLY_PREPARE,
385 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, 374 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY,
386 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE, 375 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE,
387 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE, 376 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE,
388 ]); 377 ]);
389 378
390 %InstallToContext([ 379 %InstallToContext([
391 "concat_iterable_to_array", ConcatIterableToArray, 380 "concat_iterable_to_array", ConcatIterableToArray,
392 "non_number_to_number", NonNumberToNumber, 381 "non_number_to_number", NonNumberToNumber,
393 "non_string_to_string", NonStringToString, 382 "non_string_to_string", NonStringToString,
394 "to_integer_fun", ToInteger, 383 "to_integer_fun", ToInteger,
395 "to_length_fun", ToLength, 384 "to_length_fun", ToLength,
396 "to_number_fun", ToNumber, 385 "to_number_fun", ToNumber,
397 "to_primitive", ToPrimitive,
398 "to_string_fun", ToString, 386 "to_string_fun", ToString,
399 ]); 387 ]);
400 388
401 utils.Export(function(to) { 389 utils.Export(function(to) {
402 to.ToBoolean = ToBoolean; 390 to.ToBoolean = ToBoolean;
403 to.ToLength = ToLength; 391 to.ToLength = ToLength;
404 to.ToNumber = ToNumber; 392 to.ToNumber = ToNumber;
405 to.ToPrimitive = ToPrimitive;
406 to.ToString = ToString; 393 to.ToString = ToString;
407 }); 394 });
408 395
409 }) 396 })
OLDNEW
« no previous file with comments | « src/macros.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698