mirror of https://github.com/tc39/test262.git
Moved all test helper functions into sta.js; removed sputnikLib.js.
Laid down the groundwork for a console-based test runner.
This commit is contained in:
parent
352d86b8ed
commit
ffa85c2584
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
|
||||
var msPerDay = 86400000;
|
||||
var msPerSecond = 1000;
|
||||
var msPerMinute = 60000;
|
||||
var msPerHour = 3600000;
|
||||
|
||||
var date_1899_end = -2208988800001;
|
||||
var date_1900_start = -2208988800000;
|
||||
var date_1969_end = -1;
|
||||
var date_1970_start = 0;
|
||||
var date_1999_end = 946684799999;
|
||||
var date_2000_start = 946684800000;
|
||||
var date_2099_end = 4102444799999;
|
||||
var date_2100_start = 4102444800000;
|
|
@ -1,411 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
var $LocalTZ,
|
||||
$DST_start_month,
|
||||
$DST_start_sunday,
|
||||
$DST_start_hour,
|
||||
$DST_start_minutes,
|
||||
$DST_end_month,
|
||||
$DST_end_sunday,
|
||||
$DST_end_hour,
|
||||
$DST_end_minutes;
|
||||
|
||||
(function () {
|
||||
/**
|
||||
* Finds the first date, starting from |start|, where |predicate|
|
||||
* holds.
|
||||
*/
|
||||
var findNearestDateBefore = function(start, predicate) {
|
||||
var current = start;
|
||||
var month = 1000 * 60 * 60 * 24 * 30;
|
||||
for (var step = month; step > 0; step = Math.floor(step / 3)) {
|
||||
if (!predicate(current)) {
|
||||
while (!predicate(current))
|
||||
current = new Date(current.getTime() + step);
|
||||
current = new Date(current.getTime() - step);
|
||||
}
|
||||
}
|
||||
while (!predicate(current)) {
|
||||
current = new Date(current.getTime() + 1);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
|
||||
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
|
||||
var juneOffset = juneDate.getTimezoneOffset();
|
||||
var decemberOffset = decemberDate.getTimezoneOffset();
|
||||
var isSouthernHemisphere = (juneOffset > decemberOffset);
|
||||
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
|
||||
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
|
||||
|
||||
var dstStart = findNearestDateBefore(winterTime, function (date) {
|
||||
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_start_month = dstStart.getMonth();
|
||||
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_start_hour = dstStart.getHours();
|
||||
$DST_start_minutes = dstStart.getMinutes();
|
||||
|
||||
var dstEnd = findNearestDateBefore(summerTime, function (date) {
|
||||
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_end_month = dstEnd.getMonth();
|
||||
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_end_hour = dstEnd.getHours();
|
||||
$DST_end_minutes = dstEnd.getMinutes();
|
||||
|
||||
return;
|
||||
})();
|
||||
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
}
|
||||
|
||||
function TimeWithinDay(t) {
|
||||
return t%msPerDay;
|
||||
}
|
||||
|
||||
//15.9.1.3 Year Number
|
||||
function DaysInYear(y){
|
||||
if(y%4 != 0) return 365;
|
||||
if(y%4 == 0 && y%100 != 0) return 366;
|
||||
if(y%100 == 0 && y%400 != 0) return 365;
|
||||
if(y%400 == 0) return 366;
|
||||
}
|
||||
|
||||
function DayFromYear(y) {
|
||||
return (365*(y-1970)
|
||||
+ Math.floor((y-1969)/4)
|
||||
- Math.floor((y-1901)/100)
|
||||
+ Math.floor((y-1601)/400));
|
||||
}
|
||||
|
||||
function TimeFromYear(y){
|
||||
return msPerDay*DayFromYear(y);
|
||||
}
|
||||
|
||||
function YearFromTime(t) {
|
||||
t = Number(t);
|
||||
var sign = ( t < 0 ) ? -1 : 1;
|
||||
var year = ( sign < 0 ) ? 1969 : 1970;
|
||||
|
||||
for(var time = 0;;year += sign){
|
||||
time = TimeFromYear(year);
|
||||
|
||||
if(sign > 0 && time > t){
|
||||
year -= sign;
|
||||
break;
|
||||
}
|
||||
else if(sign < 0 && time <= t){
|
||||
break;
|
||||
}
|
||||
};
|
||||
return year;
|
||||
}
|
||||
|
||||
function InLeapYear(t){
|
||||
if(DaysInYear(YearFromTime(t)) == 365)
|
||||
return 0;
|
||||
|
||||
if(DaysInYear(YearFromTime(t)) == 366)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function DayWithinYear(t) {
|
||||
return Day(t)-DayFromYear(YearFromTime(t));
|
||||
}
|
||||
|
||||
//15.9.1.4 Month Number
|
||||
function MonthFromTime(t){
|
||||
var day = DayWithinYear(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if((0 <= day) && (day < 31)) return 0;
|
||||
if((31 <= day) && (day < (59+leap))) return 1;
|
||||
if(((59+leap) <= day) && (day < (90+leap))) return 2;
|
||||
if(((90+leap) <= day) && (day < (120+leap))) return 3;
|
||||
if(((120+leap) <= day) && (day < (151+leap))) return 4;
|
||||
if(((151+leap) <= day) && (day < (181+leap))) return 5;
|
||||
if(((181+leap) <= day) && (day < (212+leap))) return 6;
|
||||
if(((212+leap) <= day) && (day < (243+leap))) return 7;
|
||||
if(((243+leap) <= day) && (day < (273+leap))) return 8;
|
||||
if(((273+leap) <= day) && (day < (304+leap))) return 9;
|
||||
if(((304+leap) <= day) && (day < (334+leap))) return 10;
|
||||
if(((334+leap) <= day) && (day < (365+leap))) return 11;
|
||||
}
|
||||
|
||||
//15.9.1.5 Date Number
|
||||
function DateFromTime(t) {
|
||||
var day = DayWithinYear(t);
|
||||
var month = MonthFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if(month == 0) return day+1;
|
||||
if(month == 1) return day-30;
|
||||
if(month == 2) return day-58-leap;
|
||||
if(month == 3) return day-89-leap;
|
||||
if(month == 4) return day-119-leap;
|
||||
if(month == 5) return day-150-leap;
|
||||
if(month == 6) return day-180-leap;
|
||||
if(month == 7) return day-211-leap;
|
||||
if(month == 8) return day-242-leap;
|
||||
if(month == 9) return day-272-leap;
|
||||
if(month == 10) return day-303-leap;
|
||||
if(month == 11) return day-333-leap;
|
||||
}
|
||||
|
||||
//15.9.1.6 Week Day
|
||||
function WeekDay(t) {
|
||||
var weekday = (Day(t)+4)%7;
|
||||
return (weekday < 0 ? 7+weekday : weekday);
|
||||
}
|
||||
|
||||
//15.9.1.9 Daylight Saving Time Adjustment
|
||||
$LocalTZ = (new Date()).getTimezoneOffset() / -60;
|
||||
if (DaylightSavingTA((new Date()).valueOf()) !== 0) {
|
||||
$LocalTZ -= 1;
|
||||
}
|
||||
var LocalTZA = $LocalTZ*msPerHour;
|
||||
|
||||
function DaysInMonth(m, leap) {
|
||||
m = m%12;
|
||||
|
||||
//April, June, Sept, Nov
|
||||
if(m == 3 || m == 5 || m == 8 || m == 10 ) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
//Jan, March, May, July, Aug, Oct, Dec
|
||||
if(m == 0 || m == 2 || m == 4 || m == 6 || m == 7 || m == 9 || m == 11){
|
||||
return 31;
|
||||
}
|
||||
|
||||
//Feb
|
||||
return 28+leap;
|
||||
}
|
||||
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
|
||||
if (count==='"first"') {
|
||||
for (var d=1; d <= DaysInMonth(m, InLeapYear(t)); d++) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
} else if(count==='"last"') {
|
||||
for (var d=DaysInMonth(m, InLeapYear(t)); d>0; d--) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("Unsupported 'count' arg:" + count);
|
||||
}
|
||||
/*
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
var day = 0;
|
||||
|
||||
if(m >= 1) day += DaysInMonth(0, leap);
|
||||
if(m >= 2) day += DaysInMonth(1, leap);
|
||||
if(m >= 3) day += DaysInMonth(2, leap);
|
||||
if(m >= 4) day += DaysInMonth(3, leap);
|
||||
if(m >= 5) day += DaysInMonth(4, leap);
|
||||
if(m >= 6) day += DaysInMonth(5, leap);
|
||||
if(m >= 7) day += DaysInMonth(6, leap);
|
||||
if(m >= 8) day += DaysInMonth(7, leap);
|
||||
if(m >= 9) day += DaysInMonth(8, leap);
|
||||
if(m >= 10) day += DaysInMonth(9, leap);
|
||||
if(m >= 11) day += DaysInMonth(10, leap);
|
||||
|
||||
var month_start = TimeFromYear(year)+day*msPerDay;
|
||||
var sunday = 0;
|
||||
|
||||
if(count === "last"){
|
||||
for(var last_sunday = month_start+DaysInMonth(m, leap)*msPerDay;
|
||||
WeekDay(last_sunday)>0;
|
||||
last_sunday -= msPerDay
|
||||
){};
|
||||
sunday = last_sunday;
|
||||
}
|
||||
else {
|
||||
for(var first_sunday = month_start;
|
||||
WeekDay(first_sunday)>0;
|
||||
first_sunday += msPerDay
|
||||
){};
|
||||
sunday = first_sunday+7*msPerDay*(count-1);
|
||||
}
|
||||
|
||||
return sunday;
|
||||
}*/
|
||||
|
||||
function DaylightSavingTA(t) {
|
||||
// t = t-LocalTZA;
|
||||
|
||||
var DST_start = GetSundayInMonth(t, $DST_start_month, $DST_start_sunday) +
|
||||
$DST_start_hour*msPerHour +
|
||||
$DST_start_minutes*msPerMinute;
|
||||
|
||||
var k = new Date(DST_start);
|
||||
|
||||
var DST_end = GetSundayInMonth(t, $DST_end_month, $DST_end_sunday) +
|
||||
$DST_end_hour*msPerHour +
|
||||
$DST_end_minutes*msPerMinute;
|
||||
|
||||
if ( t >= DST_start && t < DST_end ) {
|
||||
return msPerHour;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//15.9.1.9 Local Time
|
||||
function LocalTime(t){
|
||||
return t+LocalTZA+DaylightSavingTA(t);
|
||||
}
|
||||
|
||||
function UTC(t) {
|
||||
return t-LocalTZA-DaylightSavingTA(t-LocalTZA);
|
||||
}
|
||||
|
||||
//15.9.1.10 Hours, Minutes, Second, and Milliseconds
|
||||
function HourFromTime(t){
|
||||
return Math.floor(t/msPerHour)%HoursPerDay;
|
||||
}
|
||||
|
||||
function MinFromTime(t){
|
||||
return Math.floor(t/msPerMinute)%MinutesPerHour;
|
||||
}
|
||||
|
||||
function SecFromTime(t){
|
||||
return Math.floor(t/msPerSecond)%SecondsPerMinute;
|
||||
}
|
||||
|
||||
function msFromTime(t){
|
||||
return t%msPerSecond;
|
||||
}
|
||||
|
||||
//15.9.1.11 MakeTime (hour, min, sec, ms)
|
||||
function MakeTime(hour, min, sec, ms){
|
||||
if ( !isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
hour = ToInteger(hour);
|
||||
min = ToInteger(min);
|
||||
sec = ToInteger(sec);
|
||||
ms = ToInteger(ms);
|
||||
|
||||
return ((hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms);
|
||||
}
|
||||
|
||||
//15.9.1.12 MakeDay (year, month, date)
|
||||
function MakeDay(year, month, date) {
|
||||
if ( !isFinite(year) || !isFinite(month) || !isFinite(date)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
year = ToInteger(year);
|
||||
month = ToInteger(month);
|
||||
date = ToInteger(date );
|
||||
|
||||
var result5 = year + Math.floor(month/12);
|
||||
var result6 = month%12;
|
||||
|
||||
var sign = ( year < 1970 ) ? -1 : 1;
|
||||
var t = ( year < 1970 ) ? 1 : 0;
|
||||
var y = ( year < 1970 ) ? 1969 : 1970;
|
||||
|
||||
if( sign == -1 ){
|
||||
for ( y = 1969; y >= year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
} else {
|
||||
for ( y = 1970 ; y < year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
}
|
||||
|
||||
var leap = 0;
|
||||
for ( var m = 0; m < month; m++ ) {
|
||||
//if year is changed, than we need to recalculate leep
|
||||
leap = InLeapYear(t);
|
||||
t += DaysInMonth(m, leap)*msPerDay;
|
||||
}
|
||||
|
||||
if ( YearFromTime(t) != result5 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( MonthFromTime(t) != result6 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( DateFromTime(t) != 1 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return Day(t)+date-1;
|
||||
}
|
||||
|
||||
//15.9.1.13 MakeDate (day, time)
|
||||
function MakeDate( day, time ) {
|
||||
if(!isFinite(day) || !isFinite(time)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return day*msPerDay+time;
|
||||
}
|
||||
|
||||
//15.9.1.14 TimeClip (time)
|
||||
function TimeClip(time) {
|
||||
if(!isFinite(time) || Math.abs(time) > 8.64e15){
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return ToInteger(time);
|
||||
}
|
||||
|
||||
//Test Functions
|
||||
function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
||||
/*
|
||||
* 1. Call ToNumber(year)
|
||||
* 2. Call ToNumber(month)
|
||||
* 3. If date is supplied use ToNumber(date); else use 1
|
||||
* 4. If hours is supplied use ToNumber(hours); else use 0
|
||||
* 5. If minutes is supplied use ToNumber(minutes); else use 0
|
||||
* 6. If seconds is supplied use ToNumber(seconds); else use 0
|
||||
* 7. If ms is supplied use ToNumber(ms); else use 0
|
||||
* 8. If Result(1) is not NaN and 0 <= ToInteger(Result(1)) <= 99, Result(8) is
|
||||
* 1900+ToInteger(Result(1)); otherwise, Result(8) is Result(1)
|
||||
* 9. Compute MakeDay(Result(8), Result(2), Result(3))
|
||||
* 10. Compute MakeTime(Result(4), Result(5), Result(6), Result(7))
|
||||
* 11. Compute MakeDate(Result(9), Result(10))
|
||||
* 12. Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(11)))
|
||||
*/
|
||||
var r1 = Number(year);
|
||||
var r2 = Number(month);
|
||||
var r3 = ((date && arguments.length > 2) ? Number(date) : 1);
|
||||
var r4 = ((hours && arguments.length > 3) ? Number(hours) : 0);
|
||||
var r5 = ((minutes && arguments.length > 4) ? Number(minutes) : 0);
|
||||
var r6 = ((seconds && arguments.length > 5) ? Number(seconds) : 0);
|
||||
var r7 = ((ms && arguments.length > 6) ? Number(ms) : 0);
|
||||
|
||||
var r8 = r1;
|
||||
|
||||
if(!isNaN(r1) && (0 <= ToInteger(r1)) && (ToInteger(r1) <= 99))
|
||||
r8 = 1900+r1;
|
||||
|
||||
var r9 = MakeDay(r8, r2, r3);
|
||||
var r10 = MakeTime(r4, r5, r6, r7);
|
||||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/// Copyright (c) 2011 Microsoft Corporation
|
||||
///
|
||||
/// Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
/// that the following conditions are met:
|
||||
/// * Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
/// the following disclaimer.
|
||||
/// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
/// the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
/// * Neither the name of Microsoft nor the names of its contributors may be used to
|
||||
/// endorse or promote products derived from this software without specific prior written permission.
|
||||
///
|
||||
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
/// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
/// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
/// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
/// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
/// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
/// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
function testRun(id, path, description, codeString, result, error) {
|
||||
if (result!=="pass") {
|
||||
throw new Error("Test '" + path + "'failed: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
function testFinished() {
|
||||
//no-op
|
||||
}
|
|
@ -19,9 +19,10 @@
|
|||
/// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//Error Detector
|
||||
|
||||
window.onerror = function(errorMsg, url, lineNumber) {
|
||||
window.iframeError = errorMsg;
|
||||
if (this.window!==undefined) { //for console support
|
||||
window.onerror = function(errorMsg, url, lineNumber) {
|
||||
window.iframeError = errorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
//This doesn't work with early errors in current versions of Opera
|
||||
|
|
|
@ -22,18 +22,18 @@
|
|||
|
||||
//An exception is expected
|
||||
if (testDescrip.negative !== undefined) {
|
||||
//TODO - come up with a generic way of catching the error type from window.onerror
|
||||
//TODO - come up with a generic way of catching the error type from this.onerror
|
||||
testDescrip.negative = testDescrip.negative === "NotEarlyError" ?
|
||||
testDescrip.negative : (testDescrip.negative === "^((?!NotEarlyError).)*$" ?
|
||||
testDescrip.negative : ".");
|
||||
if (window.iframeError === undefined) { //no exception was thrown
|
||||
if (this.iframeError === undefined) { //no exception was thrown
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'fail',
|
||||
Error('No exception was thrown; expected an error "message" property matching the regular expression "' + testDescrip.negative + '".'));
|
||||
} else if (!(new RegExp(testDescrip.negative, "i").test(window.iframeError))) { //wrong type of exception thrown
|
||||
} else if (!(new RegExp(testDescrip.negative, "i").test(this.iframeError))) { //wrong type of exception thrown
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'fail',
|
||||
Error('Expected an exception with a "message" property matching the regular expression "' + testDescrip.negative +'" to be thrown; actual was "' + window.iframeError + '".'));
|
||||
Error('Expected an exception with a "message" property matching the regular expression "' + testDescrip.negative +'" to be thrown; actual was "' + this.iframeError + '".'));
|
||||
} else {
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'pass', undefined);
|
||||
|
@ -41,10 +41,10 @@ if (testDescrip.negative !== undefined) {
|
|||
}
|
||||
|
||||
//Exception was not expected to be thrown
|
||||
else if (window.iframeError !== undefined) {
|
||||
else if (this.iframeError !== undefined) {
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'fail',
|
||||
Error('Unexpected exception, "' + window.iframeError + '" was thrown.'));
|
||||
Error('Unexpected exception, "' + this.iframeError + '" was thrown.'));
|
||||
}
|
||||
|
||||
else {
|
||||
|
|
|
@ -1,548 +0,0 @@
|
|||
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function Test262Error(message) {
|
||||
if (message) this.message = message;
|
||||
}
|
||||
|
||||
Test262Error.prototype.toString = function () {
|
||||
return "Test262 Error: " + this.message;
|
||||
};
|
||||
|
||||
function testFailed(message) {
|
||||
throw new Test262Error(message);
|
||||
}
|
||||
|
||||
|
||||
function testPrint(message) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//adaptors for Test262 framework
|
||||
function $PRINT(message) {
|
||||
|
||||
}
|
||||
|
||||
function $INCLUDE(message) { }
|
||||
function $ERROR(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
function $FAIL(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Sputnik library definitions
|
||||
//Ultimately these should be namespaced some how and only made
|
||||
//available to tests that explicitly include them.
|
||||
//For now, we just define the globally
|
||||
|
||||
//math_precision.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function getPrecision(num)
|
||||
{
|
||||
//TODO: Create a table of prec's,
|
||||
// because using Math for testing Math isn't that correct.
|
||||
|
||||
log2num = Math.log(Math.abs(num))/Math.LN2;
|
||||
pernum = Math.ceil(log2num);
|
||||
return(2 * Math.pow(2, -52 + pernum));
|
||||
//return(0);
|
||||
}
|
||||
|
||||
|
||||
//math_isequal.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var prec;
|
||||
function isEqual(num1, num2)
|
||||
{
|
||||
if ((num1 === Infinity)&&(num2 === Infinity))
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
if ((num1 === -Infinity)&&(num2 === -Infinity))
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
prec = getPrecision(Math.min(Math.abs(num1), Math.abs(num2)));
|
||||
return(Math.abs(num1 - num2) <= prec);
|
||||
//return(num1 === num2);
|
||||
}
|
||||
|
||||
//numeric_conversion.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function ToInteger(p) {
|
||||
x = Number(p);
|
||||
|
||||
if(isNaN(x)){
|
||||
return +0;
|
||||
}
|
||||
|
||||
if((x === +0)
|
||||
|| (x === -0)
|
||||
|| (x === Number.POSITIVE_INFINITY)
|
||||
|| (x === Number.NEGATIVE_INFINITY)){
|
||||
return x;
|
||||
}
|
||||
|
||||
var sign = ( x < 0 ) ? -1 : 1;
|
||||
|
||||
return (sign*Math.floor(Math.abs(x)));
|
||||
}
|
||||
|
||||
//Date_constants.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
|
||||
var msPerDay = 86400000;
|
||||
var msPerSecond = 1000;
|
||||
var msPerMinute = 60000;
|
||||
var msPerHour = 3600000;
|
||||
|
||||
var date_1899_end = -2208988800001;
|
||||
var date_1900_start = -2208988800000;
|
||||
var date_1969_end = -1;
|
||||
var date_1970_start = 0;
|
||||
var date_1999_end = 946684799999;
|
||||
var date_2000_start = 946684800000;
|
||||
var date_2099_end = 4102444799999;
|
||||
var date_2100_start = 4102444800000;
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
// for now, we'll just use 0 for everything
|
||||
var $LocalTZ = 0;
|
||||
var $DST_start_month = 0;
|
||||
var $DST_start_sunday = 0;
|
||||
var $DST_start_hour = 0;
|
||||
var $DST_start_minutes = 0;
|
||||
var $DST_end_month = 0;
|
||||
var $DST_end_sunday = 0;
|
||||
var $DST_end_hour = 0;
|
||||
var $DST_end_minutes = 0;
|
||||
|
||||
|
||||
//Date.library.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
}
|
||||
|
||||
function TimeWithinDay(t) {
|
||||
return t%msPerDay;
|
||||
}
|
||||
|
||||
//15.9.1.3 Year Number
|
||||
function DaysInYear(y){
|
||||
if(y%4 != 0) return 365;
|
||||
if(y%4 == 0 && y%100 != 0) return 366;
|
||||
if(y%100 == 0 && y%400 != 0) return 365;
|
||||
if(y%400 == 0) return 366;
|
||||
}
|
||||
|
||||
function DayFromYear(y) {
|
||||
return (365*(y-1970)
|
||||
+ Math.floor((y-1969)/4)
|
||||
- Math.floor((y-1901)/100)
|
||||
+ Math.floor((y-1601)/400));
|
||||
}
|
||||
|
||||
function TimeFromYear(y){
|
||||
return msPerDay*DayFromYear(y);
|
||||
}
|
||||
|
||||
function YearFromTime(t) {
|
||||
t = Number(t);
|
||||
var sign = ( t < 0 ) ? -1 : 1;
|
||||
var year = ( sign < 0 ) ? 1969 : 1970;
|
||||
|
||||
for(var time = 0;;year += sign){
|
||||
time = TimeFromYear(year);
|
||||
|
||||
if(sign > 0 && time > t){
|
||||
year -= sign;
|
||||
break;
|
||||
}
|
||||
else if(sign < 0 && time <= t){
|
||||
break;
|
||||
}
|
||||
};
|
||||
return year;
|
||||
}
|
||||
|
||||
function InLeapYear(t){
|
||||
if(DaysInYear(YearFromTime(t)) == 365)
|
||||
return 0;
|
||||
|
||||
if(DaysInYear(YearFromTime(t)) == 366)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function DayWithinYear(t) {
|
||||
return Day(t)-DayFromYear(YearFromTime(t));
|
||||
}
|
||||
|
||||
//15.9.1.4 Month Number
|
||||
function MonthFromTime(t){
|
||||
var day = DayWithinYear(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if((0 <= day) && (day < 31)) return 0;
|
||||
if((31 <= day) && (day < (59+leap))) return 1;
|
||||
if(((59+leap) <= day) && (day < (90+leap))) return 2;
|
||||
if(((90+leap) <= day) && (day < (120+leap))) return 3;
|
||||
if(((120+leap) <= day) && (day < (151+leap))) return 4;
|
||||
if(((151+leap) <= day) && (day < (181+leap))) return 5;
|
||||
if(((181+leap) <= day) && (day < (212+leap))) return 6;
|
||||
if(((212+leap) <= day) && (day < (243+leap))) return 7;
|
||||
if(((243+leap) <= day) && (day < (273+leap))) return 8;
|
||||
if(((273+leap) <= day) && (day < (304+leap))) return 9;
|
||||
if(((304+leap) <= day) && (day < (334+leap))) return 10;
|
||||
if(((334+leap) <= day) && (day < (365+leap))) return 11;
|
||||
}
|
||||
|
||||
//15.9.1.5 Date Number
|
||||
function DateFromTime(t) {
|
||||
var day = DayWithinYear(t);
|
||||
var month = MonthFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if(month == 0) return day+1;
|
||||
if(month == 1) return day-30;
|
||||
if(month == 2) return day-58-leap;
|
||||
if(month == 3) return day-89-leap;
|
||||
if(month == 4) return day-119-leap;
|
||||
if(month == 5) return day-150-leap;
|
||||
if(month == 6) return day-180-leap;
|
||||
if(month == 7) return day-211-leap;
|
||||
if(month == 8) return day-242-leap;
|
||||
if(month == 9) return day-272-leap;
|
||||
if(month == 10) return day-303-leap;
|
||||
if(month == 11) return day-333-leap;
|
||||
}
|
||||
|
||||
//15.9.1.6 Week Day
|
||||
function WeekDay(t) {
|
||||
var weekday = (Day(t)+4)%7;
|
||||
return (weekday < 0 ? 7+weekday : weekday);
|
||||
}
|
||||
|
||||
//15.9.1.9 Daylight Saving Time Adjustment
|
||||
var LocalTZA = $LocalTZ*msPerHour;
|
||||
|
||||
function DaysInMonth(m, leap) {
|
||||
m = m%12;
|
||||
|
||||
//April, June, Sept, Nov
|
||||
if(m == 3 || m == 5 || m == 8 || m == 10 ) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
//Jan, March, May, July, Aug, Oct, Dec
|
||||
if(m == 0 || m == 2 || m == 4 || m == 6 || m == 7 || m == 9 || m == 11){
|
||||
return 31;
|
||||
}
|
||||
|
||||
//Feb
|
||||
return 28+leap;
|
||||
}
|
||||
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
var day = 0;
|
||||
|
||||
if(m >= 1) day += DaysInMonth(0, leap);
|
||||
if(m >= 2) day += DaysInMonth(1, leap);
|
||||
if(m >= 3) day += DaysInMonth(2, leap);
|
||||
if(m >= 4) day += DaysInMonth(3, leap);
|
||||
if(m >= 5) day += DaysInMonth(4, leap);
|
||||
if(m >= 6) day += DaysInMonth(5, leap);
|
||||
if(m >= 7) day += DaysInMonth(6, leap);
|
||||
if(m >= 8) day += DaysInMonth(7, leap);
|
||||
if(m >= 9) day += DaysInMonth(8, leap);
|
||||
if(m >= 10) day += DaysInMonth(9, leap);
|
||||
if(m >= 11) day += DaysInMonth(10, leap);
|
||||
|
||||
var month_start = TimeFromYear(year)+day*msPerDay;
|
||||
var sunday = 0;
|
||||
|
||||
if(count === "last"){
|
||||
for(var last_sunday = month_start+DaysInMonth(m, leap)*msPerDay;
|
||||
WeekDay(last_sunday)>0;
|
||||
last_sunday -= msPerDay
|
||||
){};
|
||||
sunday = last_sunday;
|
||||
}
|
||||
else {
|
||||
for(var first_sunday = month_start;
|
||||
WeekDay(first_sunday)>0;
|
||||
first_sunday += msPerDay
|
||||
){};
|
||||
sunday = first_sunday+7*msPerDay*(count-1);
|
||||
}
|
||||
|
||||
return sunday;
|
||||
}
|
||||
|
||||
function DaylightSavingTA(t) {
|
||||
t = t-LocalTZA;
|
||||
|
||||
var DST_start = GetSundayInMonth(t, $DST_start_month, $DST_start_sunday)
|
||||
+$DST_start_hour*msPerHour
|
||||
+$DST_start_minutes*msPerMinute;
|
||||
|
||||
var k = new Date(DST_start);
|
||||
|
||||
var DST_end = GetSundayInMonth(t, $DST_end_month, $DST_end_sunday)
|
||||
+$DST_end_hour*msPerHour
|
||||
+$DST_end_minutes*msPerMinute;
|
||||
|
||||
if ( t >= DST_start && t < DST_end ) {
|
||||
return msPerHour;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//15.9.1.9 Local Time
|
||||
function LocalTime(t){
|
||||
return t+LocalTZA+DaylightSavingTA(t);
|
||||
}
|
||||
|
||||
function UTC(t) {
|
||||
return t-LocalTZA-DaylightSavingTA(t-LocalTZA);
|
||||
}
|
||||
|
||||
//15.9.1.10 Hours, Minutes, Second, and Milliseconds
|
||||
function HourFromTime(t){
|
||||
return Math.floor(t/msPerHour)%HoursPerDay;
|
||||
}
|
||||
|
||||
function MinFromTime(t){
|
||||
return Math.floor(t/msPerMinute)%MinutesPerHour;
|
||||
}
|
||||
|
||||
function SecFromTime(t){
|
||||
return Math.floor(t/msPerSecond)%SecondsPerMinute;
|
||||
}
|
||||
|
||||
function msFromTime(t){
|
||||
return t%msPerSecond;
|
||||
}
|
||||
|
||||
//15.9.1.11 MakeTime (hour, min, sec, ms)
|
||||
function MakeTime(hour, min, sec, ms){
|
||||
if ( !isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
hour = ToInteger(hour);
|
||||
min = ToInteger(min);
|
||||
sec = ToInteger(sec);
|
||||
ms = ToInteger(ms);
|
||||
|
||||
return ((hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms);
|
||||
}
|
||||
|
||||
//15.9.1.12 MakeDay (year, month, date)
|
||||
function MakeDay(year, month, date) {
|
||||
if ( !isFinite(year) || !isFinite(month) || !isFinite(date)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
year = ToInteger(year);
|
||||
month = ToInteger(month);
|
||||
date = ToInteger(date );
|
||||
|
||||
var result5 = year + Math.floor(month/12);
|
||||
var result6 = month%12;
|
||||
|
||||
var sign = ( year < 1970 ) ? -1 : 1;
|
||||
var t = ( year < 1970 ) ? 1 : 0;
|
||||
var y = ( year < 1970 ) ? 1969 : 1970;
|
||||
|
||||
if( sign == -1 ){
|
||||
for ( y = 1969; y >= year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
} else {
|
||||
for ( y = 1970 ; y < year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
}
|
||||
|
||||
var leap = 0;
|
||||
for ( var m = 0; m < month; m++ ) {
|
||||
//if year is changed, than we need to recalculate leep
|
||||
leap = InLeapYear(t);
|
||||
t += DaysInMonth(m, leap)*msPerDay;
|
||||
}
|
||||
|
||||
if ( YearFromTime(t) != result5 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( MonthFromTime(t) != result6 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( DateFromTime(t) != 1 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return Day(t)+date-1;
|
||||
}
|
||||
|
||||
//15.9.1.13 MakeDate (day, time)
|
||||
function MakeDate( day, time ) {
|
||||
if(!isFinite(day) || !isFinite(time)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return day*msPerDay+time;
|
||||
}
|
||||
|
||||
//15.9.1.14 TimeClip (time)
|
||||
function TimeClip(time) {
|
||||
if(!isFinite(time) || Math.abs(time) > 8.64e15){
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return ToInteger(time);
|
||||
}
|
||||
|
||||
//Test Functions
|
||||
function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
||||
/*
|
||||
* 1. Call ToNumber(year)
|
||||
* 2. Call ToNumber(month)
|
||||
* 3. If date is supplied use ToNumber(date); else use 1
|
||||
* 4. If hours is supplied use ToNumber(hours); else use 0
|
||||
* 5. If minutes is supplied use ToNumber(minutes); else use 0
|
||||
* 6. If seconds is supplied use ToNumber(seconds); else use 0
|
||||
* 7. If ms is supplied use ToNumber(ms); else use 0
|
||||
* 8. If Result(1) is not NaN and 0 <= ToInteger(Result(1)) <= 99,
|
||||
* Result(8) is 1900+ToInteger(Result(1));
|
||||
* otherwise, Result(8) is Result(1)
|
||||
* 9. Compute MakeDay(Result(8), Result(2), Result(3))
|
||||
* 10. Compute MakeTime(Result(4), Result(5), Result(6), Result(7))
|
||||
* 11. Compute MakeDate(Result(9), Result(10))
|
||||
* 12. Set the [[Value]] property of the newly constructed object to
|
||||
* TimeClip(UTC(Result(11)))
|
||||
*/
|
||||
var r1 = Number(year);
|
||||
var r2 = Number(month);
|
||||
var r3 = ((date && arguments.length > 2) ? Number(date) : 1);
|
||||
var r4 = ((hours && arguments.length > 3) ? Number(hours) : 0);
|
||||
var r5 = ((minutes && arguments.length > 4) ? Number(minutes) : 0);
|
||||
var r6 = ((seconds && arguments.length > 5) ? Number(seconds) : 0);
|
||||
var r7 = ((ms && arguments.length > 6) ? Number(ms) : 0);
|
||||
|
||||
var r8 = r1;
|
||||
|
||||
if(!isNaN(r1) && (0 <= ToInteger(r1)) && (ToInteger(r1) <= 99))
|
||||
r8 = 1900+r1;
|
||||
|
||||
var r9 = MakeDay(r8, r2, r3);
|
||||
var r10 = MakeTime(r4, r5, r6, r7);
|
||||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**** Python code for initialize the above constants
|
||||
// We may want to replicate the following in JavaScript.
|
||||
// However, using JS date operations to generate parameters that are then used to
|
||||
// test those some date operations seems unsound. However, it isn't clear if there
|
||||
//is a good interoperable alternative.
|
||||
|
||||
# Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
# This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
def GetDaylightSavingsTimes():
|
||||
# Is the given floating-point time in DST?
|
||||
def IsDst(t):
|
||||
return time.localtime(t)[-1]
|
||||
# Binary search to find an interval between the two times no greater than
|
||||
# delta where DST switches, returning the midpoint.
|
||||
def FindBetween(start, end, delta):
|
||||
while end - start > delta:
|
||||
middle = (end + start) / 2
|
||||
if IsDst(middle) == IsDst(start):
|
||||
start = middle
|
||||
else:
|
||||
end = middle
|
||||
return (start + end) / 2
|
||||
now = time.time()
|
||||
one_month = (30 * 24 * 60 * 60)
|
||||
# First find a date with different daylight savings. To avoid corner cases
|
||||
# we try four months before and after today.
|
||||
after = now + 4 * one_month
|
||||
before = now - 4 * one_month
|
||||
if IsDst(now) == IsDst(before) and IsDst(now) == IsDst(after):
|
||||
logger.warning("Was unable to determine DST info.")
|
||||
return None
|
||||
# Determine when the change occurs between now and the date we just found
|
||||
# in a different DST.
|
||||
if IsDst(now) != IsDst(before):
|
||||
first = FindBetween(before, now, 1)
|
||||
else:
|
||||
first = FindBetween(now, after, 1)
|
||||
# Determine when the change occurs between three and nine months from the
|
||||
# first.
|
||||
second = FindBetween(first + 3 * one_month, first + 9 * one_month, 1)
|
||||
# Find out which switch is into and which if out of DST
|
||||
if IsDst(first - 1) and not IsDst(first + 1):
|
||||
start = second
|
||||
end = first
|
||||
else:
|
||||
start = first
|
||||
end = second
|
||||
return (start, end)
|
||||
|
||||
|
||||
def GetDaylightSavingsAttribs():
|
||||
times = GetDaylightSavingsTimes()
|
||||
if not times:
|
||||
return None
|
||||
(start, end) = times
|
||||
def DstMonth(t):
|
||||
return time.localtime(t)[1] - 1
|
||||
def DstHour(t):
|
||||
return time.localtime(t - 1)[3] + 1
|
||||
def DstSunday(t):
|
||||
if time.localtime(t)[2] > 15:
|
||||
return "'last'"
|
||||
else:
|
||||
return "'first'"
|
||||
def DstMinutes(t):
|
||||
return (time.localtime(t - 1)[4] + 1) % 60
|
||||
attribs = { }
|
||||
attribs['start_month'] = DstMonth(start)
|
||||
attribs['end_month'] = DstMonth(end)
|
||||
attribs['start_sunday'] = DstSunday(start)
|
||||
attribs['end_sunday'] = DstSunday(end)
|
||||
attribs['start_hour'] = DstHour(start)
|
||||
attribs['end_hour'] = DstHour(end)
|
||||
attribs['start_minutes'] = DstMinutes(start)
|
||||
attribs['end_minutes'] = DstMinutes(end)
|
||||
return attribs
|
||||
|
||||
*********/
|
|
@ -284,6 +284,624 @@ var NotEarlyErrorString = "NotEarlyError";
|
|||
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
|
||||
var NotEarlyError = new Error(NotEarlyErrorString);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function Test262Error(message) {
|
||||
if (message) this.message = message;
|
||||
}
|
||||
|
||||
Test262Error.prototype.toString = function () {
|
||||
return "Test262 Error: " + this.message;
|
||||
};
|
||||
|
||||
function testFailed(message) {
|
||||
throw new Test262Error(message);
|
||||
}
|
||||
|
||||
|
||||
function testPrint(message) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//adaptors for Test262 framework
|
||||
function $PRINT(message) {
|
||||
|
||||
}
|
||||
|
||||
function $INCLUDE(message) { }
|
||||
function $ERROR(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
function $FAIL(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Sputnik library definitions
|
||||
//Ultimately these should be namespaced some how and only made
|
||||
//available to tests that explicitly include them.
|
||||
//For now, we just define the globally
|
||||
|
||||
//math_precision.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function getPrecision(num) {
|
||||
//TODO: Create a table of prec's,
|
||||
// because using Math for testing Math isn't that correct.
|
||||
|
||||
log2num = Math.log(Math.abs(num)) / Math.LN2;
|
||||
pernum = Math.ceil(log2num);
|
||||
return (2 * Math.pow(2, -52 + pernum));
|
||||
//return(0);
|
||||
}
|
||||
|
||||
|
||||
//math_isequal.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var prec;
|
||||
function isEqual(num1, num2) {
|
||||
if ((num1 === Infinity) && (num2 === Infinity)) {
|
||||
return (true);
|
||||
}
|
||||
if ((num1 === -Infinity) && (num2 === -Infinity)) {
|
||||
return (true);
|
||||
}
|
||||
prec = getPrecision(Math.min(Math.abs(num1), Math.abs(num2)));
|
||||
return (Math.abs(num1 - num2) <= prec);
|
||||
//return(num1 === num2);
|
||||
}
|
||||
|
||||
//numeric_conversion.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function ToInteger(p) {
|
||||
x = Number(p);
|
||||
|
||||
if (isNaN(x)) {
|
||||
return +0;
|
||||
}
|
||||
|
||||
if ((x === +0)
|
||||
|| (x === -0)
|
||||
|| (x === Number.POSITIVE_INFINITY)
|
||||
|| (x === Number.NEGATIVE_INFINITY)) {
|
||||
return x;
|
||||
}
|
||||
|
||||
var sign = (x < 0) ? -1 : 1;
|
||||
|
||||
return (sign * Math.floor(Math.abs(x)));
|
||||
}
|
||||
|
||||
//Date_constants.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
|
||||
var msPerDay = 86400000;
|
||||
var msPerSecond = 1000;
|
||||
var msPerMinute = 60000;
|
||||
var msPerHour = 3600000;
|
||||
|
||||
var date_1899_end = -2208988800001;
|
||||
var date_1900_start = -2208988800000;
|
||||
var date_1969_end = -1;
|
||||
var date_1970_start = 0;
|
||||
var date_1999_end = 946684799999;
|
||||
var date_2000_start = 946684800000;
|
||||
var date_2099_end = 4102444799999;
|
||||
var date_2100_start = 4102444800000;
|
||||
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
var $LocalTZ,
|
||||
$DST_start_month,
|
||||
$DST_start_sunday,
|
||||
$DST_start_hour,
|
||||
$DST_start_minutes,
|
||||
$DST_end_month,
|
||||
$DST_end_sunday,
|
||||
$DST_end_hour,
|
||||
$DST_end_minutes;
|
||||
|
||||
(function () {
|
||||
/**
|
||||
* Finds the first date, starting from |start|, where |predicate|
|
||||
* holds.
|
||||
*/
|
||||
var findNearestDateBefore = function(start, predicate) {
|
||||
var current = start;
|
||||
var month = 1000 * 60 * 60 * 24 * 30;
|
||||
for (var step = month; step > 0; step = Math.floor(step / 3)) {
|
||||
if (!predicate(current)) {
|
||||
while (!predicate(current))
|
||||
current = new Date(current.getTime() + step);
|
||||
current = new Date(current.getTime() - step);
|
||||
}
|
||||
}
|
||||
while (!predicate(current)) {
|
||||
current = new Date(current.getTime() + 1);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
|
||||
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
|
||||
var juneOffset = juneDate.getTimezoneOffset();
|
||||
var decemberOffset = decemberDate.getTimezoneOffset();
|
||||
var isSouthernHemisphere = (juneOffset > decemberOffset);
|
||||
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
|
||||
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
|
||||
|
||||
var dstStart = findNearestDateBefore(winterTime, function (date) {
|
||||
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_start_month = dstStart.getMonth();
|
||||
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_start_hour = dstStart.getHours();
|
||||
$DST_start_minutes = dstStart.getMinutes();
|
||||
|
||||
var dstEnd = findNearestDateBefore(summerTime, function (date) {
|
||||
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_end_month = dstEnd.getMonth();
|
||||
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_end_hour = dstEnd.getHours();
|
||||
$DST_end_minutes = dstEnd.getMinutes();
|
||||
|
||||
return;
|
||||
})();
|
||||
|
||||
|
||||
//Date.library.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
}
|
||||
|
||||
function TimeWithinDay(t) {
|
||||
return t%msPerDay;
|
||||
}
|
||||
|
||||
//15.9.1.3 Year Number
|
||||
function DaysInYear(y){
|
||||
if(y%4 != 0) return 365;
|
||||
if(y%4 == 0 && y%100 != 0) return 366;
|
||||
if(y%100 == 0 && y%400 != 0) return 365;
|
||||
if(y%400 == 0) return 366;
|
||||
}
|
||||
|
||||
function DayFromYear(y) {
|
||||
return (365*(y-1970)
|
||||
+ Math.floor((y-1969)/4)
|
||||
- Math.floor((y-1901)/100)
|
||||
+ Math.floor((y-1601)/400));
|
||||
}
|
||||
|
||||
function TimeFromYear(y){
|
||||
return msPerDay*DayFromYear(y);
|
||||
}
|
||||
|
||||
function YearFromTime(t) {
|
||||
t = Number(t);
|
||||
var sign = ( t < 0 ) ? -1 : 1;
|
||||
var year = ( sign < 0 ) ? 1969 : 1970;
|
||||
|
||||
for(var time = 0;;year += sign){
|
||||
time = TimeFromYear(year);
|
||||
|
||||
if(sign > 0 && time > t){
|
||||
year -= sign;
|
||||
break;
|
||||
}
|
||||
else if(sign < 0 && time <= t){
|
||||
break;
|
||||
}
|
||||
};
|
||||
return year;
|
||||
}
|
||||
|
||||
function InLeapYear(t){
|
||||
if(DaysInYear(YearFromTime(t)) == 365)
|
||||
return 0;
|
||||
|
||||
if(DaysInYear(YearFromTime(t)) == 366)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function DayWithinYear(t) {
|
||||
return Day(t)-DayFromYear(YearFromTime(t));
|
||||
}
|
||||
|
||||
//15.9.1.4 Month Number
|
||||
function MonthFromTime(t){
|
||||
var day = DayWithinYear(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if((0 <= day) && (day < 31)) return 0;
|
||||
if((31 <= day) && (day < (59+leap))) return 1;
|
||||
if(((59+leap) <= day) && (day < (90+leap))) return 2;
|
||||
if(((90+leap) <= day) && (day < (120+leap))) return 3;
|
||||
if(((120+leap) <= day) && (day < (151+leap))) return 4;
|
||||
if(((151+leap) <= day) && (day < (181+leap))) return 5;
|
||||
if(((181+leap) <= day) && (day < (212+leap))) return 6;
|
||||
if(((212+leap) <= day) && (day < (243+leap))) return 7;
|
||||
if(((243+leap) <= day) && (day < (273+leap))) return 8;
|
||||
if(((273+leap) <= day) && (day < (304+leap))) return 9;
|
||||
if(((304+leap) <= day) && (day < (334+leap))) return 10;
|
||||
if(((334+leap) <= day) && (day < (365+leap))) return 11;
|
||||
}
|
||||
|
||||
//15.9.1.5 Date Number
|
||||
function DateFromTime(t) {
|
||||
var day = DayWithinYear(t);
|
||||
var month = MonthFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if(month == 0) return day+1;
|
||||
if(month == 1) return day-30;
|
||||
if(month == 2) return day-58-leap;
|
||||
if(month == 3) return day-89-leap;
|
||||
if(month == 4) return day-119-leap;
|
||||
if(month == 5) return day-150-leap;
|
||||
if(month == 6) return day-180-leap;
|
||||
if(month == 7) return day-211-leap;
|
||||
if(month == 8) return day-242-leap;
|
||||
if(month == 9) return day-272-leap;
|
||||
if(month == 10) return day-303-leap;
|
||||
if(month == 11) return day-333-leap;
|
||||
}
|
||||
|
||||
//15.9.1.6 Week Day
|
||||
function WeekDay(t) {
|
||||
var weekday = (Day(t)+4)%7;
|
||||
return (weekday < 0 ? 7+weekday : weekday);
|
||||
}
|
||||
|
||||
//15.9.1.9 Daylight Saving Time Adjustment
|
||||
$LocalTZ = (new Date()).getTimezoneOffset() / -60;
|
||||
if (DaylightSavingTA((new Date()).valueOf()) !== 0) {
|
||||
$LocalTZ -= 1;
|
||||
}
|
||||
var LocalTZA = $LocalTZ*msPerHour;
|
||||
|
||||
function DaysInMonth(m, leap) {
|
||||
m = m%12;
|
||||
|
||||
//April, June, Sept, Nov
|
||||
if(m == 3 || m == 5 || m == 8 || m == 10 ) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
//Jan, March, May, July, Aug, Oct, Dec
|
||||
if(m == 0 || m == 2 || m == 4 || m == 6 || m == 7 || m == 9 || m == 11){
|
||||
return 31;
|
||||
}
|
||||
|
||||
//Feb
|
||||
return 28+leap;
|
||||
}
|
||||
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
|
||||
if (count==='"first"') {
|
||||
for (var d=1; d <= DaysInMonth(m, InLeapYear(t)); d++) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
} else if(count==='"last"') {
|
||||
for (var d=DaysInMonth(m, InLeapYear(t)); d>0; d--) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("Unsupported 'count' arg:" + count);
|
||||
}
|
||||
/*
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
var day = 0;
|
||||
|
||||
if(m >= 1) day += DaysInMonth(0, leap);
|
||||
if(m >= 2) day += DaysInMonth(1, leap);
|
||||
if(m >= 3) day += DaysInMonth(2, leap);
|
||||
if(m >= 4) day += DaysInMonth(3, leap);
|
||||
if(m >= 5) day += DaysInMonth(4, leap);
|
||||
if(m >= 6) day += DaysInMonth(5, leap);
|
||||
if(m >= 7) day += DaysInMonth(6, leap);
|
||||
if(m >= 8) day += DaysInMonth(7, leap);
|
||||
if(m >= 9) day += DaysInMonth(8, leap);
|
||||
if(m >= 10) day += DaysInMonth(9, leap);
|
||||
if(m >= 11) day += DaysInMonth(10, leap);
|
||||
|
||||
var month_start = TimeFromYear(year)+day*msPerDay;
|
||||
var sunday = 0;
|
||||
|
||||
if(count === "last"){
|
||||
for(var last_sunday = month_start+DaysInMonth(m, leap)*msPerDay;
|
||||
WeekDay(last_sunday)>0;
|
||||
last_sunday -= msPerDay
|
||||
){};
|
||||
sunday = last_sunday;
|
||||
}
|
||||
else {
|
||||
for(var first_sunday = month_start;
|
||||
WeekDay(first_sunday)>0;
|
||||
first_sunday += msPerDay
|
||||
){};
|
||||
sunday = first_sunday+7*msPerDay*(count-1);
|
||||
}
|
||||
|
||||
return sunday;
|
||||
}*/
|
||||
|
||||
function DaylightSavingTA(t) {
|
||||
// t = t-LocalTZA;
|
||||
|
||||
var DST_start = GetSundayInMonth(t, $DST_start_month, $DST_start_sunday) +
|
||||
$DST_start_hour*msPerHour +
|
||||
$DST_start_minutes*msPerMinute;
|
||||
|
||||
var k = new Date(DST_start);
|
||||
|
||||
var DST_end = GetSundayInMonth(t, $DST_end_month, $DST_end_sunday) +
|
||||
$DST_end_hour*msPerHour +
|
||||
$DST_end_minutes*msPerMinute;
|
||||
|
||||
if ( t >= DST_start && t < DST_end ) {
|
||||
return msPerHour;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//15.9.1.9 Local Time
|
||||
function LocalTime(t){
|
||||
return t+LocalTZA+DaylightSavingTA(t);
|
||||
}
|
||||
|
||||
function UTC(t) {
|
||||
return t-LocalTZA-DaylightSavingTA(t-LocalTZA);
|
||||
}
|
||||
|
||||
//15.9.1.10 Hours, Minutes, Second, and Milliseconds
|
||||
function HourFromTime(t){
|
||||
return Math.floor(t/msPerHour)%HoursPerDay;
|
||||
}
|
||||
|
||||
function MinFromTime(t){
|
||||
return Math.floor(t/msPerMinute)%MinutesPerHour;
|
||||
}
|
||||
|
||||
function SecFromTime(t){
|
||||
return Math.floor(t/msPerSecond)%SecondsPerMinute;
|
||||
}
|
||||
|
||||
function msFromTime(t){
|
||||
return t%msPerSecond;
|
||||
}
|
||||
|
||||
//15.9.1.11 MakeTime (hour, min, sec, ms)
|
||||
function MakeTime(hour, min, sec, ms){
|
||||
if ( !isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
hour = ToInteger(hour);
|
||||
min = ToInteger(min);
|
||||
sec = ToInteger(sec);
|
||||
ms = ToInteger(ms);
|
||||
|
||||
return ((hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms);
|
||||
}
|
||||
|
||||
//15.9.1.12 MakeDay (year, month, date)
|
||||
function MakeDay(year, month, date) {
|
||||
if ( !isFinite(year) || !isFinite(month) || !isFinite(date)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
year = ToInteger(year);
|
||||
month = ToInteger(month);
|
||||
date = ToInteger(date );
|
||||
|
||||
var result5 = year + Math.floor(month/12);
|
||||
var result6 = month%12;
|
||||
|
||||
var sign = ( year < 1970 ) ? -1 : 1;
|
||||
var t = ( year < 1970 ) ? 1 : 0;
|
||||
var y = ( year < 1970 ) ? 1969 : 1970;
|
||||
|
||||
if( sign == -1 ){
|
||||
for ( y = 1969; y >= year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
} else {
|
||||
for ( y = 1970 ; y < year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
}
|
||||
|
||||
var leap = 0;
|
||||
for ( var m = 0; m < month; m++ ) {
|
||||
//if year is changed, than we need to recalculate leep
|
||||
leap = InLeapYear(t);
|
||||
t += DaysInMonth(m, leap)*msPerDay;
|
||||
}
|
||||
|
||||
if ( YearFromTime(t) != result5 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( MonthFromTime(t) != result6 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( DateFromTime(t) != 1 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return Day(t)+date-1;
|
||||
}
|
||||
|
||||
//15.9.1.13 MakeDate (day, time)
|
||||
function MakeDate( day, time ) {
|
||||
if(!isFinite(day) || !isFinite(time)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return day*msPerDay+time;
|
||||
}
|
||||
|
||||
//15.9.1.14 TimeClip (time)
|
||||
function TimeClip(time) {
|
||||
if(!isFinite(time) || Math.abs(time) > 8.64e15){
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return ToInteger(time);
|
||||
}
|
||||
|
||||
//Test Functions
|
||||
function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
||||
/*
|
||||
* 1. Call ToNumber(year)
|
||||
* 2. Call ToNumber(month)
|
||||
* 3. If date is supplied use ToNumber(date); else use 1
|
||||
* 4. If hours is supplied use ToNumber(hours); else use 0
|
||||
* 5. If minutes is supplied use ToNumber(minutes); else use 0
|
||||
* 6. If seconds is supplied use ToNumber(seconds); else use 0
|
||||
* 7. If ms is supplied use ToNumber(ms); else use 0
|
||||
* 8. If Result(1) is not NaN and 0 <= ToInteger(Result(1)) <= 99, Result(8) is
|
||||
* 1900+ToInteger(Result(1)); otherwise, Result(8) is Result(1)
|
||||
* 9. Compute MakeDay(Result(8), Result(2), Result(3))
|
||||
* 10. Compute MakeTime(Result(4), Result(5), Result(6), Result(7))
|
||||
* 11. Compute MakeDate(Result(9), Result(10))
|
||||
* 12. Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(11)))
|
||||
*/
|
||||
var r1 = Number(year);
|
||||
var r2 = Number(month);
|
||||
var r3 = ((date && arguments.length > 2) ? Number(date) : 1);
|
||||
var r4 = ((hours && arguments.length > 3) ? Number(hours) : 0);
|
||||
var r5 = ((minutes && arguments.length > 4) ? Number(minutes) : 0);
|
||||
var r6 = ((seconds && arguments.length > 5) ? Number(seconds) : 0);
|
||||
var r7 = ((ms && arguments.length > 6) ? Number(ms) : 0);
|
||||
|
||||
var r8 = r1;
|
||||
|
||||
if(!isNaN(r1) && (0 <= ToInteger(r1)) && (ToInteger(r1) <= 99))
|
||||
r8 = 1900+r1;
|
||||
|
||||
var r9 = MakeDay(r8, r2, r3);
|
||||
var r10 = MakeTime(r4, r5, r6, r7);
|
||||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**** Python code for initialize the above constants
|
||||
// We may want to replicate the following in JavaScript.
|
||||
// However, using JS date operations to generate parameters that are then used to
|
||||
// test those some date operations seems unsound. However, it isn't clear if there
|
||||
//is a good interoperable alternative.
|
||||
|
||||
# Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
# This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
def GetDaylightSavingsTimes():
|
||||
# Is the given floating-point time in DST?
|
||||
def IsDst(t):
|
||||
return time.localtime(t)[-1]
|
||||
# Binary search to find an interval between the two times no greater than
|
||||
# delta where DST switches, returning the midpoint.
|
||||
def FindBetween(start, end, delta):
|
||||
while end - start > delta:
|
||||
middle = (end + start) / 2
|
||||
if IsDst(middle) == IsDst(start):
|
||||
start = middle
|
||||
else:
|
||||
end = middle
|
||||
return (start + end) / 2
|
||||
now = time.time()
|
||||
one_month = (30 * 24 * 60 * 60)
|
||||
# First find a date with different daylight savings. To avoid corner cases
|
||||
# we try four months before and after today.
|
||||
after = now + 4 * one_month
|
||||
before = now - 4 * one_month
|
||||
if IsDst(now) == IsDst(before) and IsDst(now) == IsDst(after):
|
||||
logger.warning("Was unable to determine DST info.")
|
||||
return None
|
||||
# Determine when the change occurs between now and the date we just found
|
||||
# in a different DST.
|
||||
if IsDst(now) != IsDst(before):
|
||||
first = FindBetween(before, now, 1)
|
||||
else:
|
||||
first = FindBetween(now, after, 1)
|
||||
# Determine when the change occurs between three and nine months from the
|
||||
# first.
|
||||
second = FindBetween(first + 3 * one_month, first + 9 * one_month, 1)
|
||||
# Find out which switch is into and which if out of DST
|
||||
if IsDst(first - 1) and not IsDst(first + 1):
|
||||
start = second
|
||||
end = first
|
||||
else:
|
||||
start = first
|
||||
end = second
|
||||
return (start, end)
|
||||
|
||||
|
||||
def GetDaylightSavingsAttribs():
|
||||
times = GetDaylightSavingsTimes()
|
||||
if not times:
|
||||
return None
|
||||
(start, end) = times
|
||||
def DstMonth(t):
|
||||
return time.localtime(t)[1] - 1
|
||||
def DstHour(t):
|
||||
return time.localtime(t - 1)[3] + 1
|
||||
def DstSunday(t):
|
||||
if time.localtime(t)[2] > 15:
|
||||
return "'last'"
|
||||
else:
|
||||
return "'first'"
|
||||
def DstMinutes(t):
|
||||
return (time.localtime(t - 1)[4] + 1) % 60
|
||||
attribs = { }
|
||||
attribs['start_month'] = DstMonth(start)
|
||||
attribs['end_month'] = DstMonth(end)
|
||||
attribs['start_sunday'] = DstSunday(start)
|
||||
attribs['end_sunday'] = DstSunday(end)
|
||||
attribs['start_hour'] = DstHour(start)
|
||||
attribs['end_hour'] = DstHour(end)
|
||||
attribs['start_minutes'] = DstMinutes(start)
|
||||
attribs['end_minutes'] = DstMinutes(end)
|
||||
return attribs
|
||||
|
||||
*********/
|
||||
|
||||
//--Test case registration-----------------------------------------------------
|
||||
function runTestCase(testcase) {
|
||||
if (testcase() !== true) {
|
||||
|
|
|
@ -127,11 +127,6 @@ function BrowserRunner() {
|
|||
//TODO: these should be moved to sta.js
|
||||
var includes = code.match(/\$INCLUDE\(([^\)]+)\)/g), // find all of the $INCLUDE statements
|
||||
include;
|
||||
iwin.Test262Error = Test262Error;
|
||||
iwin.$ERROR = $ERROR;
|
||||
iwin.$FAIL = $FAIL;
|
||||
iwin.$PRINT = function () { };
|
||||
iwin.$INCLUDE = function () { };
|
||||
|
||||
if (includes !== null) {
|
||||
// We have some includes, so loop through each include and
|
||||
|
|
|
@ -47,6 +47,8 @@ __parser.add_argument('version', action='store',
|
|||
help='Version of the test suite.')
|
||||
__parser.add_argument('--type', action='store', default='test262',
|
||||
help='Type of test case runner to generate.')
|
||||
__parser.add_argument('--console', action='store_true', default=False,
|
||||
help='Type of test case runner to generate.')
|
||||
ARGS = __parser.parse_args()
|
||||
|
||||
if not os.path.exists(EXCLUDED_FILENAME):
|
||||
|
@ -92,6 +94,21 @@ if not hasattr(ARGS, "version"):
|
|||
sys.exit(1)
|
||||
|
||||
#--Helpers--------------------------------------------------------------------#
|
||||
def createDepDirs(dirName):
|
||||
#base case
|
||||
if dirName==os.path.dirname(dirName):
|
||||
if not os.path.exists(dirName):
|
||||
os.mkdir(dirName)
|
||||
else:
|
||||
if not os.path.exists(dirName):
|
||||
createDepDirs(os.path.dirname(dirName))
|
||||
os.mkdir(dirName)
|
||||
|
||||
def test262PathToConsoleFile(path):
|
||||
stuff = os.path.join(TEST262_CONSOLE_CASES_DIR, path.replace("/", os.path.sep))
|
||||
createDepDirs(os.path.dirname(stuff))
|
||||
return stuff
|
||||
|
||||
def getJSCount(dirName):
|
||||
'''
|
||||
Returns the total number of *.js files (recursively) under a given
|
||||
|
@ -210,9 +227,7 @@ for chapter in TEST_SUITE_SECTIONS:
|
|||
if EXCLUDE_LIST.count(testName)==0:
|
||||
# dictionary for each test
|
||||
testDict = {}
|
||||
#TODO
|
||||
#testDict["id"] = testName
|
||||
testDict["path"] = testPath.replace("/ietestcenter", "").replace("/sputnik_converted", "")
|
||||
testDict["path"] = testPath
|
||||
|
||||
tempFile = open(test, "r")
|
||||
scriptCode = tempFile.readlines()
|
||||
|
@ -233,10 +248,10 @@ for chapter in TEST_SUITE_SECTIONS:
|
|||
if scriptCodeContent=="":
|
||||
print "WARNING (" + test + "): unable to strip comments/license header/etc."
|
||||
scriptCodeContent = "".join(scriptCode)
|
||||
scriptCodeContent = base64.b64encode(scriptCodeContent)
|
||||
scriptCodeContentB64 = base64.b64encode(scriptCodeContent)
|
||||
|
||||
#add the test encoded code node to our test dictionary
|
||||
testDict["code"] = scriptCodeContent
|
||||
testDict["code"] = scriptCodeContentB64
|
||||
#now close the dictionary for the test
|
||||
|
||||
#now get the metadata added.
|
||||
|
@ -248,6 +263,12 @@ for chapter in TEST_SUITE_SECTIONS:
|
|||
|
||||
#this adds the test to our tests array
|
||||
tests.append(testDict)
|
||||
|
||||
if ARGS.console:
|
||||
with open(test262PathToConsoleFile(testDict["path"]), "w") as fConsole:
|
||||
fConsole.write(scriptCodeContent)
|
||||
with open(test262PathToConsoleFile(testDict["path"][:-3] + "_metadata.js"), "w") as fConsoleMeta:
|
||||
fConsoleMeta.write("testDescrip = " + str(testDict))
|
||||
testCount += 1
|
||||
else:
|
||||
print "Excluded:", testName
|
||||
|
@ -295,13 +316,19 @@ print ""
|
|||
print "Deploying test harness files to 'TEST262_WEB_HARNESS_DIR'..."
|
||||
if TEST262_HARNESS_DIR!=TEST262_WEB_HARNESS_DIR:
|
||||
for filename in [x for x in os.listdir(TEST262_HARNESS_DIR) if x.endswith(".js")]:
|
||||
toFilename = os.path.join(TEST262_WEB_HARNESS_DIR, filename)
|
||||
fileExists = os.path.exists(toFilename)
|
||||
if fileExists:
|
||||
SC_HELPER.edit(toFilename)
|
||||
shutil.copy(os.path.join(TEST262_HARNESS_DIR, filename),
|
||||
toFilename)
|
||||
if not fileExists:
|
||||
SC_HELPER.add(toFilename)
|
||||
toFilenameList = [ os.path.join(TEST262_WEB_HARNESS_DIR, filename)]
|
||||
if ARGS.console:
|
||||
toFilenameList.append(os.path.join(TEST262_CONSOLE_HARNESS_DIR, filename))
|
||||
|
||||
for toFilename in toFilenameList:
|
||||
if not os.path.exists(os.path.dirname(toFilename)):
|
||||
os.mkdir(os.path.dirname(toFilename))
|
||||
fileExists = os.path.exists(toFilename)
|
||||
if fileExists:
|
||||
SC_HELPER.edit(toFilename)
|
||||
shutil.copy(os.path.join(TEST262_HARNESS_DIR, filename),
|
||||
toFilename)
|
||||
if not fileExists:
|
||||
SC_HELPER.add(toFilename)
|
||||
|
||||
print "Done."
|
||||
|
|
|
@ -28,6 +28,7 @@ import re
|
|||
MAX_CASES_PER_JSON = 1000
|
||||
|
||||
WEBSITE_SHORT_NAME = "website"
|
||||
CONSOLE_SHORT_NAME = "console"
|
||||
|
||||
#Path to the root of the Hg repository (relative to this file's location)
|
||||
TEST262_ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")
|
||||
|
@ -42,9 +43,11 @@ TEST262_HARNESS_DIR = os.path.join(TEST262_ROOT, "test", "harness")
|
|||
|
||||
#Directory full of website test cases (ported over from TEST262_CASES_DIR)
|
||||
TEST262_WEB_CASES_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, "json")
|
||||
TEST262_CONSOLE_CASES_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME)
|
||||
|
||||
#Directory containing the website's test harness (ported over from TEST262_HARNESS_DIR)
|
||||
TEST262_WEB_HARNESS_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, "harness")
|
||||
TEST262_CONSOLE_HARNESS_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME, "harness")
|
||||
|
||||
#Path to the ported test case files on the actual website as opposed to the Hg layout
|
||||
WEBSITE_CASES_PATH = "json/"
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
<script type="text/javascript" src="harness/jqueryprogressbar.js"></script>
|
||||
<script type="text/javascript" src="harness/helper.js"></script>
|
||||
<script type="text/javascript" src="harness/jquery.base64.js"></script>
|
||||
<script type="text/javascript" src="harness/sputnikLib.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
//To support all the browsers
|
||||
$(window).resize(ResizeLoadIndicator);
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
<script type="text/javascript" src="harness/jqueryprogressbar.js"></script>
|
||||
<script type="text/javascript" src="harness/helper.js"></script>
|
||||
<script type="text/javascript" src="harness/jquery.base64.js"></script>
|
||||
<script type="text/javascript" src="harness/sputnikLib.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
//To support all the browsers
|
||||
$(window).resize(ResizeLoadIndicator);
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
|
||||
var msPerDay = 86400000;
|
||||
var msPerSecond = 1000;
|
||||
var msPerMinute = 60000;
|
||||
var msPerHour = 3600000;
|
||||
|
||||
var date_1899_end = -2208988800001;
|
||||
var date_1900_start = -2208988800000;
|
||||
var date_1969_end = -1;
|
||||
var date_1970_start = 0;
|
||||
var date_1999_end = 946684799999;
|
||||
var date_2000_start = 946684800000;
|
||||
var date_2099_end = 4102444799999;
|
||||
var date_2100_start = 4102444800000;
|
|
@ -1,411 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
var $LocalTZ,
|
||||
$DST_start_month,
|
||||
$DST_start_sunday,
|
||||
$DST_start_hour,
|
||||
$DST_start_minutes,
|
||||
$DST_end_month,
|
||||
$DST_end_sunday,
|
||||
$DST_end_hour,
|
||||
$DST_end_minutes;
|
||||
|
||||
(function () {
|
||||
/**
|
||||
* Finds the first date, starting from |start|, where |predicate|
|
||||
* holds.
|
||||
*/
|
||||
var findNearestDateBefore = function(start, predicate) {
|
||||
var current = start;
|
||||
var month = 1000 * 60 * 60 * 24 * 30;
|
||||
for (var step = month; step > 0; step = Math.floor(step / 3)) {
|
||||
if (!predicate(current)) {
|
||||
while (!predicate(current))
|
||||
current = new Date(current.getTime() + step);
|
||||
current = new Date(current.getTime() - step);
|
||||
}
|
||||
}
|
||||
while (!predicate(current)) {
|
||||
current = new Date(current.getTime() + 1);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
|
||||
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
|
||||
var juneOffset = juneDate.getTimezoneOffset();
|
||||
var decemberOffset = decemberDate.getTimezoneOffset();
|
||||
var isSouthernHemisphere = (juneOffset > decemberOffset);
|
||||
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
|
||||
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
|
||||
|
||||
var dstStart = findNearestDateBefore(winterTime, function (date) {
|
||||
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_start_month = dstStart.getMonth();
|
||||
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_start_hour = dstStart.getHours();
|
||||
$DST_start_minutes = dstStart.getMinutes();
|
||||
|
||||
var dstEnd = findNearestDateBefore(summerTime, function (date) {
|
||||
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_end_month = dstEnd.getMonth();
|
||||
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_end_hour = dstEnd.getHours();
|
||||
$DST_end_minutes = dstEnd.getMinutes();
|
||||
|
||||
return;
|
||||
})();
|
||||
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
}
|
||||
|
||||
function TimeWithinDay(t) {
|
||||
return t%msPerDay;
|
||||
}
|
||||
|
||||
//15.9.1.3 Year Number
|
||||
function DaysInYear(y){
|
||||
if(y%4 != 0) return 365;
|
||||
if(y%4 == 0 && y%100 != 0) return 366;
|
||||
if(y%100 == 0 && y%400 != 0) return 365;
|
||||
if(y%400 == 0) return 366;
|
||||
}
|
||||
|
||||
function DayFromYear(y) {
|
||||
return (365*(y-1970)
|
||||
+ Math.floor((y-1969)/4)
|
||||
- Math.floor((y-1901)/100)
|
||||
+ Math.floor((y-1601)/400));
|
||||
}
|
||||
|
||||
function TimeFromYear(y){
|
||||
return msPerDay*DayFromYear(y);
|
||||
}
|
||||
|
||||
function YearFromTime(t) {
|
||||
t = Number(t);
|
||||
var sign = ( t < 0 ) ? -1 : 1;
|
||||
var year = ( sign < 0 ) ? 1969 : 1970;
|
||||
|
||||
for(var time = 0;;year += sign){
|
||||
time = TimeFromYear(year);
|
||||
|
||||
if(sign > 0 && time > t){
|
||||
year -= sign;
|
||||
break;
|
||||
}
|
||||
else if(sign < 0 && time <= t){
|
||||
break;
|
||||
}
|
||||
};
|
||||
return year;
|
||||
}
|
||||
|
||||
function InLeapYear(t){
|
||||
if(DaysInYear(YearFromTime(t)) == 365)
|
||||
return 0;
|
||||
|
||||
if(DaysInYear(YearFromTime(t)) == 366)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function DayWithinYear(t) {
|
||||
return Day(t)-DayFromYear(YearFromTime(t));
|
||||
}
|
||||
|
||||
//15.9.1.4 Month Number
|
||||
function MonthFromTime(t){
|
||||
var day = DayWithinYear(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if((0 <= day) && (day < 31)) return 0;
|
||||
if((31 <= day) && (day < (59+leap))) return 1;
|
||||
if(((59+leap) <= day) && (day < (90+leap))) return 2;
|
||||
if(((90+leap) <= day) && (day < (120+leap))) return 3;
|
||||
if(((120+leap) <= day) && (day < (151+leap))) return 4;
|
||||
if(((151+leap) <= day) && (day < (181+leap))) return 5;
|
||||
if(((181+leap) <= day) && (day < (212+leap))) return 6;
|
||||
if(((212+leap) <= day) && (day < (243+leap))) return 7;
|
||||
if(((243+leap) <= day) && (day < (273+leap))) return 8;
|
||||
if(((273+leap) <= day) && (day < (304+leap))) return 9;
|
||||
if(((304+leap) <= day) && (day < (334+leap))) return 10;
|
||||
if(((334+leap) <= day) && (day < (365+leap))) return 11;
|
||||
}
|
||||
|
||||
//15.9.1.5 Date Number
|
||||
function DateFromTime(t) {
|
||||
var day = DayWithinYear(t);
|
||||
var month = MonthFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if(month == 0) return day+1;
|
||||
if(month == 1) return day-30;
|
||||
if(month == 2) return day-58-leap;
|
||||
if(month == 3) return day-89-leap;
|
||||
if(month == 4) return day-119-leap;
|
||||
if(month == 5) return day-150-leap;
|
||||
if(month == 6) return day-180-leap;
|
||||
if(month == 7) return day-211-leap;
|
||||
if(month == 8) return day-242-leap;
|
||||
if(month == 9) return day-272-leap;
|
||||
if(month == 10) return day-303-leap;
|
||||
if(month == 11) return day-333-leap;
|
||||
}
|
||||
|
||||
//15.9.1.6 Week Day
|
||||
function WeekDay(t) {
|
||||
var weekday = (Day(t)+4)%7;
|
||||
return (weekday < 0 ? 7+weekday : weekday);
|
||||
}
|
||||
|
||||
//15.9.1.9 Daylight Saving Time Adjustment
|
||||
$LocalTZ = (new Date()).getTimezoneOffset() / -60;
|
||||
if (DaylightSavingTA((new Date()).valueOf()) !== 0) {
|
||||
$LocalTZ -= 1;
|
||||
}
|
||||
var LocalTZA = $LocalTZ*msPerHour;
|
||||
|
||||
function DaysInMonth(m, leap) {
|
||||
m = m%12;
|
||||
|
||||
//April, June, Sept, Nov
|
||||
if(m == 3 || m == 5 || m == 8 || m == 10 ) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
//Jan, March, May, July, Aug, Oct, Dec
|
||||
if(m == 0 || m == 2 || m == 4 || m == 6 || m == 7 || m == 9 || m == 11){
|
||||
return 31;
|
||||
}
|
||||
|
||||
//Feb
|
||||
return 28+leap;
|
||||
}
|
||||
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
|
||||
if (count==='"first"') {
|
||||
for (var d=1; d <= DaysInMonth(m, InLeapYear(t)); d++) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
} else if(count==='"last"') {
|
||||
for (var d=DaysInMonth(m, InLeapYear(t)); d>0; d--) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("Unsupported 'count' arg:" + count);
|
||||
}
|
||||
/*
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
var day = 0;
|
||||
|
||||
if(m >= 1) day += DaysInMonth(0, leap);
|
||||
if(m >= 2) day += DaysInMonth(1, leap);
|
||||
if(m >= 3) day += DaysInMonth(2, leap);
|
||||
if(m >= 4) day += DaysInMonth(3, leap);
|
||||
if(m >= 5) day += DaysInMonth(4, leap);
|
||||
if(m >= 6) day += DaysInMonth(5, leap);
|
||||
if(m >= 7) day += DaysInMonth(6, leap);
|
||||
if(m >= 8) day += DaysInMonth(7, leap);
|
||||
if(m >= 9) day += DaysInMonth(8, leap);
|
||||
if(m >= 10) day += DaysInMonth(9, leap);
|
||||
if(m >= 11) day += DaysInMonth(10, leap);
|
||||
|
||||
var month_start = TimeFromYear(year)+day*msPerDay;
|
||||
var sunday = 0;
|
||||
|
||||
if(count === "last"){
|
||||
for(var last_sunday = month_start+DaysInMonth(m, leap)*msPerDay;
|
||||
WeekDay(last_sunday)>0;
|
||||
last_sunday -= msPerDay
|
||||
){};
|
||||
sunday = last_sunday;
|
||||
}
|
||||
else {
|
||||
for(var first_sunday = month_start;
|
||||
WeekDay(first_sunday)>0;
|
||||
first_sunday += msPerDay
|
||||
){};
|
||||
sunday = first_sunday+7*msPerDay*(count-1);
|
||||
}
|
||||
|
||||
return sunday;
|
||||
}*/
|
||||
|
||||
function DaylightSavingTA(t) {
|
||||
// t = t-LocalTZA;
|
||||
|
||||
var DST_start = GetSundayInMonth(t, $DST_start_month, $DST_start_sunday) +
|
||||
$DST_start_hour*msPerHour +
|
||||
$DST_start_minutes*msPerMinute;
|
||||
|
||||
var k = new Date(DST_start);
|
||||
|
||||
var DST_end = GetSundayInMonth(t, $DST_end_month, $DST_end_sunday) +
|
||||
$DST_end_hour*msPerHour +
|
||||
$DST_end_minutes*msPerMinute;
|
||||
|
||||
if ( t >= DST_start && t < DST_end ) {
|
||||
return msPerHour;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//15.9.1.9 Local Time
|
||||
function LocalTime(t){
|
||||
return t+LocalTZA+DaylightSavingTA(t);
|
||||
}
|
||||
|
||||
function UTC(t) {
|
||||
return t-LocalTZA-DaylightSavingTA(t-LocalTZA);
|
||||
}
|
||||
|
||||
//15.9.1.10 Hours, Minutes, Second, and Milliseconds
|
||||
function HourFromTime(t){
|
||||
return Math.floor(t/msPerHour)%HoursPerDay;
|
||||
}
|
||||
|
||||
function MinFromTime(t){
|
||||
return Math.floor(t/msPerMinute)%MinutesPerHour;
|
||||
}
|
||||
|
||||
function SecFromTime(t){
|
||||
return Math.floor(t/msPerSecond)%SecondsPerMinute;
|
||||
}
|
||||
|
||||
function msFromTime(t){
|
||||
return t%msPerSecond;
|
||||
}
|
||||
|
||||
//15.9.1.11 MakeTime (hour, min, sec, ms)
|
||||
function MakeTime(hour, min, sec, ms){
|
||||
if ( !isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
hour = ToInteger(hour);
|
||||
min = ToInteger(min);
|
||||
sec = ToInteger(sec);
|
||||
ms = ToInteger(ms);
|
||||
|
||||
return ((hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms);
|
||||
}
|
||||
|
||||
//15.9.1.12 MakeDay (year, month, date)
|
||||
function MakeDay(year, month, date) {
|
||||
if ( !isFinite(year) || !isFinite(month) || !isFinite(date)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
year = ToInteger(year);
|
||||
month = ToInteger(month);
|
||||
date = ToInteger(date );
|
||||
|
||||
var result5 = year + Math.floor(month/12);
|
||||
var result6 = month%12;
|
||||
|
||||
var sign = ( year < 1970 ) ? -1 : 1;
|
||||
var t = ( year < 1970 ) ? 1 : 0;
|
||||
var y = ( year < 1970 ) ? 1969 : 1970;
|
||||
|
||||
if( sign == -1 ){
|
||||
for ( y = 1969; y >= year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
} else {
|
||||
for ( y = 1970 ; y < year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
}
|
||||
|
||||
var leap = 0;
|
||||
for ( var m = 0; m < month; m++ ) {
|
||||
//if year is changed, than we need to recalculate leep
|
||||
leap = InLeapYear(t);
|
||||
t += DaysInMonth(m, leap)*msPerDay;
|
||||
}
|
||||
|
||||
if ( YearFromTime(t) != result5 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( MonthFromTime(t) != result6 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( DateFromTime(t) != 1 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return Day(t)+date-1;
|
||||
}
|
||||
|
||||
//15.9.1.13 MakeDate (day, time)
|
||||
function MakeDate( day, time ) {
|
||||
if(!isFinite(day) || !isFinite(time)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return day*msPerDay+time;
|
||||
}
|
||||
|
||||
//15.9.1.14 TimeClip (time)
|
||||
function TimeClip(time) {
|
||||
if(!isFinite(time) || Math.abs(time) > 8.64e15){
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return ToInteger(time);
|
||||
}
|
||||
|
||||
//Test Functions
|
||||
function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
||||
/*
|
||||
* 1. Call ToNumber(year)
|
||||
* 2. Call ToNumber(month)
|
||||
* 3. If date is supplied use ToNumber(date); else use 1
|
||||
* 4. If hours is supplied use ToNumber(hours); else use 0
|
||||
* 5. If minutes is supplied use ToNumber(minutes); else use 0
|
||||
* 6. If seconds is supplied use ToNumber(seconds); else use 0
|
||||
* 7. If ms is supplied use ToNumber(ms); else use 0
|
||||
* 8. If Result(1) is not NaN and 0 <= ToInteger(Result(1)) <= 99, Result(8) is
|
||||
* 1900+ToInteger(Result(1)); otherwise, Result(8) is Result(1)
|
||||
* 9. Compute MakeDay(Result(8), Result(2), Result(3))
|
||||
* 10. Compute MakeTime(Result(4), Result(5), Result(6), Result(7))
|
||||
* 11. Compute MakeDate(Result(9), Result(10))
|
||||
* 12. Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(11)))
|
||||
*/
|
||||
var r1 = Number(year);
|
||||
var r2 = Number(month);
|
||||
var r3 = ((date && arguments.length > 2) ? Number(date) : 1);
|
||||
var r4 = ((hours && arguments.length > 3) ? Number(hours) : 0);
|
||||
var r5 = ((minutes && arguments.length > 4) ? Number(minutes) : 0);
|
||||
var r6 = ((seconds && arguments.length > 5) ? Number(seconds) : 0);
|
||||
var r7 = ((ms && arguments.length > 6) ? Number(ms) : 0);
|
||||
|
||||
var r8 = r1;
|
||||
|
||||
if(!isNaN(r1) && (0 <= ToInteger(r1)) && (ToInteger(r1) <= 99))
|
||||
r8 = 1900+r1;
|
||||
|
||||
var r9 = MakeDay(r8, r2, r3);
|
||||
var r10 = MakeTime(r4, r5, r6, r7);
|
||||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/// Copyright (c) 2011 Microsoft Corporation
|
||||
///
|
||||
/// Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
/// that the following conditions are met:
|
||||
/// * Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
/// the following disclaimer.
|
||||
/// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
/// the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
/// * Neither the name of Microsoft nor the names of its contributors may be used to
|
||||
/// endorse or promote products derived from this software without specific prior written permission.
|
||||
///
|
||||
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
/// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
/// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
/// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
/// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
/// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
/// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
function testRun(id, path, description, codeString, result, error) {
|
||||
if (result!=="pass") {
|
||||
throw new Error("Test '" + path + "'failed: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
function testFinished() {
|
||||
//no-op
|
||||
}
|
|
@ -19,9 +19,10 @@
|
|||
/// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//Error Detector
|
||||
|
||||
window.onerror = function(errorMsg, url, lineNumber) {
|
||||
window.iframeError = errorMsg;
|
||||
if (this.window!==undefined) { //for console support
|
||||
window.onerror = function(errorMsg, url, lineNumber) {
|
||||
window.iframeError = errorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
//This doesn't work with early errors in current versions of Opera
|
||||
|
|
|
@ -22,18 +22,18 @@
|
|||
|
||||
//An exception is expected
|
||||
if (testDescrip.negative !== undefined) {
|
||||
//TODO - come up with a generic way of catching the error type from window.onerror
|
||||
//TODO - come up with a generic way of catching the error type from this.onerror
|
||||
testDescrip.negative = testDescrip.negative === "NotEarlyError" ?
|
||||
testDescrip.negative : (testDescrip.negative === "^((?!NotEarlyError).)*$" ?
|
||||
testDescrip.negative : ".");
|
||||
if (window.iframeError === undefined) { //no exception was thrown
|
||||
if (this.iframeError === undefined) { //no exception was thrown
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'fail',
|
||||
Error('No exception was thrown; expected an error "message" property matching the regular expression "' + testDescrip.negative + '".'));
|
||||
} else if (!(new RegExp(testDescrip.negative, "i").test(window.iframeError))) { //wrong type of exception thrown
|
||||
} else if (!(new RegExp(testDescrip.negative, "i").test(this.iframeError))) { //wrong type of exception thrown
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'fail',
|
||||
Error('Expected an exception with a "message" property matching the regular expression "' + testDescrip.negative +'" to be thrown; actual was "' + window.iframeError + '".'));
|
||||
Error('Expected an exception with a "message" property matching the regular expression "' + testDescrip.negative +'" to be thrown; actual was "' + this.iframeError + '".'));
|
||||
} else {
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'pass', undefined);
|
||||
|
@ -41,10 +41,10 @@ if (testDescrip.negative !== undefined) {
|
|||
}
|
||||
|
||||
//Exception was not expected to be thrown
|
||||
else if (window.iframeError !== undefined) {
|
||||
else if (this.iframeError !== undefined) {
|
||||
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code,
|
||||
'fail',
|
||||
Error('Unexpected exception, "' + window.iframeError + '" was thrown.'));
|
||||
Error('Unexpected exception, "' + this.iframeError + '" was thrown.'));
|
||||
}
|
||||
|
||||
else {
|
||||
|
|
|
@ -1,548 +0,0 @@
|
|||
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function Test262Error(message) {
|
||||
if (message) this.message = message;
|
||||
}
|
||||
|
||||
Test262Error.prototype.toString = function () {
|
||||
return "Test262 Error: " + this.message;
|
||||
};
|
||||
|
||||
function testFailed(message) {
|
||||
throw new Test262Error(message);
|
||||
}
|
||||
|
||||
|
||||
function testPrint(message) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//adaptors for Test262 framework
|
||||
function $PRINT(message) {
|
||||
|
||||
}
|
||||
|
||||
function $INCLUDE(message) { }
|
||||
function $ERROR(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
function $FAIL(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Sputnik library definitions
|
||||
//Ultimately these should be namespaced some how and only made
|
||||
//available to tests that explicitly include them.
|
||||
//For now, we just define the globally
|
||||
|
||||
//math_precision.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function getPrecision(num)
|
||||
{
|
||||
//TODO: Create a table of prec's,
|
||||
// because using Math for testing Math isn't that correct.
|
||||
|
||||
log2num = Math.log(Math.abs(num))/Math.LN2;
|
||||
pernum = Math.ceil(log2num);
|
||||
return(2 * Math.pow(2, -52 + pernum));
|
||||
//return(0);
|
||||
}
|
||||
|
||||
|
||||
//math_isequal.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var prec;
|
||||
function isEqual(num1, num2)
|
||||
{
|
||||
if ((num1 === Infinity)&&(num2 === Infinity))
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
if ((num1 === -Infinity)&&(num2 === -Infinity))
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
prec = getPrecision(Math.min(Math.abs(num1), Math.abs(num2)));
|
||||
return(Math.abs(num1 - num2) <= prec);
|
||||
//return(num1 === num2);
|
||||
}
|
||||
|
||||
//numeric_conversion.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function ToInteger(p) {
|
||||
x = Number(p);
|
||||
|
||||
if(isNaN(x)){
|
||||
return +0;
|
||||
}
|
||||
|
||||
if((x === +0)
|
||||
|| (x === -0)
|
||||
|| (x === Number.POSITIVE_INFINITY)
|
||||
|| (x === Number.NEGATIVE_INFINITY)){
|
||||
return x;
|
||||
}
|
||||
|
||||
var sign = ( x < 0 ) ? -1 : 1;
|
||||
|
||||
return (sign*Math.floor(Math.abs(x)));
|
||||
}
|
||||
|
||||
//Date_constants.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
|
||||
var msPerDay = 86400000;
|
||||
var msPerSecond = 1000;
|
||||
var msPerMinute = 60000;
|
||||
var msPerHour = 3600000;
|
||||
|
||||
var date_1899_end = -2208988800001;
|
||||
var date_1900_start = -2208988800000;
|
||||
var date_1969_end = -1;
|
||||
var date_1970_start = 0;
|
||||
var date_1999_end = 946684799999;
|
||||
var date_2000_start = 946684800000;
|
||||
var date_2099_end = 4102444799999;
|
||||
var date_2100_start = 4102444800000;
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
// for now, we'll just use 0 for everything
|
||||
var $LocalTZ = 0;
|
||||
var $DST_start_month = 0;
|
||||
var $DST_start_sunday = 0;
|
||||
var $DST_start_hour = 0;
|
||||
var $DST_start_minutes = 0;
|
||||
var $DST_end_month = 0;
|
||||
var $DST_end_sunday = 0;
|
||||
var $DST_end_hour = 0;
|
||||
var $DST_end_minutes = 0;
|
||||
|
||||
|
||||
//Date.library.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
}
|
||||
|
||||
function TimeWithinDay(t) {
|
||||
return t%msPerDay;
|
||||
}
|
||||
|
||||
//15.9.1.3 Year Number
|
||||
function DaysInYear(y){
|
||||
if(y%4 != 0) return 365;
|
||||
if(y%4 == 0 && y%100 != 0) return 366;
|
||||
if(y%100 == 0 && y%400 != 0) return 365;
|
||||
if(y%400 == 0) return 366;
|
||||
}
|
||||
|
||||
function DayFromYear(y) {
|
||||
return (365*(y-1970)
|
||||
+ Math.floor((y-1969)/4)
|
||||
- Math.floor((y-1901)/100)
|
||||
+ Math.floor((y-1601)/400));
|
||||
}
|
||||
|
||||
function TimeFromYear(y){
|
||||
return msPerDay*DayFromYear(y);
|
||||
}
|
||||
|
||||
function YearFromTime(t) {
|
||||
t = Number(t);
|
||||
var sign = ( t < 0 ) ? -1 : 1;
|
||||
var year = ( sign < 0 ) ? 1969 : 1970;
|
||||
|
||||
for(var time = 0;;year += sign){
|
||||
time = TimeFromYear(year);
|
||||
|
||||
if(sign > 0 && time > t){
|
||||
year -= sign;
|
||||
break;
|
||||
}
|
||||
else if(sign < 0 && time <= t){
|
||||
break;
|
||||
}
|
||||
};
|
||||
return year;
|
||||
}
|
||||
|
||||
function InLeapYear(t){
|
||||
if(DaysInYear(YearFromTime(t)) == 365)
|
||||
return 0;
|
||||
|
||||
if(DaysInYear(YearFromTime(t)) == 366)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function DayWithinYear(t) {
|
||||
return Day(t)-DayFromYear(YearFromTime(t));
|
||||
}
|
||||
|
||||
//15.9.1.4 Month Number
|
||||
function MonthFromTime(t){
|
||||
var day = DayWithinYear(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if((0 <= day) && (day < 31)) return 0;
|
||||
if((31 <= day) && (day < (59+leap))) return 1;
|
||||
if(((59+leap) <= day) && (day < (90+leap))) return 2;
|
||||
if(((90+leap) <= day) && (day < (120+leap))) return 3;
|
||||
if(((120+leap) <= day) && (day < (151+leap))) return 4;
|
||||
if(((151+leap) <= day) && (day < (181+leap))) return 5;
|
||||
if(((181+leap) <= day) && (day < (212+leap))) return 6;
|
||||
if(((212+leap) <= day) && (day < (243+leap))) return 7;
|
||||
if(((243+leap) <= day) && (day < (273+leap))) return 8;
|
||||
if(((273+leap) <= day) && (day < (304+leap))) return 9;
|
||||
if(((304+leap) <= day) && (day < (334+leap))) return 10;
|
||||
if(((334+leap) <= day) && (day < (365+leap))) return 11;
|
||||
}
|
||||
|
||||
//15.9.1.5 Date Number
|
||||
function DateFromTime(t) {
|
||||
var day = DayWithinYear(t);
|
||||
var month = MonthFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if(month == 0) return day+1;
|
||||
if(month == 1) return day-30;
|
||||
if(month == 2) return day-58-leap;
|
||||
if(month == 3) return day-89-leap;
|
||||
if(month == 4) return day-119-leap;
|
||||
if(month == 5) return day-150-leap;
|
||||
if(month == 6) return day-180-leap;
|
||||
if(month == 7) return day-211-leap;
|
||||
if(month == 8) return day-242-leap;
|
||||
if(month == 9) return day-272-leap;
|
||||
if(month == 10) return day-303-leap;
|
||||
if(month == 11) return day-333-leap;
|
||||
}
|
||||
|
||||
//15.9.1.6 Week Day
|
||||
function WeekDay(t) {
|
||||
var weekday = (Day(t)+4)%7;
|
||||
return (weekday < 0 ? 7+weekday : weekday);
|
||||
}
|
||||
|
||||
//15.9.1.9 Daylight Saving Time Adjustment
|
||||
var LocalTZA = $LocalTZ*msPerHour;
|
||||
|
||||
function DaysInMonth(m, leap) {
|
||||
m = m%12;
|
||||
|
||||
//April, June, Sept, Nov
|
||||
if(m == 3 || m == 5 || m == 8 || m == 10 ) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
//Jan, March, May, July, Aug, Oct, Dec
|
||||
if(m == 0 || m == 2 || m == 4 || m == 6 || m == 7 || m == 9 || m == 11){
|
||||
return 31;
|
||||
}
|
||||
|
||||
//Feb
|
||||
return 28+leap;
|
||||
}
|
||||
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
var day = 0;
|
||||
|
||||
if(m >= 1) day += DaysInMonth(0, leap);
|
||||
if(m >= 2) day += DaysInMonth(1, leap);
|
||||
if(m >= 3) day += DaysInMonth(2, leap);
|
||||
if(m >= 4) day += DaysInMonth(3, leap);
|
||||
if(m >= 5) day += DaysInMonth(4, leap);
|
||||
if(m >= 6) day += DaysInMonth(5, leap);
|
||||
if(m >= 7) day += DaysInMonth(6, leap);
|
||||
if(m >= 8) day += DaysInMonth(7, leap);
|
||||
if(m >= 9) day += DaysInMonth(8, leap);
|
||||
if(m >= 10) day += DaysInMonth(9, leap);
|
||||
if(m >= 11) day += DaysInMonth(10, leap);
|
||||
|
||||
var month_start = TimeFromYear(year)+day*msPerDay;
|
||||
var sunday = 0;
|
||||
|
||||
if(count === "last"){
|
||||
for(var last_sunday = month_start+DaysInMonth(m, leap)*msPerDay;
|
||||
WeekDay(last_sunday)>0;
|
||||
last_sunday -= msPerDay
|
||||
){};
|
||||
sunday = last_sunday;
|
||||
}
|
||||
else {
|
||||
for(var first_sunday = month_start;
|
||||
WeekDay(first_sunday)>0;
|
||||
first_sunday += msPerDay
|
||||
){};
|
||||
sunday = first_sunday+7*msPerDay*(count-1);
|
||||
}
|
||||
|
||||
return sunday;
|
||||
}
|
||||
|
||||
function DaylightSavingTA(t) {
|
||||
t = t-LocalTZA;
|
||||
|
||||
var DST_start = GetSundayInMonth(t, $DST_start_month, $DST_start_sunday)
|
||||
+$DST_start_hour*msPerHour
|
||||
+$DST_start_minutes*msPerMinute;
|
||||
|
||||
var k = new Date(DST_start);
|
||||
|
||||
var DST_end = GetSundayInMonth(t, $DST_end_month, $DST_end_sunday)
|
||||
+$DST_end_hour*msPerHour
|
||||
+$DST_end_minutes*msPerMinute;
|
||||
|
||||
if ( t >= DST_start && t < DST_end ) {
|
||||
return msPerHour;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//15.9.1.9 Local Time
|
||||
function LocalTime(t){
|
||||
return t+LocalTZA+DaylightSavingTA(t);
|
||||
}
|
||||
|
||||
function UTC(t) {
|
||||
return t-LocalTZA-DaylightSavingTA(t-LocalTZA);
|
||||
}
|
||||
|
||||
//15.9.1.10 Hours, Minutes, Second, and Milliseconds
|
||||
function HourFromTime(t){
|
||||
return Math.floor(t/msPerHour)%HoursPerDay;
|
||||
}
|
||||
|
||||
function MinFromTime(t){
|
||||
return Math.floor(t/msPerMinute)%MinutesPerHour;
|
||||
}
|
||||
|
||||
function SecFromTime(t){
|
||||
return Math.floor(t/msPerSecond)%SecondsPerMinute;
|
||||
}
|
||||
|
||||
function msFromTime(t){
|
||||
return t%msPerSecond;
|
||||
}
|
||||
|
||||
//15.9.1.11 MakeTime (hour, min, sec, ms)
|
||||
function MakeTime(hour, min, sec, ms){
|
||||
if ( !isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
hour = ToInteger(hour);
|
||||
min = ToInteger(min);
|
||||
sec = ToInteger(sec);
|
||||
ms = ToInteger(ms);
|
||||
|
||||
return ((hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms);
|
||||
}
|
||||
|
||||
//15.9.1.12 MakeDay (year, month, date)
|
||||
function MakeDay(year, month, date) {
|
||||
if ( !isFinite(year) || !isFinite(month) || !isFinite(date)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
year = ToInteger(year);
|
||||
month = ToInteger(month);
|
||||
date = ToInteger(date );
|
||||
|
||||
var result5 = year + Math.floor(month/12);
|
||||
var result6 = month%12;
|
||||
|
||||
var sign = ( year < 1970 ) ? -1 : 1;
|
||||
var t = ( year < 1970 ) ? 1 : 0;
|
||||
var y = ( year < 1970 ) ? 1969 : 1970;
|
||||
|
||||
if( sign == -1 ){
|
||||
for ( y = 1969; y >= year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
} else {
|
||||
for ( y = 1970 ; y < year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
}
|
||||
|
||||
var leap = 0;
|
||||
for ( var m = 0; m < month; m++ ) {
|
||||
//if year is changed, than we need to recalculate leep
|
||||
leap = InLeapYear(t);
|
||||
t += DaysInMonth(m, leap)*msPerDay;
|
||||
}
|
||||
|
||||
if ( YearFromTime(t) != result5 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( MonthFromTime(t) != result6 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( DateFromTime(t) != 1 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return Day(t)+date-1;
|
||||
}
|
||||
|
||||
//15.9.1.13 MakeDate (day, time)
|
||||
function MakeDate( day, time ) {
|
||||
if(!isFinite(day) || !isFinite(time)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return day*msPerDay+time;
|
||||
}
|
||||
|
||||
//15.9.1.14 TimeClip (time)
|
||||
function TimeClip(time) {
|
||||
if(!isFinite(time) || Math.abs(time) > 8.64e15){
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return ToInteger(time);
|
||||
}
|
||||
|
||||
//Test Functions
|
||||
function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
||||
/*
|
||||
* 1. Call ToNumber(year)
|
||||
* 2. Call ToNumber(month)
|
||||
* 3. If date is supplied use ToNumber(date); else use 1
|
||||
* 4. If hours is supplied use ToNumber(hours); else use 0
|
||||
* 5. If minutes is supplied use ToNumber(minutes); else use 0
|
||||
* 6. If seconds is supplied use ToNumber(seconds); else use 0
|
||||
* 7. If ms is supplied use ToNumber(ms); else use 0
|
||||
* 8. If Result(1) is not NaN and 0 <= ToInteger(Result(1)) <= 99,
|
||||
* Result(8) is 1900+ToInteger(Result(1));
|
||||
* otherwise, Result(8) is Result(1)
|
||||
* 9. Compute MakeDay(Result(8), Result(2), Result(3))
|
||||
* 10. Compute MakeTime(Result(4), Result(5), Result(6), Result(7))
|
||||
* 11. Compute MakeDate(Result(9), Result(10))
|
||||
* 12. Set the [[Value]] property of the newly constructed object to
|
||||
* TimeClip(UTC(Result(11)))
|
||||
*/
|
||||
var r1 = Number(year);
|
||||
var r2 = Number(month);
|
||||
var r3 = ((date && arguments.length > 2) ? Number(date) : 1);
|
||||
var r4 = ((hours && arguments.length > 3) ? Number(hours) : 0);
|
||||
var r5 = ((minutes && arguments.length > 4) ? Number(minutes) : 0);
|
||||
var r6 = ((seconds && arguments.length > 5) ? Number(seconds) : 0);
|
||||
var r7 = ((ms && arguments.length > 6) ? Number(ms) : 0);
|
||||
|
||||
var r8 = r1;
|
||||
|
||||
if(!isNaN(r1) && (0 <= ToInteger(r1)) && (ToInteger(r1) <= 99))
|
||||
r8 = 1900+r1;
|
||||
|
||||
var r9 = MakeDay(r8, r2, r3);
|
||||
var r10 = MakeTime(r4, r5, r6, r7);
|
||||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**** Python code for initialize the above constants
|
||||
// We may want to replicate the following in JavaScript.
|
||||
// However, using JS date operations to generate parameters that are then used to
|
||||
// test those some date operations seems unsound. However, it isn't clear if there
|
||||
//is a good interoperable alternative.
|
||||
|
||||
# Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
# This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
def GetDaylightSavingsTimes():
|
||||
# Is the given floating-point time in DST?
|
||||
def IsDst(t):
|
||||
return time.localtime(t)[-1]
|
||||
# Binary search to find an interval between the two times no greater than
|
||||
# delta where DST switches, returning the midpoint.
|
||||
def FindBetween(start, end, delta):
|
||||
while end - start > delta:
|
||||
middle = (end + start) / 2
|
||||
if IsDst(middle) == IsDst(start):
|
||||
start = middle
|
||||
else:
|
||||
end = middle
|
||||
return (start + end) / 2
|
||||
now = time.time()
|
||||
one_month = (30 * 24 * 60 * 60)
|
||||
# First find a date with different daylight savings. To avoid corner cases
|
||||
# we try four months before and after today.
|
||||
after = now + 4 * one_month
|
||||
before = now - 4 * one_month
|
||||
if IsDst(now) == IsDst(before) and IsDst(now) == IsDst(after):
|
||||
logger.warning("Was unable to determine DST info.")
|
||||
return None
|
||||
# Determine when the change occurs between now and the date we just found
|
||||
# in a different DST.
|
||||
if IsDst(now) != IsDst(before):
|
||||
first = FindBetween(before, now, 1)
|
||||
else:
|
||||
first = FindBetween(now, after, 1)
|
||||
# Determine when the change occurs between three and nine months from the
|
||||
# first.
|
||||
second = FindBetween(first + 3 * one_month, first + 9 * one_month, 1)
|
||||
# Find out which switch is into and which if out of DST
|
||||
if IsDst(first - 1) and not IsDst(first + 1):
|
||||
start = second
|
||||
end = first
|
||||
else:
|
||||
start = first
|
||||
end = second
|
||||
return (start, end)
|
||||
|
||||
|
||||
def GetDaylightSavingsAttribs():
|
||||
times = GetDaylightSavingsTimes()
|
||||
if not times:
|
||||
return None
|
||||
(start, end) = times
|
||||
def DstMonth(t):
|
||||
return time.localtime(t)[1] - 1
|
||||
def DstHour(t):
|
||||
return time.localtime(t - 1)[3] + 1
|
||||
def DstSunday(t):
|
||||
if time.localtime(t)[2] > 15:
|
||||
return "'last'"
|
||||
else:
|
||||
return "'first'"
|
||||
def DstMinutes(t):
|
||||
return (time.localtime(t - 1)[4] + 1) % 60
|
||||
attribs = { }
|
||||
attribs['start_month'] = DstMonth(start)
|
||||
attribs['end_month'] = DstMonth(end)
|
||||
attribs['start_sunday'] = DstSunday(start)
|
||||
attribs['end_sunday'] = DstSunday(end)
|
||||
attribs['start_hour'] = DstHour(start)
|
||||
attribs['end_hour'] = DstHour(end)
|
||||
attribs['start_minutes'] = DstMinutes(start)
|
||||
attribs['end_minutes'] = DstMinutes(end)
|
||||
return attribs
|
||||
|
||||
*********/
|
|
@ -284,6 +284,624 @@ var NotEarlyErrorString = "NotEarlyError";
|
|||
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
|
||||
var NotEarlyError = new Error(NotEarlyErrorString);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function Test262Error(message) {
|
||||
if (message) this.message = message;
|
||||
}
|
||||
|
||||
Test262Error.prototype.toString = function () {
|
||||
return "Test262 Error: " + this.message;
|
||||
};
|
||||
|
||||
function testFailed(message) {
|
||||
throw new Test262Error(message);
|
||||
}
|
||||
|
||||
|
||||
function testPrint(message) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//adaptors for Test262 framework
|
||||
function $PRINT(message) {
|
||||
|
||||
}
|
||||
|
||||
function $INCLUDE(message) { }
|
||||
function $ERROR(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
function $FAIL(message) {
|
||||
testFailed(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Sputnik library definitions
|
||||
//Ultimately these should be namespaced some how and only made
|
||||
//available to tests that explicitly include them.
|
||||
//For now, we just define the globally
|
||||
|
||||
//math_precision.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function getPrecision(num) {
|
||||
//TODO: Create a table of prec's,
|
||||
// because using Math for testing Math isn't that correct.
|
||||
|
||||
log2num = Math.log(Math.abs(num)) / Math.LN2;
|
||||
pernum = Math.ceil(log2num);
|
||||
return (2 * Math.pow(2, -52 + pernum));
|
||||
//return(0);
|
||||
}
|
||||
|
||||
|
||||
//math_isequal.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var prec;
|
||||
function isEqual(num1, num2) {
|
||||
if ((num1 === Infinity) && (num2 === Infinity)) {
|
||||
return (true);
|
||||
}
|
||||
if ((num1 === -Infinity) && (num2 === -Infinity)) {
|
||||
return (true);
|
||||
}
|
||||
prec = getPrecision(Math.min(Math.abs(num1), Math.abs(num2)));
|
||||
return (Math.abs(num1 - num2) <= prec);
|
||||
//return(num1 === num2);
|
||||
}
|
||||
|
||||
//numeric_conversion.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
function ToInteger(p) {
|
||||
x = Number(p);
|
||||
|
||||
if (isNaN(x)) {
|
||||
return +0;
|
||||
}
|
||||
|
||||
if ((x === +0)
|
||||
|| (x === -0)
|
||||
|| (x === Number.POSITIVE_INFINITY)
|
||||
|| (x === Number.NEGATIVE_INFINITY)) {
|
||||
return x;
|
||||
}
|
||||
|
||||
var sign = (x < 0) ? -1 : 1;
|
||||
|
||||
return (sign * Math.floor(Math.abs(x)));
|
||||
}
|
||||
|
||||
//Date_constants.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
|
||||
var msPerDay = 86400000;
|
||||
var msPerSecond = 1000;
|
||||
var msPerMinute = 60000;
|
||||
var msPerHour = 3600000;
|
||||
|
||||
var date_1899_end = -2208988800001;
|
||||
var date_1900_start = -2208988800000;
|
||||
var date_1969_end = -1;
|
||||
var date_1970_start = 0;
|
||||
var date_1999_end = 946684799999;
|
||||
var date_2000_start = 946684800000;
|
||||
var date_2099_end = 4102444799999;
|
||||
var date_2100_start = 4102444800000;
|
||||
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
var $LocalTZ,
|
||||
$DST_start_month,
|
||||
$DST_start_sunday,
|
||||
$DST_start_hour,
|
||||
$DST_start_minutes,
|
||||
$DST_end_month,
|
||||
$DST_end_sunday,
|
||||
$DST_end_hour,
|
||||
$DST_end_minutes;
|
||||
|
||||
(function () {
|
||||
/**
|
||||
* Finds the first date, starting from |start|, where |predicate|
|
||||
* holds.
|
||||
*/
|
||||
var findNearestDateBefore = function(start, predicate) {
|
||||
var current = start;
|
||||
var month = 1000 * 60 * 60 * 24 * 30;
|
||||
for (var step = month; step > 0; step = Math.floor(step / 3)) {
|
||||
if (!predicate(current)) {
|
||||
while (!predicate(current))
|
||||
current = new Date(current.getTime() + step);
|
||||
current = new Date(current.getTime() - step);
|
||||
}
|
||||
}
|
||||
while (!predicate(current)) {
|
||||
current = new Date(current.getTime() + 1);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
|
||||
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
|
||||
var juneOffset = juneDate.getTimezoneOffset();
|
||||
var decemberOffset = decemberDate.getTimezoneOffset();
|
||||
var isSouthernHemisphere = (juneOffset > decemberOffset);
|
||||
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
|
||||
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
|
||||
|
||||
var dstStart = findNearestDateBefore(winterTime, function (date) {
|
||||
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_start_month = dstStart.getMonth();
|
||||
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_start_hour = dstStart.getHours();
|
||||
$DST_start_minutes = dstStart.getMinutes();
|
||||
|
||||
var dstEnd = findNearestDateBefore(summerTime, function (date) {
|
||||
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_end_month = dstEnd.getMonth();
|
||||
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_end_hour = dstEnd.getHours();
|
||||
$DST_end_minutes = dstEnd.getMinutes();
|
||||
|
||||
return;
|
||||
})();
|
||||
|
||||
|
||||
//Date.library.js
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
}
|
||||
|
||||
function TimeWithinDay(t) {
|
||||
return t%msPerDay;
|
||||
}
|
||||
|
||||
//15.9.1.3 Year Number
|
||||
function DaysInYear(y){
|
||||
if(y%4 != 0) return 365;
|
||||
if(y%4 == 0 && y%100 != 0) return 366;
|
||||
if(y%100 == 0 && y%400 != 0) return 365;
|
||||
if(y%400 == 0) return 366;
|
||||
}
|
||||
|
||||
function DayFromYear(y) {
|
||||
return (365*(y-1970)
|
||||
+ Math.floor((y-1969)/4)
|
||||
- Math.floor((y-1901)/100)
|
||||
+ Math.floor((y-1601)/400));
|
||||
}
|
||||
|
||||
function TimeFromYear(y){
|
||||
return msPerDay*DayFromYear(y);
|
||||
}
|
||||
|
||||
function YearFromTime(t) {
|
||||
t = Number(t);
|
||||
var sign = ( t < 0 ) ? -1 : 1;
|
||||
var year = ( sign < 0 ) ? 1969 : 1970;
|
||||
|
||||
for(var time = 0;;year += sign){
|
||||
time = TimeFromYear(year);
|
||||
|
||||
if(sign > 0 && time > t){
|
||||
year -= sign;
|
||||
break;
|
||||
}
|
||||
else if(sign < 0 && time <= t){
|
||||
break;
|
||||
}
|
||||
};
|
||||
return year;
|
||||
}
|
||||
|
||||
function InLeapYear(t){
|
||||
if(DaysInYear(YearFromTime(t)) == 365)
|
||||
return 0;
|
||||
|
||||
if(DaysInYear(YearFromTime(t)) == 366)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function DayWithinYear(t) {
|
||||
return Day(t)-DayFromYear(YearFromTime(t));
|
||||
}
|
||||
|
||||
//15.9.1.4 Month Number
|
||||
function MonthFromTime(t){
|
||||
var day = DayWithinYear(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if((0 <= day) && (day < 31)) return 0;
|
||||
if((31 <= day) && (day < (59+leap))) return 1;
|
||||
if(((59+leap) <= day) && (day < (90+leap))) return 2;
|
||||
if(((90+leap) <= day) && (day < (120+leap))) return 3;
|
||||
if(((120+leap) <= day) && (day < (151+leap))) return 4;
|
||||
if(((151+leap) <= day) && (day < (181+leap))) return 5;
|
||||
if(((181+leap) <= day) && (day < (212+leap))) return 6;
|
||||
if(((212+leap) <= day) && (day < (243+leap))) return 7;
|
||||
if(((243+leap) <= day) && (day < (273+leap))) return 8;
|
||||
if(((273+leap) <= day) && (day < (304+leap))) return 9;
|
||||
if(((304+leap) <= day) && (day < (334+leap))) return 10;
|
||||
if(((334+leap) <= day) && (day < (365+leap))) return 11;
|
||||
}
|
||||
|
||||
//15.9.1.5 Date Number
|
||||
function DateFromTime(t) {
|
||||
var day = DayWithinYear(t);
|
||||
var month = MonthFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
|
||||
if(month == 0) return day+1;
|
||||
if(month == 1) return day-30;
|
||||
if(month == 2) return day-58-leap;
|
||||
if(month == 3) return day-89-leap;
|
||||
if(month == 4) return day-119-leap;
|
||||
if(month == 5) return day-150-leap;
|
||||
if(month == 6) return day-180-leap;
|
||||
if(month == 7) return day-211-leap;
|
||||
if(month == 8) return day-242-leap;
|
||||
if(month == 9) return day-272-leap;
|
||||
if(month == 10) return day-303-leap;
|
||||
if(month == 11) return day-333-leap;
|
||||
}
|
||||
|
||||
//15.9.1.6 Week Day
|
||||
function WeekDay(t) {
|
||||
var weekday = (Day(t)+4)%7;
|
||||
return (weekday < 0 ? 7+weekday : weekday);
|
||||
}
|
||||
|
||||
//15.9.1.9 Daylight Saving Time Adjustment
|
||||
$LocalTZ = (new Date()).getTimezoneOffset() / -60;
|
||||
if (DaylightSavingTA((new Date()).valueOf()) !== 0) {
|
||||
$LocalTZ -= 1;
|
||||
}
|
||||
var LocalTZA = $LocalTZ*msPerHour;
|
||||
|
||||
function DaysInMonth(m, leap) {
|
||||
m = m%12;
|
||||
|
||||
//April, June, Sept, Nov
|
||||
if(m == 3 || m == 5 || m == 8 || m == 10 ) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
//Jan, March, May, July, Aug, Oct, Dec
|
||||
if(m == 0 || m == 2 || m == 4 || m == 6 || m == 7 || m == 9 || m == 11){
|
||||
return 31;
|
||||
}
|
||||
|
||||
//Feb
|
||||
return 28+leap;
|
||||
}
|
||||
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
|
||||
if (count==='"first"') {
|
||||
for (var d=1; d <= DaysInMonth(m, InLeapYear(t)); d++) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
} else if(count==='"last"') {
|
||||
for (var d=DaysInMonth(m, InLeapYear(t)); d>0; d--) {
|
||||
tempDate = new Date(year, m, d);
|
||||
if (tempDate.getDay()===0) {
|
||||
return tempDate.valueOf();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("Unsupported 'count' arg:" + count);
|
||||
}
|
||||
/*
|
||||
function GetSundayInMonth(t, m, count){
|
||||
var year = YearFromTime(t);
|
||||
var leap = InLeapYear(t);
|
||||
var day = 0;
|
||||
|
||||
if(m >= 1) day += DaysInMonth(0, leap);
|
||||
if(m >= 2) day += DaysInMonth(1, leap);
|
||||
if(m >= 3) day += DaysInMonth(2, leap);
|
||||
if(m >= 4) day += DaysInMonth(3, leap);
|
||||
if(m >= 5) day += DaysInMonth(4, leap);
|
||||
if(m >= 6) day += DaysInMonth(5, leap);
|
||||
if(m >= 7) day += DaysInMonth(6, leap);
|
||||
if(m >= 8) day += DaysInMonth(7, leap);
|
||||
if(m >= 9) day += DaysInMonth(8, leap);
|
||||
if(m >= 10) day += DaysInMonth(9, leap);
|
||||
if(m >= 11) day += DaysInMonth(10, leap);
|
||||
|
||||
var month_start = TimeFromYear(year)+day*msPerDay;
|
||||
var sunday = 0;
|
||||
|
||||
if(count === "last"){
|
||||
for(var last_sunday = month_start+DaysInMonth(m, leap)*msPerDay;
|
||||
WeekDay(last_sunday)>0;
|
||||
last_sunday -= msPerDay
|
||||
){};
|
||||
sunday = last_sunday;
|
||||
}
|
||||
else {
|
||||
for(var first_sunday = month_start;
|
||||
WeekDay(first_sunday)>0;
|
||||
first_sunday += msPerDay
|
||||
){};
|
||||
sunday = first_sunday+7*msPerDay*(count-1);
|
||||
}
|
||||
|
||||
return sunday;
|
||||
}*/
|
||||
|
||||
function DaylightSavingTA(t) {
|
||||
// t = t-LocalTZA;
|
||||
|
||||
var DST_start = GetSundayInMonth(t, $DST_start_month, $DST_start_sunday) +
|
||||
$DST_start_hour*msPerHour +
|
||||
$DST_start_minutes*msPerMinute;
|
||||
|
||||
var k = new Date(DST_start);
|
||||
|
||||
var DST_end = GetSundayInMonth(t, $DST_end_month, $DST_end_sunday) +
|
||||
$DST_end_hour*msPerHour +
|
||||
$DST_end_minutes*msPerMinute;
|
||||
|
||||
if ( t >= DST_start && t < DST_end ) {
|
||||
return msPerHour;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//15.9.1.9 Local Time
|
||||
function LocalTime(t){
|
||||
return t+LocalTZA+DaylightSavingTA(t);
|
||||
}
|
||||
|
||||
function UTC(t) {
|
||||
return t-LocalTZA-DaylightSavingTA(t-LocalTZA);
|
||||
}
|
||||
|
||||
//15.9.1.10 Hours, Minutes, Second, and Milliseconds
|
||||
function HourFromTime(t){
|
||||
return Math.floor(t/msPerHour)%HoursPerDay;
|
||||
}
|
||||
|
||||
function MinFromTime(t){
|
||||
return Math.floor(t/msPerMinute)%MinutesPerHour;
|
||||
}
|
||||
|
||||
function SecFromTime(t){
|
||||
return Math.floor(t/msPerSecond)%SecondsPerMinute;
|
||||
}
|
||||
|
||||
function msFromTime(t){
|
||||
return t%msPerSecond;
|
||||
}
|
||||
|
||||
//15.9.1.11 MakeTime (hour, min, sec, ms)
|
||||
function MakeTime(hour, min, sec, ms){
|
||||
if ( !isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
hour = ToInteger(hour);
|
||||
min = ToInteger(min);
|
||||
sec = ToInteger(sec);
|
||||
ms = ToInteger(ms);
|
||||
|
||||
return ((hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms);
|
||||
}
|
||||
|
||||
//15.9.1.12 MakeDay (year, month, date)
|
||||
function MakeDay(year, month, date) {
|
||||
if ( !isFinite(year) || !isFinite(month) || !isFinite(date)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
year = ToInteger(year);
|
||||
month = ToInteger(month);
|
||||
date = ToInteger(date );
|
||||
|
||||
var result5 = year + Math.floor(month/12);
|
||||
var result6 = month%12;
|
||||
|
||||
var sign = ( year < 1970 ) ? -1 : 1;
|
||||
var t = ( year < 1970 ) ? 1 : 0;
|
||||
var y = ( year < 1970 ) ? 1969 : 1970;
|
||||
|
||||
if( sign == -1 ){
|
||||
for ( y = 1969; y >= year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
} else {
|
||||
for ( y = 1970 ; y < year; y += sign ) {
|
||||
t += sign * DaysInYear(y)*msPerDay;
|
||||
}
|
||||
}
|
||||
|
||||
var leap = 0;
|
||||
for ( var m = 0; m < month; m++ ) {
|
||||
//if year is changed, than we need to recalculate leep
|
||||
leap = InLeapYear(t);
|
||||
t += DaysInMonth(m, leap)*msPerDay;
|
||||
}
|
||||
|
||||
if ( YearFromTime(t) != result5 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( MonthFromTime(t) != result6 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
if ( DateFromTime(t) != 1 ) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return Day(t)+date-1;
|
||||
}
|
||||
|
||||
//15.9.1.13 MakeDate (day, time)
|
||||
function MakeDate( day, time ) {
|
||||
if(!isFinite(day) || !isFinite(time)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return day*msPerDay+time;
|
||||
}
|
||||
|
||||
//15.9.1.14 TimeClip (time)
|
||||
function TimeClip(time) {
|
||||
if(!isFinite(time) || Math.abs(time) > 8.64e15){
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
return ToInteger(time);
|
||||
}
|
||||
|
||||
//Test Functions
|
||||
function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
||||
/*
|
||||
* 1. Call ToNumber(year)
|
||||
* 2. Call ToNumber(month)
|
||||
* 3. If date is supplied use ToNumber(date); else use 1
|
||||
* 4. If hours is supplied use ToNumber(hours); else use 0
|
||||
* 5. If minutes is supplied use ToNumber(minutes); else use 0
|
||||
* 6. If seconds is supplied use ToNumber(seconds); else use 0
|
||||
* 7. If ms is supplied use ToNumber(ms); else use 0
|
||||
* 8. If Result(1) is not NaN and 0 <= ToInteger(Result(1)) <= 99, Result(8) is
|
||||
* 1900+ToInteger(Result(1)); otherwise, Result(8) is Result(1)
|
||||
* 9. Compute MakeDay(Result(8), Result(2), Result(3))
|
||||
* 10. Compute MakeTime(Result(4), Result(5), Result(6), Result(7))
|
||||
* 11. Compute MakeDate(Result(9), Result(10))
|
||||
* 12. Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(11)))
|
||||
*/
|
||||
var r1 = Number(year);
|
||||
var r2 = Number(month);
|
||||
var r3 = ((date && arguments.length > 2) ? Number(date) : 1);
|
||||
var r4 = ((hours && arguments.length > 3) ? Number(hours) : 0);
|
||||
var r5 = ((minutes && arguments.length > 4) ? Number(minutes) : 0);
|
||||
var r6 = ((seconds && arguments.length > 5) ? Number(seconds) : 0);
|
||||
var r7 = ((ms && arguments.length > 6) ? Number(ms) : 0);
|
||||
|
||||
var r8 = r1;
|
||||
|
||||
if(!isNaN(r1) && (0 <= ToInteger(r1)) && (ToInteger(r1) <= 99))
|
||||
r8 = 1900+r1;
|
||||
|
||||
var r9 = MakeDay(r8, r2, r3);
|
||||
var r10 = MakeTime(r4, r5, r6, r7);
|
||||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**** Python code for initialize the above constants
|
||||
// We may want to replicate the following in JavaScript.
|
||||
// However, using JS date operations to generate parameters that are then used to
|
||||
// test those some date operations seems unsound. However, it isn't clear if there
|
||||
//is a good interoperable alternative.
|
||||
|
||||
# Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
# This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
def GetDaylightSavingsTimes():
|
||||
# Is the given floating-point time in DST?
|
||||
def IsDst(t):
|
||||
return time.localtime(t)[-1]
|
||||
# Binary search to find an interval between the two times no greater than
|
||||
# delta where DST switches, returning the midpoint.
|
||||
def FindBetween(start, end, delta):
|
||||
while end - start > delta:
|
||||
middle = (end + start) / 2
|
||||
if IsDst(middle) == IsDst(start):
|
||||
start = middle
|
||||
else:
|
||||
end = middle
|
||||
return (start + end) / 2
|
||||
now = time.time()
|
||||
one_month = (30 * 24 * 60 * 60)
|
||||
# First find a date with different daylight savings. To avoid corner cases
|
||||
# we try four months before and after today.
|
||||
after = now + 4 * one_month
|
||||
before = now - 4 * one_month
|
||||
if IsDst(now) == IsDst(before) and IsDst(now) == IsDst(after):
|
||||
logger.warning("Was unable to determine DST info.")
|
||||
return None
|
||||
# Determine when the change occurs between now and the date we just found
|
||||
# in a different DST.
|
||||
if IsDst(now) != IsDst(before):
|
||||
first = FindBetween(before, now, 1)
|
||||
else:
|
||||
first = FindBetween(now, after, 1)
|
||||
# Determine when the change occurs between three and nine months from the
|
||||
# first.
|
||||
second = FindBetween(first + 3 * one_month, first + 9 * one_month, 1)
|
||||
# Find out which switch is into and which if out of DST
|
||||
if IsDst(first - 1) and not IsDst(first + 1):
|
||||
start = second
|
||||
end = first
|
||||
else:
|
||||
start = first
|
||||
end = second
|
||||
return (start, end)
|
||||
|
||||
|
||||
def GetDaylightSavingsAttribs():
|
||||
times = GetDaylightSavingsTimes()
|
||||
if not times:
|
||||
return None
|
||||
(start, end) = times
|
||||
def DstMonth(t):
|
||||
return time.localtime(t)[1] - 1
|
||||
def DstHour(t):
|
||||
return time.localtime(t - 1)[3] + 1
|
||||
def DstSunday(t):
|
||||
if time.localtime(t)[2] > 15:
|
||||
return "'last'"
|
||||
else:
|
||||
return "'first'"
|
||||
def DstMinutes(t):
|
||||
return (time.localtime(t - 1)[4] + 1) % 60
|
||||
attribs = { }
|
||||
attribs['start_month'] = DstMonth(start)
|
||||
attribs['end_month'] = DstMonth(end)
|
||||
attribs['start_sunday'] = DstSunday(start)
|
||||
attribs['end_sunday'] = DstSunday(end)
|
||||
attribs['start_hour'] = DstHour(start)
|
||||
attribs['end_hour'] = DstHour(end)
|
||||
attribs['start_minutes'] = DstMinutes(start)
|
||||
attribs['end_minutes'] = DstMinutes(end)
|
||||
return attribs
|
||||
|
||||
*********/
|
||||
|
||||
//--Test case registration-----------------------------------------------------
|
||||
function runTestCase(testcase) {
|
||||
if (testcase() !== true) {
|
||||
|
|
|
@ -127,11 +127,6 @@ function BrowserRunner() {
|
|||
//TODO: these should be moved to sta.js
|
||||
var includes = code.match(/\$INCLUDE\(([^\)]+)\)/g), // find all of the $INCLUDE statements
|
||||
include;
|
||||
iwin.Test262Error = Test262Error;
|
||||
iwin.$ERROR = $ERROR;
|
||||
iwin.$FAIL = $FAIL;
|
||||
iwin.$PRINT = function () { };
|
||||
iwin.$INCLUDE = function () { };
|
||||
|
||||
if (includes !== null) {
|
||||
// We have some includes, so loop through each include and
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"date":"2011-09-25","numTests":11016,"testSuite":["json/07_Lexical_Conventions.json","json/08_Types.json","json/09_Type_Conversion.json","json/10_Execution_Contexts.json","json/11.10_Binary_Bitwise_Operators.json","json/11.11_Binary_Logical_Operators.json","json/11.12_Conditional_Operator.json","json/11.13_Assignment_Operators.json","json/11.14_Comma_Operator.json","json/11.1_Primary_Expressions.json","json/11.2_Left_Hand_Side_Expressions.json","json/11.3_PostfixExpressions.json","json/11.4_Unary_Operators.json","json/11.5_Multiplicative_Operators.json","json/11.6_Additive_Operators.json","json/11.7_Bitwise_Shift_Operators.json","json/11.8_Relational_Operators.json","json/11.9_Equality_Operators.json","json/12_Statement.json","json/13_Function_Definition.json","json/14_Program.json","json/15.10_RegExp_Objects.json","json/15.11_Error_Objects.json","json/15.12_The_JSON_Object.json","json/15.1_The_Global_Object.json","json/15.2_Object_Objects.json","json/15.3_Function_Objects.json","json/15.4_Array_Objects.json","json/15.5_String_Objects.json","json/15.6_Boolean_Objects.json","json/15.7_Number_Objects.json","json/15.8_The_Math_Object.json","json/15.9_Date_Objects.json","json/chapter07.json","json/chapter08.json","json/chapter10.json","json/chapter11.json","json/chapter12.json","json/chapter13.json","json/chapter14.json","json/15.1.json","json/15.10.json","json/15.11.json","json/15.12.json","json/15.2.3.1.json","json/15.2.3.10.json","json/15.2.3.11.json","json/15.2.3.12.json","json/15.2.3.13.json","json/15.2.3.14.json","json/15.2.3.2.json","json/15.2.3.3.json","json/15.2.3.4.json","json/15.2.3.5.json","json/15.2.3.6.json","json/15.2.3.7.json","json/15.2.3.8.json","json/15.2.3.9.json","json/15.2.4.json","json/15.3.json","json/15.4.3.json","json/15.4.4.10.json","json/15.4.4.12.json","json/15.4.4.14.json","json/15.4.4.15.json","json/15.4.4.16.json","json/15.4.4.17.json","json/15.4.4.18.json","json/15.4.4.19.json","json/15.4.4.20.json","json/15.4.4.21.json","json/15.4.4.22.json","json/15.4.4.4.json","json/15.4.5.json","json/15.5.json","json/15.7.json","json/15.9.json"],"version":"ES5"}
|
||||
{"date":"2011-09-26","numTests":11016,"testSuite":["json/07_Lexical_Conventions.json","json/08_Types.json","json/09_Type_Conversion.json","json/10_Execution_Contexts.json","json/11.10_Binary_Bitwise_Operators.json","json/11.11_Binary_Logical_Operators.json","json/11.12_Conditional_Operator.json","json/11.13_Assignment_Operators.json","json/11.14_Comma_Operator.json","json/11.1_Primary_Expressions.json","json/11.2_Left_Hand_Side_Expressions.json","json/11.3_PostfixExpressions.json","json/11.4_Unary_Operators.json","json/11.5_Multiplicative_Operators.json","json/11.6_Additive_Operators.json","json/11.7_Bitwise_Shift_Operators.json","json/11.8_Relational_Operators.json","json/11.9_Equality_Operators.json","json/12_Statement.json","json/13_Function_Definition.json","json/14_Program.json","json/15.10_RegExp_Objects.json","json/15.11_Error_Objects.json","json/15.12_The_JSON_Object.json","json/15.1_The_Global_Object.json","json/15.2_Object_Objects.json","json/15.3_Function_Objects.json","json/15.4_Array_Objects.json","json/15.5_String_Objects.json","json/15.6_Boolean_Objects.json","json/15.7_Number_Objects.json","json/15.8_The_Math_Object.json","json/15.9_Date_Objects.json","json/chapter07.json","json/chapter08.json","json/chapter10.json","json/chapter11.json","json/chapter12.json","json/chapter13.json","json/chapter14.json","json/15.1.json","json/15.10.json","json/15.11.json","json/15.12.json","json/15.2.3.1.json","json/15.2.3.10.json","json/15.2.3.11.json","json/15.2.3.12.json","json/15.2.3.13.json","json/15.2.3.14.json","json/15.2.3.2.json","json/15.2.3.3.json","json/15.2.3.4.json","json/15.2.3.5.json","json/15.2.3.6.json","json/15.2.3.7.json","json/15.2.3.8.json","json/15.2.3.9.json","json/15.2.4.json","json/15.3.json","json/15.4.3.json","json/15.4.4.10.json","json/15.4.4.12.json","json/15.4.4.14.json","json/15.4.4.15.json","json/15.4.4.16.json","json/15.4.4.17.json","json/15.4.4.18.json","json/15.4.4.19.json","json/15.4.4.20.json","json/15.4.4.21.json","json/15.4.4.22.json","json/15.4.4.4.json","json/15.4.5.json","json/15.5.json","json/15.7.json","json/15.9.json"],"version":"ES5"}
|
Loading…
Reference in New Issue