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 | /** File Name: 15.9.5.26-1.js |
michael@0 | 8 | ECMA Section: 15.9.5.26 Date.prototype.setSeconds(sec [,ms]) |
michael@0 | 9 | Description: |
michael@0 | 10 | |
michael@0 | 11 | If ms is not specified, this behaves as if ms were specified with the |
michael@0 | 12 | value getMilliseconds( ). |
michael@0 | 13 | |
michael@0 | 14 | 1. Let t be the result of LocalTime(this time value). |
michael@0 | 15 | 2. Call ToNumber(sec). |
michael@0 | 16 | 3. If ms is not specified, compute msFromTime(t); otherwise, call |
michael@0 | 17 | ToNumber(ms). |
michael@0 | 18 | 4. Compute MakeTime(HourFromTime(t), MinFromTime(t), Result(2), |
michael@0 | 19 | Result(3)). |
michael@0 | 20 | 5. Compute UTC(MakeDate(Day(t), Result(4))). |
michael@0 | 21 | 6. Set the [[Value]] property of the this value to TimeClip(Result(5)). |
michael@0 | 22 | 7. Return the value of the [[Value]] property of the this value. |
michael@0 | 23 | |
michael@0 | 24 | Author: christine@netscape.com |
michael@0 | 25 | Date: 12 november 1997 |
michael@0 | 26 | */ |
michael@0 | 27 | var SECTION = "15.9.5.26-1"; |
michael@0 | 28 | var VERSION = "ECMA_1"; |
michael@0 | 29 | startTest(); |
michael@0 | 30 | |
michael@0 | 31 | writeHeaderToLog( SECTION + " Date.prototype.setSeconds(sec [,ms] )"); |
michael@0 | 32 | |
michael@0 | 33 | addNewTestCase( 0, 0, 0, |
michael@0 | 34 | "TDATE = new Date(0);(TDATE).setSeconds(0,0);TDATE", |
michael@0 | 35 | UTCDateFromTime(SetSeconds(0,0,0)), |
michael@0 | 36 | LocalDateFromTime(SetSeconds(0,0,0)) ); |
michael@0 | 37 | |
michael@0 | 38 | addNewTestCase( 28800000,59,999, |
michael@0 | 39 | "TDATE = new Date(28800000);(TDATE).setSeconds(59,999);TDATE", |
michael@0 | 40 | UTCDateFromTime(SetSeconds(28800000,59,999)), |
michael@0 | 41 | LocalDateFromTime(SetSeconds(28800000,59,999)) ); |
michael@0 | 42 | |
michael@0 | 43 | addNewTestCase( 28800000,999,999, |
michael@0 | 44 | "TDATE = new Date(28800000);(TDATE).setSeconds(999,999);TDATE", |
michael@0 | 45 | UTCDateFromTime(SetSeconds(28800000,999,999)), |
michael@0 | 46 | LocalDateFromTime(SetSeconds(28800000,999,999)) ); |
michael@0 | 47 | |
michael@0 | 48 | addNewTestCase( 28800000,999, void 0, |
michael@0 | 49 | "TDATE = new Date(28800000);(TDATE).setSeconds(999);TDATE", |
michael@0 | 50 | UTCDateFromTime(SetSeconds(28800000,999,0)), |
michael@0 | 51 | LocalDateFromTime(SetSeconds(28800000,999,0)) ); |
michael@0 | 52 | |
michael@0 | 53 | addNewTestCase( 28800000,-28800, void 0, |
michael@0 | 54 | "TDATE = new Date(28800000);(TDATE).setSeconds(-28800);TDATE", |
michael@0 | 55 | UTCDateFromTime(SetSeconds(28800000,-28800)), |
michael@0 | 56 | LocalDateFromTime(SetSeconds(28800000,-28800)) ); |
michael@0 | 57 | |
michael@0 | 58 | addNewTestCase( 946684800000,1234567,void 0, |
michael@0 | 59 | "TDATE = new Date(946684800000);(TDATE).setSeconds(1234567);TDATE", |
michael@0 | 60 | UTCDateFromTime(SetSeconds(946684800000,1234567)), |
michael@0 | 61 | LocalDateFromTime(SetSeconds(946684800000,1234567)) ); |
michael@0 | 62 | |
michael@0 | 63 | addNewTestCase( -2208988800000,59,999, |
michael@0 | 64 | "TDATE = new Date(-2208988800000);(TDATE).setSeconds(59,999);TDATE", |
michael@0 | 65 | UTCDateFromTime(SetSeconds(-2208988800000,59,999)), |
michael@0 | 66 | LocalDateFromTime(SetSeconds(-2208988800000,59,999)) ); |
michael@0 | 67 | |
michael@0 | 68 | test(); |
michael@0 | 69 | |
michael@0 | 70 | function addNewTestCase( startTime, sec, ms, DateString,UTCDate, LocalDate) { |
michael@0 | 71 | DateCase = new Date( startTime ); |
michael@0 | 72 | if ( ms != void 0 ) { |
michael@0 | 73 | DateCase.setSeconds( sec, ms ); |
michael@0 | 74 | } else { |
michael@0 | 75 | DateCase.setSeconds( sec ); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); |
michael@0 | 79 | new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); |
michael@0 | 80 | |
michael@0 | 81 | new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); |
michael@0 | 82 | new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); |
michael@0 | 83 | new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); |
michael@0 | 84 | |
michael@0 | 85 | new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); |
michael@0 | 86 | new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); |
michael@0 | 87 | new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); |
michael@0 | 88 | new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); |
michael@0 | 89 | |
michael@0 | 90 | new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); |
michael@0 | 91 | new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); |
michael@0 | 92 | new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); |
michael@0 | 93 | |
michael@0 | 94 | new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); |
michael@0 | 95 | new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); |
michael@0 | 96 | new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); |
michael@0 | 97 | new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); |
michael@0 | 98 | |
michael@0 | 99 | DateCase.toString = Object.prototype.toString; |
michael@0 | 100 | |
michael@0 | 101 | new TestCase( SECTION, |
michael@0 | 102 | DateString+".toString=Object.prototype.toString;"+DateString+".toString()", |
michael@0 | 103 | "[object Date]", |
michael@0 | 104 | DateCase.toString() ); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function MyDate() { |
michael@0 | 108 | this.year = 0; |
michael@0 | 109 | this.month = 0; |
michael@0 | 110 | this.date = 0; |
michael@0 | 111 | this.hours = 0; |
michael@0 | 112 | this.minutes = 0; |
michael@0 | 113 | this.seconds = 0; |
michael@0 | 114 | this.ms = 0; |
michael@0 | 115 | } |
michael@0 | 116 | function LocalDateFromTime(t) { |
michael@0 | 117 | t = LocalTime(t); |
michael@0 | 118 | return ( MyDateFromTime(t) ); |
michael@0 | 119 | } |
michael@0 | 120 | function UTCDateFromTime(t) { |
michael@0 | 121 | return ( MyDateFromTime(t) ); |
michael@0 | 122 | } |
michael@0 | 123 | function MyDateFromTime( t ) { |
michael@0 | 124 | var d = new MyDate(); |
michael@0 | 125 | d.year = YearFromTime(t); |
michael@0 | 126 | d.month = MonthFromTime(t); |
michael@0 | 127 | d.date = DateFromTime(t); |
michael@0 | 128 | d.hours = HourFromTime(t); |
michael@0 | 129 | d.minutes = MinFromTime(t); |
michael@0 | 130 | d.seconds = SecFromTime(t); |
michael@0 | 131 | d.ms = msFromTime(t); |
michael@0 | 132 | |
michael@0 | 133 | d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); |
michael@0 | 134 | d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); |
michael@0 | 135 | d.day = WeekDay( d.value ); |
michael@0 | 136 | |
michael@0 | 137 | return (d); |
michael@0 | 138 | } |
michael@0 | 139 | function SetSeconds( t, s, m ) { |
michael@0 | 140 | var MS = ( m == void 0 ) ? msFromTime(t) : Number( m ); |
michael@0 | 141 | var TIME = LocalTime( t ); |
michael@0 | 142 | var SEC = Number(s); |
michael@0 | 143 | var RESULT4 = MakeTime( HourFromTime( TIME ), |
michael@0 | 144 | MinFromTime( TIME ), |
michael@0 | 145 | SEC, |
michael@0 | 146 | MS ); |
michael@0 | 147 | var UTC_TIME = UTC(MakeDate(Day(TIME), RESULT4)); |
michael@0 | 148 | return ( TimeClip(UTC_TIME) ); |
michael@0 | 149 | } |