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.24-1.js |
michael@0 | 9 | ECMA Section: 15.9.5.24 Date.prototype.setTime(time) |
michael@0 | 10 | Description: |
michael@0 | 11 | 1. If the this value is not a Date object, generate a runtime error. |
michael@0 | 12 | 2. Call ToNumber(time). |
michael@0 | 13 | 3. Call TimeClip(Result(1)). |
michael@0 | 14 | 4. Set the [[Value]] property of the this value to Result(2). |
michael@0 | 15 | 5. Return the value of the [[Value]] property of the this value. |
michael@0 | 16 | Author: christine@netscape.com |
michael@0 | 17 | Date: 12 november 1997 |
michael@0 | 18 | |
michael@0 | 19 | */ |
michael@0 | 20 | var TITLE = "Date.prototype.setTime" |
michael@0 | 21 | var SECTION = "15.9.5.24-1"; |
michael@0 | 22 | var VERSION = "ECMA_1"; |
michael@0 | 23 | startTest(); |
michael@0 | 24 | |
michael@0 | 25 | writeHeaderToLog( SECTION + " Date.prototype.setMilliseconds(ms)"); |
michael@0 | 26 | |
michael@0 | 27 | |
michael@0 | 28 | addTestCase( 0, -2208988800000 ); |
michael@0 | 29 | |
michael@0 | 30 | test(); |
michael@0 | 31 | |
michael@0 | 32 | function addTestCase( startms, newms ) { |
michael@0 | 33 | |
michael@0 | 34 | var DateCase = new Date( startms ); |
michael@0 | 35 | DateCase.setMilliseconds( newms ); |
michael@0 | 36 | var DateString = "var date = new Date("+ startms +"); date.setMilliseconds("+ newms +"); date"; |
michael@0 | 37 | var localms = UTC( Number(newms) + LocalTime( Number(startms) ) ); |
michael@0 | 38 | var UTCDate = UTCDateFromTime( localms ); |
michael@0 | 39 | var LocalDate = LocalDateFromTime( localms ); |
michael@0 | 40 | |
michael@0 | 41 | new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); |
michael@0 | 42 | new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); |
michael@0 | 43 | |
michael@0 | 44 | new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); |
michael@0 | 45 | new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); |
michael@0 | 46 | new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); |
michael@0 | 47 | |
michael@0 | 48 | new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); |
michael@0 | 49 | new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); |
michael@0 | 50 | new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); |
michael@0 | 51 | new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); |
michael@0 | 52 | |
michael@0 | 53 | new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); |
michael@0 | 54 | new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); |
michael@0 | 55 | new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); |
michael@0 | 56 | |
michael@0 | 57 | new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); |
michael@0 | 58 | new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); |
michael@0 | 59 | new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); |
michael@0 | 60 | new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); |
michael@0 | 61 | |
michael@0 | 62 | DateCase.toString = Object.prototype.toString; |
michael@0 | 63 | |
michael@0 | 64 | new TestCase( SECTION, |
michael@0 | 65 | DateString+".toString=Object.prototype.toString;"+DateString+".toString()", |
michael@0 | 66 | "[object Date]", |
michael@0 | 67 | DateCase.toString() ); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function MyDate() { |
michael@0 | 71 | this.year = 0; |
michael@0 | 72 | this.month = 0; |
michael@0 | 73 | this.date = 0; |
michael@0 | 74 | this.hours = 0; |
michael@0 | 75 | this.minutes = 0; |
michael@0 | 76 | this.seconds = 0; |
michael@0 | 77 | this.ms = 0; |
michael@0 | 78 | } |
michael@0 | 79 | function LocalDateFromTime(t) { |
michael@0 | 80 | t = LocalTime(t); |
michael@0 | 81 | return ( MyDateFromTime(t) ); |
michael@0 | 82 | } |
michael@0 | 83 | function UTCDateFromTime(t) { |
michael@0 | 84 | return ( MyDateFromTime(t) ); |
michael@0 | 85 | } |
michael@0 | 86 | function MyDateFromTime( t ) { |
michael@0 | 87 | var d = new MyDate(); |
michael@0 | 88 | d.year = YearFromTime(t); |
michael@0 | 89 | d.month = MonthFromTime(t); |
michael@0 | 90 | d.date = DateFromTime(t); |
michael@0 | 91 | d.hours = HourFromTime(t); |
michael@0 | 92 | d.minutes = MinFromTime(t); |
michael@0 | 93 | d.seconds = SecFromTime(t); |
michael@0 | 94 | d.ms = msFromTime(t); |
michael@0 | 95 | |
michael@0 | 96 | d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); |
michael@0 | 97 | d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); |
michael@0 | 98 | d.day = WeekDay( d.value ); |
michael@0 | 99 | |
michael@0 | 100 | return (d); |
michael@0 | 101 | } |