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

Side by Side Diff: src/date-delay.js

Issue 149177: Optimize Date construction and string concatenation with... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 5 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
« no previous file with comments | « no previous file | src/math.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 29 matching lines...) Expand all
40 // changes to these properties. 40 // changes to these properties.
41 const $Date = global.Date; 41 const $Date = global.Date;
42 42
43 // Helper function to throw error. 43 // Helper function to throw error.
44 function ThrowDateTypeError() { 44 function ThrowDateTypeError() {
45 throw new $TypeError('this is not a Date object.'); 45 throw new $TypeError('this is not a Date object.');
46 } 46 }
47 47
48 // ECMA 262 - 15.9.1.2 48 // ECMA 262 - 15.9.1.2
49 function Day(time) { 49 function Day(time) {
50 return FLOOR(time/msPerDay); 50 return FLOOR(time / msPerDay);
51 } 51 }
52 52
53 53
54 // ECMA 262 - 5.2 54 // ECMA 262 - 5.2
55 function Modulo(value, remainder) { 55 function Modulo(value, remainder) {
56 var mod = value % remainder; 56 var mod = value % remainder;
57 // Guard against returning -0. 57 // Guard against returning -0.
58 if (mod == 0) return 0; 58 if (mod == 0) return 0;
59 return mod >= 0 ? mod : mod + remainder; 59 return mod >= 0 ? mod : mod + remainder;
60 } 60 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 421
422 // ECMA 262 - 15.9.1.14 422 // ECMA 262 - 15.9.1.14
423 function TimeClip(time) { 423 function TimeClip(time) {
424 if (!$isFinite(time)) return $NaN; 424 if (!$isFinite(time)) return $NaN;
425 if ($abs(time) > 8.64E15) return $NaN; 425 if ($abs(time) > 8.64E15) return $NaN;
426 return TO_INTEGER(time); 426 return TO_INTEGER(time);
427 } 427 }
428 428
429 429
430 %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { 430 %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) {
431 if (%_IsConstructCall()) { 431 if (!%_IsConstructCall()) {
432 // ECMA 262 - 15.9.3 432 // ECMA 262 - 15.9.2
433 var argc = %_ArgumentsLength(); 433 return (new $Date()).toString();
434 if (argc == 0) { 434 }
435 %_SetValueOf(this, %DateCurrentTime()); 435
436 return; 436 // ECMA 262 - 15.9.3
437 var argc = %_ArgumentsLength();
438 var value;
439 if (argc == 0) {
440 value = %DateCurrentTime();
441
442 } else if (argc == 1) {
443 if (IS_NUMBER(year)) {
444 value = TimeClip(year);
445 } else {
446 // According to ECMA 262, no hint should be given for this
447 // conversion. However, ToPrimitive defaults to STRING_HINT for
448 // Date objects which will lose precision when the Date
449 // constructor is called with another Date object as its
450 // argument. We therefore use NUMBER_HINT for the conversion,
451 // which is the default for everything else than Date objects.
452 // This makes us behave like KJS and SpiderMonkey.
453 var time = ToPrimitive(year, NUMBER_HINT);
454 value = IS_STRING(time) ? DateParse(time) : TimeClip(ToNumber(time));
437 } 455 }
438 if (argc == 1) { 456
439 // According to ECMA 262, no hint should be given for this 457 } else {
440 // conversion. However, ToPrimitive defaults to String Hint
441 // for Date objects which will lose precision when the Date
442 // constructor is called with another Date object as its
443 // argument. We therefore use Number Hint for the conversion
444 // (which is the default for everything else than Date
445 // objects). This makes us behave like KJS and SpiderMonkey.
446 var time = ToPrimitive(year, NUMBER_HINT);
447 if (IS_STRING(time)) {
448 %_SetValueOf(this, DateParse(time));
449 } else {
450 %_SetValueOf(this, TimeClip(ToNumber(time)));
451 }
452 return;
453 }
454 year = ToNumber(year); 458 year = ToNumber(year);
455 month = ToNumber(month); 459 month = ToNumber(month);
456 date = argc > 2 ? ToNumber(date) : 1; 460 date = argc > 2 ? ToNumber(date) : 1;
457 hours = argc > 3 ? ToNumber(hours) : 0; 461 hours = argc > 3 ? ToNumber(hours) : 0;
458 minutes = argc > 4 ? ToNumber(minutes) : 0; 462 minutes = argc > 4 ? ToNumber(minutes) : 0;
459 seconds = argc > 5 ? ToNumber(seconds) : 0; 463 seconds = argc > 5 ? ToNumber(seconds) : 0;
460 ms = argc > 6 ? ToNumber(ms) : 0; 464 ms = argc > 6 ? ToNumber(ms) : 0;
461 year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) 465 year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
462 ? 1900 + TO_INTEGER(year) : year; 466 ? 1900 + TO_INTEGER(year) : year;
463 var day = MakeDay(year, month, date); 467 var day = MakeDay(year, month, date);
464 var time = MakeTime(hours, minutes, seconds, ms); 468 var time = MakeTime(hours, minutes, seconds, ms);
465 %_SetValueOf(this, TimeClip(UTC(MakeDate(day, time)))); 469 value = TimeClip(UTC(MakeDate(day, time)));
466 } else {
467 // ECMA 262 - 15.9.2
468 return (new $Date()).toString();
469 } 470 }
471 %_SetValueOf(this, value);
470 }); 472 });
471 473
472 474
473 // Helper functions. 475 // Helper functions.
474 function GetTimeFrom(aDate) { 476 function GetTimeFrom(aDate) {
475 return DATE_VALUE(aDate); 477 return DATE_VALUE(aDate);
476 } 478 }
477 479
478 480
479 function GetMillisecondsFrom(aDate) { 481 function GetMillisecondsFrom(aDate) {
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 "toGMTString", DateToGMTString, 1130 "toGMTString", DateToGMTString,
1129 "toUTCString", DateToUTCString, 1131 "toUTCString", DateToUTCString,
1130 "getYear", DateGetYear, 1132 "getYear", DateGetYear,
1131 "setYear", DateSetYear, 1133 "setYear", DateSetYear,
1132 "toISOString", DateToISOString, 1134 "toISOString", DateToISOString,
1133 "toJSON", DateToJSON 1135 "toJSON", DateToJSON
1134 )); 1136 ));
1135 } 1137 }
1136 1138
1137 SetupDate(); 1139 SetupDate();
OLDNEW
« no previous file with comments | « no previous file | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698