Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | File Name: 15.9.5.37-1.js |
michael@0 | 9 | ECMA Section: 15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] ) |
michael@0 | 10 | Description: |
michael@0 | 11 | |
michael@0 | 12 | If mon is not specified, this behaves as if mon were specified with the |
michael@0 | 13 | value getUTCMonth( ). If date is not specified, this behaves as if date |
michael@0 | 14 | were specified with the value getUTCDate( ). |
michael@0 | 15 | |
michael@0 | 16 | 1. Let t be this time value; but if this time value is NaN, let t be +0. |
michael@0 | 17 | 2. Call ToNumber(year). |
michael@0 | 18 | 3. If mon is not specified, compute MonthFromTime(t); otherwise, call |
michael@0 | 19 | ToNumber(mon). |
michael@0 | 20 | 4. If date is not specified, compute DateFromTime(t); otherwise, call |
michael@0 | 21 | ToNumber(date). |
michael@0 | 22 | 5. Compute MakeDay(Result(2), Result(3), Result(4)). |
michael@0 | 23 | 6. Compute MakeDate(Result(5), TimeWithinDay(t)). |
michael@0 | 24 | 7. Set the [[Value]] property of the this value to TimeClip(Result(6)). |
michael@0 | 25 | 8. Return the value of the [[Value]] property of the this value. |
michael@0 | 26 | |
michael@0 | 27 | Author: christine@netscape.com |
michael@0 | 28 | Date: 12 november 1997 |
michael@0 | 29 | |
michael@0 | 30 | Added some Year 2000 test cases. |
michael@0 | 31 | */ |
michael@0 | 32 | var SECTION = "15.9.5.37-1"; |
michael@0 | 33 | var VERSION = "ECMA_1"; |
michael@0 | 34 | startTest(); |
michael@0 | 35 | |
michael@0 | 36 | writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )"); |
michael@0 | 37 | |
michael@0 | 38 | // Dates around 1900 |
michael@0 | 39 | addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1900);TDATE", |
michael@0 | 40 | UTCDateFromTime(SetUTCFullYear(0,1900)), |
michael@0 | 41 | LocalDateFromTime(SetUTCFullYear(0,1900)) ); |
michael@0 | 42 | |
michael@0 | 43 | addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1899);TDATE", |
michael@0 | 44 | UTCDateFromTime(SetUTCFullYear(0,1899)), |
michael@0 | 45 | LocalDateFromTime(SetUTCFullYear(0,1899)) ); |
michael@0 | 46 | |
michael@0 | 47 | addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1901);TDATE", |
michael@0 | 48 | UTCDateFromTime(SetUTCFullYear(0,1901)), |
michael@0 | 49 | LocalDateFromTime(SetUTCFullYear(0,1901)) ); |
michael@0 | 50 | |
michael@0 | 51 | test(); |
michael@0 | 52 | |
michael@0 | 53 | function addNewTestCase( DateString, UTCDate, LocalDate) { |
michael@0 | 54 | DateCase = eval( DateString ); |
michael@0 | 55 | |
michael@0 | 56 | new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); |
michael@0 | 57 | new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); |
michael@0 | 58 | |
michael@0 | 59 | new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); |
michael@0 | 60 | new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); |
michael@0 | 61 | new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); |
michael@0 | 62 | new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); |
michael@0 | 63 | new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); |
michael@0 | 64 | new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); |
michael@0 | 65 | new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); |
michael@0 | 66 | new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); |
michael@0 | 67 | |
michael@0 | 68 | new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); |
michael@0 | 69 | new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); |
michael@0 | 70 | new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); |
michael@0 | 71 | new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); |
michael@0 | 72 | new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); |
michael@0 | 73 | new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); |
michael@0 | 74 | new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); |
michael@0 | 75 | new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); |
michael@0 | 76 | |
michael@0 | 77 | DateCase.toString = Object.prototype.toString; |
michael@0 | 78 | |
michael@0 | 79 | new TestCase( SECTION, |
michael@0 | 80 | DateString+".toString=Object.prototype.toString;"+DateString+".toString()", |
michael@0 | 81 | "[object Date]", |
michael@0 | 82 | DateCase.toString() ); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function MyDate() { |
michael@0 | 86 | this.year = 0; |
michael@0 | 87 | this.month = 0; |
michael@0 | 88 | this.date = 0; |
michael@0 | 89 | this.hours = 0; |
michael@0 | 90 | this.minutes = 0; |
michael@0 | 91 | this.seconds = 0; |
michael@0 | 92 | this.ms = 0; |
michael@0 | 93 | } |
michael@0 | 94 | function LocalDateFromTime(t) { |
michael@0 | 95 | t = LocalTime(t); |
michael@0 | 96 | return ( MyDateFromTime(t) ); |
michael@0 | 97 | } |
michael@0 | 98 | function UTCDateFromTime(t) { |
michael@0 | 99 | return ( MyDateFromTime(t) ); |
michael@0 | 100 | } |
michael@0 | 101 | function MyDateFromTime( t ) { |
michael@0 | 102 | var d = new MyDate(); |
michael@0 | 103 | d.year = YearFromTime(t); |
michael@0 | 104 | d.month = MonthFromTime(t); |
michael@0 | 105 | d.date = DateFromTime(t); |
michael@0 | 106 | d.hours = HourFromTime(t); |
michael@0 | 107 | d.minutes = MinFromTime(t); |
michael@0 | 108 | d.seconds = SecFromTime(t); |
michael@0 | 109 | d.ms = msFromTime(t); |
michael@0 | 110 | |
michael@0 | 111 | d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); |
michael@0 | 112 | d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); |
michael@0 | 113 | d.day = WeekDay( d.value ); |
michael@0 | 114 | |
michael@0 | 115 | return (d); |
michael@0 | 116 | } |
michael@0 | 117 | function SetUTCFullYear( t, year, mon, date ) { |
michael@0 | 118 | var T = ( t != t ) ? 0 : t; |
michael@0 | 119 | var YEAR = Number(year); |
michael@0 | 120 | var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon ); |
michael@0 | 121 | var DATE = ( date == void 0 ) ? DateFromTime(T) : Number( date ); |
michael@0 | 122 | var DAY = MakeDay( YEAR, MONTH, DATE ); |
michael@0 | 123 | |
michael@0 | 124 | return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) ); |
michael@0 | 125 | } |