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

Side by Side Diff: src/date.js

Issue 14125004: Move global code for builtins into setup functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 years, 8 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 | « src/collection.js ('k') | src/json.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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28
29 // This file relies on the fact that the following declarations have been made 28 // This file relies on the fact that the following declarations have been made
30 // in v8natives.js: 29 // in v8natives.js:
31 // var $isFinite = GlobalIsFinite; 30 // var $isFinite = GlobalIsFinite;
32 31
32 var $Date = global.Date;
33
33 // ------------------------------------------------------------------- 34 // -------------------------------------------------------------------
34 35
35 // This file contains date support implemented in JavaScript. 36 // This file contains date support implemented in JavaScript.
36 37
37 // Keep reference to original values of some global properties. This
38 // has the added benefit that the code in this file is isolated from
39 // changes to these properties.
40 var $Date = global.Date;
41
42 // Helper function to throw error. 38 // Helper function to throw error.
43 function ThrowDateTypeError() { 39 function ThrowDateTypeError() {
44 throw new $TypeError('this is not a Date object.'); 40 throw new $TypeError('this is not a Date object.');
45 } 41 }
46 42
47 43
48 var timezone_cache_time = $NaN; 44 var timezone_cache_time = $NaN;
49 var timezone_cache_timezone; 45 var timezone_cache_timezone;
50 46
51 function LocalTimezone(t) { 47 function LocalTimezone(t) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // The Date cache is used to limit the cost of parsing the same Date 131 // The Date cache is used to limit the cost of parsing the same Date
136 // strings over and over again. 132 // strings over and over again.
137 var Date_cache = { 133 var Date_cache = {
138 // Cached time value. 134 // Cached time value.
139 time: $NaN, 135 time: $NaN,
140 // String input for which the cached time is valid. 136 // String input for which the cached time is valid.
141 string: null 137 string: null
142 }; 138 };
143 139
144 140
145 %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { 141 function DateConstructor(year, month, date, hours, minutes, seconds, ms) {
146 if (!%_IsConstructCall()) { 142 if (!%_IsConstructCall()) {
147 // ECMA 262 - 15.9.2 143 // ECMA 262 - 15.9.2
148 return (new $Date()).toString(); 144 return (new $Date()).toString();
149 } 145 }
150 146
151 // ECMA 262 - 15.9.3 147 // ECMA 262 - 15.9.3
152 var argc = %_ArgumentsLength(); 148 var argc = %_ArgumentsLength();
153 var value; 149 var value;
154 if (argc == 0) { 150 if (argc == 0) {
155 value = %DateCurrentTime(); 151 value = %DateCurrentTime();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 seconds = argc > 5 ? ToNumber(seconds) : 0; 188 seconds = argc > 5 ? ToNumber(seconds) : 0;
193 ms = argc > 6 ? ToNumber(ms) : 0; 189 ms = argc > 6 ? ToNumber(ms) : 0;
194 year = (!NUMBER_IS_NAN(year) && 190 year = (!NUMBER_IS_NAN(year) &&
195 0 <= TO_INTEGER(year) && 191 0 <= TO_INTEGER(year) &&
196 TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year; 192 TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
197 var day = MakeDay(year, month, date); 193 var day = MakeDay(year, month, date);
198 var time = MakeTime(hours, minutes, seconds, ms); 194 var time = MakeTime(hours, minutes, seconds, ms);
199 value = MakeDate(day, time); 195 value = MakeDate(day, time);
200 SET_LOCAL_DATE_VALUE(this, value); 196 SET_LOCAL_DATE_VALUE(this, value);
201 } 197 }
202 }); 198 }
203
204
205 %FunctionSetPrototype($Date, new $Date($NaN));
206 199
207 200
208 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 201 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
209 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 202 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
210 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 203 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
211 204
212 205
213 function TwoDigitString(value) { 206 function TwoDigitString(value) {
214 return value < 10 ? "0" + value : "" + value; 207 return value < 10 ? "0" + value : "" + value;
215 } 208 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 cache = Date_cache; 753 cache = Date_cache;
761 cache.time = $NaN; 754 cache.time = $NaN;
762 cache.string = null; 755 cache.string = null;
763 } 756 }
764 757
765 758
766 // ------------------------------------------------------------------- 759 // -------------------------------------------------------------------
767 760
768 function SetUpDate() { 761 function SetUpDate() {
769 %CheckIsBootstrapping(); 762 %CheckIsBootstrapping();
763
764 %SetCode($Date, DateConstructor);
765 %FunctionSetPrototype($Date, new $Date($NaN));
766
770 // Set up non-enumerable properties of the Date object itself. 767 // Set up non-enumerable properties of the Date object itself.
771 InstallFunctions($Date, DONT_ENUM, $Array( 768 InstallFunctions($Date, DONT_ENUM, $Array(
772 "UTC", DateUTC, 769 "UTC", DateUTC,
773 "parse", DateParse, 770 "parse", DateParse,
774 "now", DateNow 771 "now", DateNow
775 )); 772 ));
776 773
777 // Set up non-enumerable constructor property of the Date prototype object. 774 // Set up non-enumerable constructor property of the Date prototype object.
778 %SetProperty($Date.prototype, "constructor", $Date, DONT_ENUM); 775 %SetProperty($Date.prototype, "constructor", $Date, DONT_ENUM);
779 776
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 "toGMTString", DateToGMTString, 820 "toGMTString", DateToGMTString,
824 "toUTCString", DateToUTCString, 821 "toUTCString", DateToUTCString,
825 "getYear", DateGetYear, 822 "getYear", DateGetYear,
826 "setYear", DateSetYear, 823 "setYear", DateSetYear,
827 "toISOString", DateToISOString, 824 "toISOString", DateToISOString,
828 "toJSON", DateToJSON 825 "toJSON", DateToJSON
829 )); 826 ));
830 } 827 }
831 828
832 SetUpDate(); 829 SetUpDate();
OLDNEW
« no previous file with comments | « src/collection.js ('k') | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698