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

Side by Side Diff: src/date.js

Issue 1167813003: [date] Refactor the %_DateField intrinsic to be optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments. Created 5 years, 6 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/compiler/linkage.cc ('k') | src/deoptimizer.h » ('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 // 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 var $createDate; 5 var $createDate;
6 6
7 // ------------------------------------------------------------------- 7 // -------------------------------------------------------------------
8 8
9 (function(global, utils) { 9 (function(global, utils) {
10 10
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 195 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
196 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 196 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
197 197
198 198
199 function TwoDigitString(value) { 199 function TwoDigitString(value) {
200 return value < 10 ? "0" + value : "" + value; 200 return value < 10 ? "0" + value : "" + value;
201 } 201 }
202 202
203 203
204 function DateString(date) { 204 function DateString(date) {
205 CHECK_DATE(date);
205 return WeekDays[LOCAL_WEEKDAY(date)] + ' ' 206 return WeekDays[LOCAL_WEEKDAY(date)] + ' '
206 + Months[LOCAL_MONTH(date)] + ' ' 207 + Months[LOCAL_MONTH(date)] + ' '
207 + TwoDigitString(LOCAL_DAY(date)) + ' ' 208 + TwoDigitString(LOCAL_DAY(date)) + ' '
208 + LOCAL_YEAR(date); 209 + LOCAL_YEAR(date);
209 } 210 }
210 211
211 212
212 var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 213 var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
213 'Thursday', 'Friday', 'Saturday']; 214 'Thursday', 'Friday', 'Saturday'];
214 var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', 215 var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June',
215 'July', 'August', 'September', 'October', 'November', 'December']; 216 'July', 'August', 'September', 'October', 'November', 'December'];
216 217
217 218
218 function LongDateString(date) { 219 function LongDateString(date) {
220 CHECK_DATE(date);
219 return LongWeekDays[LOCAL_WEEKDAY(date)] + ', ' 221 return LongWeekDays[LOCAL_WEEKDAY(date)] + ', '
220 + LongMonths[LOCAL_MONTH(date)] + ' ' 222 + LongMonths[LOCAL_MONTH(date)] + ' '
221 + TwoDigitString(LOCAL_DAY(date)) + ', ' 223 + TwoDigitString(LOCAL_DAY(date)) + ', '
222 + LOCAL_YEAR(date); 224 + LOCAL_YEAR(date);
223 } 225 }
224 226
225 227
226 function TimeString(date) { 228 function TimeString(date) {
229 CHECK_DATE(date);
227 return TwoDigitString(LOCAL_HOUR(date)) + ':' 230 return TwoDigitString(LOCAL_HOUR(date)) + ':'
228 + TwoDigitString(LOCAL_MIN(date)) + ':' 231 + TwoDigitString(LOCAL_MIN(date)) + ':'
229 + TwoDigitString(LOCAL_SEC(date)); 232 + TwoDigitString(LOCAL_SEC(date));
230 } 233 }
231 234
232 235
233 function TimeStringUTC(date) { 236 function TimeStringUTC(date) {
237 CHECK_DATE(date);
234 return TwoDigitString(UTC_HOUR(date)) + ':' 238 return TwoDigitString(UTC_HOUR(date)) + ':'
235 + TwoDigitString(UTC_MIN(date)) + ':' 239 + TwoDigitString(UTC_MIN(date)) + ':'
236 + TwoDigitString(UTC_SEC(date)); 240 + TwoDigitString(UTC_SEC(date));
237 } 241 }
238 242
239 243
240 function LocalTimezoneString(date) { 244 function LocalTimezoneString(date) {
245 CHECK_DATE(date);
241 var timezone = LocalTimezone(UTC_DATE_VALUE(date)); 246 var timezone = LocalTimezone(UTC_DATE_VALUE(date));
242 247
243 var timezoneOffset = -TIMEZONE_OFFSET(date); 248 var timezoneOffset = -TIMEZONE_OFFSET(date);
244 var sign = (timezoneOffset >= 0) ? 1 : -1; 249 var sign = (timezoneOffset >= 0) ? 1 : -1;
245 var hours = MathFloor((sign * timezoneOffset)/60); 250 var hours = MathFloor((sign * timezoneOffset)/60);
246 var min = MathFloor((sign * timezoneOffset)%60); 251 var min = MathFloor((sign * timezoneOffset)%60);
247 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + 252 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') +
248 TwoDigitString(hours) + TwoDigitString(min); 253 TwoDigitString(hours) + TwoDigitString(min);
249 return gmt + ' (' + timezone + ')'; 254 return gmt + ' (' + timezone + ')';
250 } 255 }
251 256
252 257
253 function DatePrintString(date) { 258 function DatePrintString(date) {
259 CHECK_DATE(date);
254 return DateString(date) + ' ' + TimeString(date); 260 return DateString(date) + ' ' + TimeString(date);
255 } 261 }
256 262
257 // ------------------------------------------------------------------- 263 // -------------------------------------------------------------------
258 264
259 // Reused output buffer. Used when parsing date strings. 265 // Reused output buffer. Used when parsing date strings.
260 var parse_buffer = new InternalArray(8); 266 var parse_buffer = new InternalArray(8);
261 267
262 // ECMA 262 - 15.9.4.2 268 // ECMA 262 - 15.9.4.2
263 function DateParse(string) { 269 function DateParse(string) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 302
297 303
298 // ECMA 262 - 15.9.4.4 304 // ECMA 262 - 15.9.4.4
299 function DateNow() { 305 function DateNow() {
300 return %DateCurrentTime(); 306 return %DateCurrentTime();
301 } 307 }
302 308
303 309
304 // ECMA 262 - 15.9.5.2 310 // ECMA 262 - 15.9.5.2
305 function DateToString() { 311 function DateToString() {
312 CHECK_DATE(this);
306 var t = UTC_DATE_VALUE(this) 313 var t = UTC_DATE_VALUE(this)
307 if (NUMBER_IS_NAN(t)) return kInvalidDate; 314 if (NUMBER_IS_NAN(t)) return kInvalidDate;
308 var time_zone_string = LocalTimezoneString(this) 315 var time_zone_string = LocalTimezoneString(this)
309 return DatePrintString(this) + time_zone_string; 316 return DatePrintString(this) + time_zone_string;
310 } 317 }
311 318
312 319
313 // ECMA 262 - 15.9.5.3 320 // ECMA 262 - 15.9.5.3
314 function DateToDateString() { 321 function DateToDateString() {
322 CHECK_DATE(this);
315 var t = UTC_DATE_VALUE(this); 323 var t = UTC_DATE_VALUE(this);
316 if (NUMBER_IS_NAN(t)) return kInvalidDate; 324 if (NUMBER_IS_NAN(t)) return kInvalidDate;
317 return DateString(this); 325 return DateString(this);
318 } 326 }
319 327
320 328
321 // ECMA 262 - 15.9.5.4 329 // ECMA 262 - 15.9.5.4
322 function DateToTimeString() { 330 function DateToTimeString() {
331 CHECK_DATE(this);
323 var t = UTC_DATE_VALUE(this); 332 var t = UTC_DATE_VALUE(this);
324 if (NUMBER_IS_NAN(t)) return kInvalidDate; 333 if (NUMBER_IS_NAN(t)) return kInvalidDate;
325 var time_zone_string = LocalTimezoneString(this); 334 var time_zone_string = LocalTimezoneString(this);
326 return TimeString(this) + time_zone_string; 335 return TimeString(this) + time_zone_string;
327 } 336 }
328 337
329 338
330 // ECMA 262 - 15.9.5.5 339 // ECMA 262 - 15.9.5.5
331 function DateToLocaleString() { 340 function DateToLocaleString() {
341 CHECK_DATE(this);
332 return %_CallFunction(this, DateToString); 342 return %_CallFunction(this, DateToString);
333 } 343 }
334 344
335 345
336 // ECMA 262 - 15.9.5.6 346 // ECMA 262 - 15.9.5.6
337 function DateToLocaleDateString() { 347 function DateToLocaleDateString() {
348 CHECK_DATE(this);
338 var t = UTC_DATE_VALUE(this); 349 var t = UTC_DATE_VALUE(this);
339 if (NUMBER_IS_NAN(t)) return kInvalidDate; 350 if (NUMBER_IS_NAN(t)) return kInvalidDate;
340 return LongDateString(this); 351 return LongDateString(this);
341 } 352 }
342 353
343 354
344 // ECMA 262 - 15.9.5.7 355 // ECMA 262 - 15.9.5.7
345 function DateToLocaleTimeString() { 356 function DateToLocaleTimeString() {
357 CHECK_DATE(this);
346 var t = UTC_DATE_VALUE(this); 358 var t = UTC_DATE_VALUE(this);
347 if (NUMBER_IS_NAN(t)) return kInvalidDate; 359 if (NUMBER_IS_NAN(t)) return kInvalidDate;
348 return TimeString(this); 360 return TimeString(this);
349 } 361 }
350 362
351 363
352 // ECMA 262 - 15.9.5.8 364 // ECMA 262 - 15.9.5.8
353 function DateValueOf() { 365 function DateValueOf() {
366 CHECK_DATE(this);
354 return UTC_DATE_VALUE(this); 367 return UTC_DATE_VALUE(this);
355 } 368 }
356 369
357 370
358 // ECMA 262 - 15.9.5.9 371 // ECMA 262 - 15.9.5.9
359 function DateGetTime() { 372 function DateGetTime() {
373 CHECK_DATE(this);
360 return UTC_DATE_VALUE(this); 374 return UTC_DATE_VALUE(this);
361 } 375 }
362 376
363 377
364 // ECMA 262 - 15.9.5.10 378 // ECMA 262 - 15.9.5.10
365 function DateGetFullYear() { 379 function DateGetFullYear() {
380 CHECK_DATE(this);
366 return LOCAL_YEAR(this); 381 return LOCAL_YEAR(this);
367 } 382 }
368 383
369 384
370 // ECMA 262 - 15.9.5.11 385 // ECMA 262 - 15.9.5.11
371 function DateGetUTCFullYear() { 386 function DateGetUTCFullYear() {
387 CHECK_DATE(this);
372 return UTC_YEAR(this); 388 return UTC_YEAR(this);
373 } 389 }
374 390
375 391
376 // ECMA 262 - 15.9.5.12 392 // ECMA 262 - 15.9.5.12
377 function DateGetMonth() { 393 function DateGetMonth() {
394 CHECK_DATE(this);
378 return LOCAL_MONTH(this); 395 return LOCAL_MONTH(this);
379 } 396 }
380 397
381 398
382 // ECMA 262 - 15.9.5.13 399 // ECMA 262 - 15.9.5.13
383 function DateGetUTCMonth() { 400 function DateGetUTCMonth() {
401 CHECK_DATE(this);
384 return UTC_MONTH(this); 402 return UTC_MONTH(this);
385 } 403 }
386 404
387 405
388 // ECMA 262 - 15.9.5.14 406 // ECMA 262 - 15.9.5.14
389 function DateGetDate() { 407 function DateGetDate() {
408 CHECK_DATE(this);
390 return LOCAL_DAY(this); 409 return LOCAL_DAY(this);
391 } 410 }
392 411
393 412
394 // ECMA 262 - 15.9.5.15 413 // ECMA 262 - 15.9.5.15
395 function DateGetUTCDate() { 414 function DateGetUTCDate() {
415 CHECK_DATE(this);
396 return UTC_DAY(this); 416 return UTC_DAY(this);
397 } 417 }
398 418
399 419
400 // ECMA 262 - 15.9.5.16 420 // ECMA 262 - 15.9.5.16
401 function DateGetDay() { 421 function DateGetDay() {
422 CHECK_DATE(this);
402 return LOCAL_WEEKDAY(this); 423 return LOCAL_WEEKDAY(this);
403 } 424 }
404 425
405 426
406 // ECMA 262 - 15.9.5.17 427 // ECMA 262 - 15.9.5.17
407 function DateGetUTCDay() { 428 function DateGetUTCDay() {
429 CHECK_DATE(this);
408 return UTC_WEEKDAY(this); 430 return UTC_WEEKDAY(this);
409 } 431 }
410 432
411 433
412 // ECMA 262 - 15.9.5.18 434 // ECMA 262 - 15.9.5.18
413 function DateGetHours() { 435 function DateGetHours() {
436 CHECK_DATE(this);
414 return LOCAL_HOUR(this); 437 return LOCAL_HOUR(this);
415 } 438 }
416 439
417 440
418 // ECMA 262 - 15.9.5.19 441 // ECMA 262 - 15.9.5.19
419 function DateGetUTCHours() { 442 function DateGetUTCHours() {
443 CHECK_DATE(this);
420 return UTC_HOUR(this); 444 return UTC_HOUR(this);
421 } 445 }
422 446
423 447
424 // ECMA 262 - 15.9.5.20 448 // ECMA 262 - 15.9.5.20
425 function DateGetMinutes() { 449 function DateGetMinutes() {
450 CHECK_DATE(this);
426 return LOCAL_MIN(this); 451 return LOCAL_MIN(this);
427 } 452 }
428 453
429 454
430 // ECMA 262 - 15.9.5.21 455 // ECMA 262 - 15.9.5.21
431 function DateGetUTCMinutes() { 456 function DateGetUTCMinutes() {
457 CHECK_DATE(this);
432 return UTC_MIN(this); 458 return UTC_MIN(this);
433 } 459 }
434 460
435 461
436 // ECMA 262 - 15.9.5.22 462 // ECMA 262 - 15.9.5.22
437 function DateGetSeconds() { 463 function DateGetSeconds() {
464 CHECK_DATE(this);
438 return LOCAL_SEC(this); 465 return LOCAL_SEC(this);
439 } 466 }
440 467
441 468
442 // ECMA 262 - 15.9.5.23 469 // ECMA 262 - 15.9.5.23
443 function DateGetUTCSeconds() { 470 function DateGetUTCSeconds() {
471 CHECK_DATE(this);
444 return UTC_SEC(this) 472 return UTC_SEC(this)
445 } 473 }
446 474
447 475
448 // ECMA 262 - 15.9.5.24 476 // ECMA 262 - 15.9.5.24
449 function DateGetMilliseconds() { 477 function DateGetMilliseconds() {
478 CHECK_DATE(this);
450 return LOCAL_MS(this); 479 return LOCAL_MS(this);
451 } 480 }
452 481
453 482
454 // ECMA 262 - 15.9.5.25 483 // ECMA 262 - 15.9.5.25
455 function DateGetUTCMilliseconds() { 484 function DateGetUTCMilliseconds() {
485 CHECK_DATE(this);
456 return UTC_MS(this); 486 return UTC_MS(this);
457 } 487 }
458 488
459 489
460 // ECMA 262 - 15.9.5.26 490 // ECMA 262 - 15.9.5.26
461 function DateGetTimezoneOffset() { 491 function DateGetTimezoneOffset() {
492 CHECK_DATE(this);
462 return TIMEZONE_OFFSET(this); 493 return TIMEZONE_OFFSET(this);
463 } 494 }
464 495
465 496
466 // ECMA 262 - 15.9.5.27 497 // ECMA 262 - 15.9.5.27
467 function DateSetTime(ms) { 498 function DateSetTime(ms) {
468 CHECK_DATE(this); 499 CHECK_DATE(this);
469 SET_UTC_DATE_VALUE(this, $toNumber(ms)); 500 SET_UTC_DATE_VALUE(this, $toNumber(ms));
470 return UTC_DATE_VALUE(this); 501 return UTC_DATE_VALUE(this);
471 } 502 }
472 503
473 504
474 // ECMA 262 - 15.9.5.28 505 // ECMA 262 - 15.9.5.28
475 function DateSetMilliseconds(ms) { 506 function DateSetMilliseconds(ms) {
507 CHECK_DATE(this);
476 var t = LOCAL_DATE_VALUE(this); 508 var t = LOCAL_DATE_VALUE(this);
477 ms = $toNumber(ms); 509 ms = $toNumber(ms);
478 var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), LOCAL_SEC(this), ms); 510 var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), LOCAL_SEC(this), ms);
479 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); 511 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
480 } 512 }
481 513
482 514
483 // ECMA 262 - 15.9.5.29 515 // ECMA 262 - 15.9.5.29
484 function DateSetUTCMilliseconds(ms) { 516 function DateSetUTCMilliseconds(ms) {
517 CHECK_DATE(this);
485 var t = UTC_DATE_VALUE(this); 518 var t = UTC_DATE_VALUE(this);
486 ms = $toNumber(ms); 519 ms = $toNumber(ms);
487 var time = MakeTime(UTC_HOUR(this), 520 var time = MakeTime(UTC_HOUR(this),
488 UTC_MIN(this), 521 UTC_MIN(this),
489 UTC_SEC(this), 522 UTC_SEC(this),
490 ms); 523 ms);
491 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); 524 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
492 } 525 }
493 526
494 527
495 // ECMA 262 - 15.9.5.30 528 // ECMA 262 - 15.9.5.30
496 function DateSetSeconds(sec, ms) { 529 function DateSetSeconds(sec, ms) {
530 CHECK_DATE(this);
497 var t = LOCAL_DATE_VALUE(this); 531 var t = LOCAL_DATE_VALUE(this);
498 sec = $toNumber(sec); 532 sec = $toNumber(sec);
499 ms = %_ArgumentsLength() < 2 ? LOCAL_MS(this) : $toNumber(ms); 533 ms = %_ArgumentsLength() < 2 ? LOCAL_MS(this) : $toNumber(ms);
500 var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), sec, ms); 534 var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), sec, ms);
501 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); 535 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
502 } 536 }
503 537
504 538
505 // ECMA 262 - 15.9.5.31 539 // ECMA 262 - 15.9.5.31
506 function DateSetUTCSeconds(sec, ms) { 540 function DateSetUTCSeconds(sec, ms) {
541 CHECK_DATE(this);
507 var t = UTC_DATE_VALUE(this); 542 var t = UTC_DATE_VALUE(this);
508 sec = $toNumber(sec); 543 sec = $toNumber(sec);
509 ms = %_ArgumentsLength() < 2 ? UTC_MS(this) : $toNumber(ms); 544 ms = %_ArgumentsLength() < 2 ? UTC_MS(this) : $toNumber(ms);
510 var time = MakeTime(UTC_HOUR(this), UTC_MIN(this), sec, ms); 545 var time = MakeTime(UTC_HOUR(this), UTC_MIN(this), sec, ms);
511 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); 546 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
512 } 547 }
513 548
514 549
515 // ECMA 262 - 15.9.5.33 550 // ECMA 262 - 15.9.5.33
516 function DateSetMinutes(min, sec, ms) { 551 function DateSetMinutes(min, sec, ms) {
552 CHECK_DATE(this);
517 var t = LOCAL_DATE_VALUE(this); 553 var t = LOCAL_DATE_VALUE(this);
518 min = $toNumber(min); 554 min = $toNumber(min);
519 var argc = %_ArgumentsLength(); 555 var argc = %_ArgumentsLength();
520 sec = argc < 2 ? LOCAL_SEC(this) : $toNumber(sec); 556 sec = argc < 2 ? LOCAL_SEC(this) : $toNumber(sec);
521 ms = argc < 3 ? LOCAL_MS(this) : $toNumber(ms); 557 ms = argc < 3 ? LOCAL_MS(this) : $toNumber(ms);
522 var time = MakeTime(LOCAL_HOUR(this), min, sec, ms); 558 var time = MakeTime(LOCAL_HOUR(this), min, sec, ms);
523 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); 559 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
524 } 560 }
525 561
526 562
527 // ECMA 262 - 15.9.5.34 563 // ECMA 262 - 15.9.5.34
528 function DateSetUTCMinutes(min, sec, ms) { 564 function DateSetUTCMinutes(min, sec, ms) {
565 CHECK_DATE(this);
529 var t = UTC_DATE_VALUE(this); 566 var t = UTC_DATE_VALUE(this);
530 min = $toNumber(min); 567 min = $toNumber(min);
531 var argc = %_ArgumentsLength(); 568 var argc = %_ArgumentsLength();
532 sec = argc < 2 ? UTC_SEC(this) : $toNumber(sec); 569 sec = argc < 2 ? UTC_SEC(this) : $toNumber(sec);
533 ms = argc < 3 ? UTC_MS(this) : $toNumber(ms); 570 ms = argc < 3 ? UTC_MS(this) : $toNumber(ms);
534 var time = MakeTime(UTC_HOUR(this), min, sec, ms); 571 var time = MakeTime(UTC_HOUR(this), min, sec, ms);
535 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); 572 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
536 } 573 }
537 574
538 575
539 // ECMA 262 - 15.9.5.35 576 // ECMA 262 - 15.9.5.35
540 function DateSetHours(hour, min, sec, ms) { 577 function DateSetHours(hour, min, sec, ms) {
578 CHECK_DATE(this);
541 var t = LOCAL_DATE_VALUE(this); 579 var t = LOCAL_DATE_VALUE(this);
542 hour = $toNumber(hour); 580 hour = $toNumber(hour);
543 var argc = %_ArgumentsLength(); 581 var argc = %_ArgumentsLength();
544 min = argc < 2 ? LOCAL_MIN(this) : $toNumber(min); 582 min = argc < 2 ? LOCAL_MIN(this) : $toNumber(min);
545 sec = argc < 3 ? LOCAL_SEC(this) : $toNumber(sec); 583 sec = argc < 3 ? LOCAL_SEC(this) : $toNumber(sec);
546 ms = argc < 4 ? LOCAL_MS(this) : $toNumber(ms); 584 ms = argc < 4 ? LOCAL_MS(this) : $toNumber(ms);
547 var time = MakeTime(hour, min, sec, ms); 585 var time = MakeTime(hour, min, sec, ms);
548 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); 586 return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
549 } 587 }
550 588
551 589
552 // ECMA 262 - 15.9.5.34 590 // ECMA 262 - 15.9.5.34
553 function DateSetUTCHours(hour, min, sec, ms) { 591 function DateSetUTCHours(hour, min, sec, ms) {
592 CHECK_DATE(this);
554 var t = UTC_DATE_VALUE(this); 593 var t = UTC_DATE_VALUE(this);
555 hour = $toNumber(hour); 594 hour = $toNumber(hour);
556 var argc = %_ArgumentsLength(); 595 var argc = %_ArgumentsLength();
557 min = argc < 2 ? UTC_MIN(this) : $toNumber(min); 596 min = argc < 2 ? UTC_MIN(this) : $toNumber(min);
558 sec = argc < 3 ? UTC_SEC(this) : $toNumber(sec); 597 sec = argc < 3 ? UTC_SEC(this) : $toNumber(sec);
559 ms = argc < 4 ? UTC_MS(this) : $toNumber(ms); 598 ms = argc < 4 ? UTC_MS(this) : $toNumber(ms);
560 var time = MakeTime(hour, min, sec, ms); 599 var time = MakeTime(hour, min, sec, ms);
561 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); 600 return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
562 } 601 }
563 602
564 603
565 // ECMA 262 - 15.9.5.36 604 // ECMA 262 - 15.9.5.36
566 function DateSetDate(date) { 605 function DateSetDate(date) {
606 CHECK_DATE(this);
567 var t = LOCAL_DATE_VALUE(this); 607 var t = LOCAL_DATE_VALUE(this);
568 date = $toNumber(date); 608 date = $toNumber(date);
569 var day = MakeDay(LOCAL_YEAR(this), LOCAL_MONTH(this), date); 609 var day = MakeDay(LOCAL_YEAR(this), LOCAL_MONTH(this), date);
570 return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this))); 610 return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this)));
571 } 611 }
572 612
573 613
574 // ECMA 262 - 15.9.5.37 614 // ECMA 262 - 15.9.5.37
575 function DateSetUTCDate(date) { 615 function DateSetUTCDate(date) {
616 CHECK_DATE(this);
576 var t = UTC_DATE_VALUE(this); 617 var t = UTC_DATE_VALUE(this);
577 date = $toNumber(date); 618 date = $toNumber(date);
578 var day = MakeDay(UTC_YEAR(this), UTC_MONTH(this), date); 619 var day = MakeDay(UTC_YEAR(this), UTC_MONTH(this), date);
579 return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this))); 620 return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this)));
580 } 621 }
581 622
582 623
583 // ECMA 262 - 15.9.5.38 624 // ECMA 262 - 15.9.5.38
584 function DateSetMonth(month, date) { 625 function DateSetMonth(month, date) {
626 CHECK_DATE(this);
585 var t = LOCAL_DATE_VALUE(this); 627 var t = LOCAL_DATE_VALUE(this);
586 month = $toNumber(month); 628 month = $toNumber(month);
587 date = %_ArgumentsLength() < 2 ? LOCAL_DAY(this) : $toNumber(date); 629 date = %_ArgumentsLength() < 2 ? LOCAL_DAY(this) : $toNumber(date);
588 var day = MakeDay(LOCAL_YEAR(this), month, date); 630 var day = MakeDay(LOCAL_YEAR(this), month, date);
589 return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this))); 631 return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this)));
590 } 632 }
591 633
592 634
593 // ECMA 262 - 15.9.5.39 635 // ECMA 262 - 15.9.5.39
594 function DateSetUTCMonth(month, date) { 636 function DateSetUTCMonth(month, date) {
637 CHECK_DATE(this);
595 var t = UTC_DATE_VALUE(this); 638 var t = UTC_DATE_VALUE(this);
596 month = $toNumber(month); 639 month = $toNumber(month);
597 date = %_ArgumentsLength() < 2 ? UTC_DAY(this) : $toNumber(date); 640 date = %_ArgumentsLength() < 2 ? UTC_DAY(this) : $toNumber(date);
598 var day = MakeDay(UTC_YEAR(this), month, date); 641 var day = MakeDay(UTC_YEAR(this), month, date);
599 return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this))); 642 return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this)));
600 } 643 }
601 644
602 645
603 // ECMA 262 - 15.9.5.40 646 // ECMA 262 - 15.9.5.40
604 function DateSetFullYear(year, month, date) { 647 function DateSetFullYear(year, month, date) {
648 CHECK_DATE(this);
605 var t = LOCAL_DATE_VALUE(this); 649 var t = LOCAL_DATE_VALUE(this);
606 year = $toNumber(year); 650 year = $toNumber(year);
607 var argc = %_ArgumentsLength(); 651 var argc = %_ArgumentsLength();
608 var time ; 652 var time ;
609 if (NUMBER_IS_NAN(t)) { 653 if (NUMBER_IS_NAN(t)) {
610 month = argc < 2 ? 0 : $toNumber(month); 654 month = argc < 2 ? 0 : $toNumber(month);
611 date = argc < 3 ? 1 : $toNumber(date); 655 date = argc < 3 ? 1 : $toNumber(date);
612 time = 0; 656 time = 0;
613 } else { 657 } else {
614 month = argc < 2 ? LOCAL_MONTH(this) : $toNumber(month); 658 month = argc < 2 ? LOCAL_MONTH(this) : $toNumber(month);
615 date = argc < 3 ? LOCAL_DAY(this) : $toNumber(date); 659 date = argc < 3 ? LOCAL_DAY(this) : $toNumber(date);
616 time = LOCAL_TIME_IN_DAY(this); 660 time = LOCAL_TIME_IN_DAY(this);
617 } 661 }
618 var day = MakeDay(year, month, date); 662 var day = MakeDay(year, month, date);
619 return SET_LOCAL_DATE_VALUE(this, MakeDate(day, time)); 663 return SET_LOCAL_DATE_VALUE(this, MakeDate(day, time));
620 } 664 }
621 665
622 666
623 // ECMA 262 - 15.9.5.41 667 // ECMA 262 - 15.9.5.41
624 function DateSetUTCFullYear(year, month, date) { 668 function DateSetUTCFullYear(year, month, date) {
669 CHECK_DATE(this);
625 var t = UTC_DATE_VALUE(this); 670 var t = UTC_DATE_VALUE(this);
626 year = $toNumber(year); 671 year = $toNumber(year);
627 var argc = %_ArgumentsLength(); 672 var argc = %_ArgumentsLength();
628 var time ; 673 var time ;
629 if (NUMBER_IS_NAN(t)) { 674 if (NUMBER_IS_NAN(t)) {
630 month = argc < 2 ? 0 : $toNumber(month); 675 month = argc < 2 ? 0 : $toNumber(month);
631 date = argc < 3 ? 1 : $toNumber(date); 676 date = argc < 3 ? 1 : $toNumber(date);
632 time = 0; 677 time = 0;
633 } else { 678 } else {
634 month = argc < 2 ? UTC_MONTH(this) : $toNumber(month); 679 month = argc < 2 ? UTC_MONTH(this) : $toNumber(month);
635 date = argc < 3 ? UTC_DAY(this) : $toNumber(date); 680 date = argc < 3 ? UTC_DAY(this) : $toNumber(date);
636 time = UTC_TIME_IN_DAY(this); 681 time = UTC_TIME_IN_DAY(this);
637 } 682 }
638 var day = MakeDay(year, month, date); 683 var day = MakeDay(year, month, date);
639 return SET_UTC_DATE_VALUE(this, MakeDate(day, time)); 684 return SET_UTC_DATE_VALUE(this, MakeDate(day, time));
640 } 685 }
641 686
642 687
643 // ECMA 262 - 15.9.5.42 688 // ECMA 262 - 15.9.5.42
644 function DateToUTCString() { 689 function DateToUTCString() {
690 CHECK_DATE(this);
645 var t = UTC_DATE_VALUE(this); 691 var t = UTC_DATE_VALUE(this);
646 if (NUMBER_IS_NAN(t)) return kInvalidDate; 692 if (NUMBER_IS_NAN(t)) return kInvalidDate;
647 // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT 693 // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT
648 return WeekDays[UTC_WEEKDAY(this)] + ', ' 694 return WeekDays[UTC_WEEKDAY(this)] + ', '
649 + TwoDigitString(UTC_DAY(this)) + ' ' 695 + TwoDigitString(UTC_DAY(this)) + ' '
650 + Months[UTC_MONTH(this)] + ' ' 696 + Months[UTC_MONTH(this)] + ' '
651 + UTC_YEAR(this) + ' ' 697 + UTC_YEAR(this) + ' '
652 + TimeStringUTC(this) + ' GMT'; 698 + TimeStringUTC(this) + ' GMT';
653 } 699 }
654 700
655 701
656 // ECMA 262 - B.2.4 702 // ECMA 262 - B.2.4
657 function DateGetYear() { 703 function DateGetYear() {
704 CHECK_DATE(this);
658 return LOCAL_YEAR(this) - 1900; 705 return LOCAL_YEAR(this) - 1900;
659 } 706 }
660 707
661 708
662 // ECMA 262 - B.2.5 709 // ECMA 262 - B.2.5
663 function DateSetYear(year) { 710 function DateSetYear(year) {
664 CHECK_DATE(this); 711 CHECK_DATE(this);
665 year = $toNumber(year); 712 year = $toNumber(year);
666 if (NUMBER_IS_NAN(year)) return SET_UTC_DATE_VALUE(this, NAN); 713 if (NUMBER_IS_NAN(year)) return SET_UTC_DATE_VALUE(this, NAN);
667 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) 714 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
(...skipping 27 matching lines...) Expand all
695 742
696 743
697 function PadInt(n, digits) { 744 function PadInt(n, digits) {
698 if (digits == 1) return n; 745 if (digits == 1) return n;
699 return n < %_MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n; 746 return n < %_MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n;
700 } 747 }
701 748
702 749
703 // ECMA 262 - 15.9.5.43 750 // ECMA 262 - 15.9.5.43
704 function DateToISOString() { 751 function DateToISOString() {
752 CHECK_DATE(this);
705 var t = UTC_DATE_VALUE(this); 753 var t = UTC_DATE_VALUE(this);
706 if (NUMBER_IS_NAN(t)) throw MakeRangeError(kInvalidTimeValue); 754 if (NUMBER_IS_NAN(t)) throw MakeRangeError(kInvalidTimeValue);
707 var year = this.getUTCFullYear(); 755 var year = this.getUTCFullYear();
708 var year_string; 756 var year_string;
709 if (year >= 0 && year <= 9999) { 757 if (year >= 0 && year <= 9999) {
710 year_string = PadInt(year, 4); 758 year_string = PadInt(year, 4);
711 } else { 759 } else {
712 if (year < 0) { 760 if (year < 0) {
713 year_string = "-" + PadInt(-year, 6); 761 year_string = "-" + PadInt(-year, 6);
714 } else { 762 } else {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 "getYear", DateGetYear, 877 "getYear", DateGetYear,
830 "setYear", DateSetYear, 878 "setYear", DateSetYear,
831 "toISOString", DateToISOString, 879 "toISOString", DateToISOString,
832 "toJSON", DateToJSON 880 "toJSON", DateToJSON
833 ]); 881 ]);
834 882
835 // Expose to the global scope. 883 // Expose to the global scope.
836 $createDate = CreateDate; 884 $createDate = CreateDate;
837 885
838 }) 886 })
OLDNEW
« no previous file with comments | « src/compiler/linkage.cc ('k') | src/deoptimizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698