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

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

Issue 1448933002: Introduce a BuiltinsConstructStub that sets up new.target and does a [[call]] per ES6 9.3.2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More accurate regexp Created 5 years, 1 month 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
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 // ------------------------------------------------------------------- 5 // -------------------------------------------------------------------
6 6
7 (function(global, utils) { 7 (function(global, utils) {
8 8
9 "use strict"; 9 "use strict";
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // strings over and over again. 125 // strings over and over again.
126 var Date_cache = { 126 var Date_cache = {
127 // Cached time value. 127 // Cached time value.
128 time: 0, 128 time: 0,
129 // String input for which the cached time is valid. 129 // String input for which the cached time is valid.
130 string: null 130 string: null
131 }; 131 };
132 132
133 133
134 function DateConstructor(year, month, date, hours, minutes, seconds, ms) { 134 function DateConstructor(year, month, date, hours, minutes, seconds, ms) {
135 if (!%_IsConstructCall()) { 135 if (IS_UNDEFINED(new.target)) {
136 // ECMA 262 - 15.9.2 136 // ECMA 262 - 15.9.2
137 return %_Call(DateToString, new GlobalDate()); 137 return %_Call(DateToString, new GlobalDate());
138 } 138 }
139 139
140 // ECMA 262 - 15.9.3 140 // ECMA 262 - 15.9.3
141 var argc = %_ArgumentsLength(); 141 var argc = %_ArgumentsLength();
142 var value; 142 var value;
143 var result;
143 if (argc == 0) { 144 if (argc == 0) {
144 value = %DateCurrentTime(); 145 value = %DateCurrentTime();
145 SET_UTC_DATE_VALUE(this, value); 146 result = %NewObject(GlobalDate, new.target);
147 SET_UTC_DATE_VALUE(result, value);
146 } else if (argc == 1) { 148 } else if (argc == 1) {
147 if (IS_NUMBER(year)) { 149 if (IS_NUMBER(year)) {
148 value = TimeClip(year); 150 value = TimeClip(year);
149 151
150 } else if (IS_STRING(year)) { 152 } else if (IS_STRING(year)) {
151 // Probe the Date cache. If we already have a time value for the 153 // Probe the Date cache. If we already have a time value for the
152 // given time, we re-use that instead of parsing the string again. 154 // given time, we re-use that instead of parsing the string again.
153 CheckDateCacheCurrent(); 155 CheckDateCacheCurrent();
154 var cache = Date_cache; 156 var cache = Date_cache;
155 if (cache.string === year) { 157 if (cache.string === year) {
156 value = cache.time; 158 value = cache.time;
157 } else { 159 } else {
158 value = DateParse(year); 160 value = DateParse(year);
159 if (!NUMBER_IS_NAN(value)) { 161 if (!NUMBER_IS_NAN(value)) {
160 cache.time = value; 162 cache.time = value;
161 cache.string = year; 163 cache.string = year;
162 } 164 }
163 } 165 }
164 166
165 } else if (IS_DATE(year)) { 167 } else if (IS_DATE(year)) {
166 value = UTC_DATE_VALUE(year); 168 value = UTC_DATE_VALUE(year);
167 169
168 } else { 170 } else {
169 var time = TO_PRIMITIVE(year); 171 var time = TO_PRIMITIVE(year);
170 value = IS_STRING(time) ? DateParse(time) : TO_NUMBER(time); 172 value = IS_STRING(time) ? DateParse(time) : TO_NUMBER(time);
171 } 173 }
172 SET_UTC_DATE_VALUE(this, value); 174 result = %NewObject(GlobalDate, new.target);
175 SET_UTC_DATE_VALUE(result, value);
173 } else { 176 } else {
174 year = TO_NUMBER(year); 177 year = TO_NUMBER(year);
175 month = TO_NUMBER(month); 178 month = TO_NUMBER(month);
176 date = argc > 2 ? TO_NUMBER(date) : 1; 179 date = argc > 2 ? TO_NUMBER(date) : 1;
177 hours = argc > 3 ? TO_NUMBER(hours) : 0; 180 hours = argc > 3 ? TO_NUMBER(hours) : 0;
178 minutes = argc > 4 ? TO_NUMBER(minutes) : 0; 181 minutes = argc > 4 ? TO_NUMBER(minutes) : 0;
179 seconds = argc > 5 ? TO_NUMBER(seconds) : 0; 182 seconds = argc > 5 ? TO_NUMBER(seconds) : 0;
180 ms = argc > 6 ? TO_NUMBER(ms) : 0; 183 ms = argc > 6 ? TO_NUMBER(ms) : 0;
181 year = (!NUMBER_IS_NAN(year) && 184 year = (!NUMBER_IS_NAN(year) &&
182 0 <= TO_INTEGER(year) && 185 0 <= TO_INTEGER(year) &&
183 TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year; 186 TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
184 var day = MakeDay(year, month, date); 187 var day = MakeDay(year, month, date);
185 var time = MakeTime(hours, minutes, seconds, ms); 188 var time = MakeTime(hours, minutes, seconds, ms);
186 value = MakeDate(day, time); 189 value = MakeDate(day, time);
187 SET_LOCAL_DATE_VALUE(this, value); 190 result = %NewObject(GlobalDate, new.target);
191 SET_LOCAL_DATE_VALUE(result, value);
188 } 192 }
193
194 return result;
189 } 195 }
190 196
191 197
192 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 198 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
193 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 199 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
194 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 200 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
195 201
196 202
197 function TwoDigitString(value) { 203 function TwoDigitString(value) {
198 return value < 10 ? "0" + value : "" + value; 204 return value < 10 ? "0" + value : "" + value;
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 "toUTCString", DateToUTCString, 881 "toUTCString", DateToUTCString,
876 "getYear", DateGetYear, 882 "getYear", DateGetYear,
877 "setYear", DateSetYear, 883 "setYear", DateSetYear,
878 "toISOString", DateToISOString, 884 "toISOString", DateToISOString,
879 "toJSON", DateToJSON 885 "toJSON", DateToJSON
880 ]); 886 ]);
881 887
882 %InstallToContext(["create_date_fun", CreateDate]); 888 %InstallToContext(["create_date_fun", CreateDate]);
883 889
884 }) 890 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698