mirror of https://github.com/tc39/test262.git
Merge pull request #631 from bocoup/annex-b-date
Add tests for Annex B extns to Date.prototype
This commit is contained in:
commit
28e707e367
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Check type of various properties
|
||||
es5id: B.2.4
|
||||
description: Checking properties of the Date object (getYear)
|
||||
---*/
|
||||
|
||||
if (typeof Date.prototype.getYear !== "function") $ERROR('#1: typeof Date.prototype.getYear === "function". Actual: ' + (typeof Date.prototype.getYear ));
|
||||
if (typeof Date.prototype['getYear'] !== "function") $ERROR('#2: typeof Date.prototype["getYear"] === "function". Actual: ' + (typeof Date.prototype["getYear"] ));
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.getyear
|
||||
es6id: B.2.4.1
|
||||
es5id: B.2.4
|
||||
description: NaN time value
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
2. If t is NaN, return NaN.
|
||||
---*/
|
||||
|
||||
var date = new Date({});
|
||||
|
||||
assert.sameValue(date.getYear(), NaN);
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.getyear
|
||||
es6id: B.2.4.1
|
||||
es5id: B.2.4
|
||||
description: >
|
||||
Return value for objects with numeric value in [[DateValue]] internal slot
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
2. If t is NaN, return NaN.
|
||||
3. Return YearFromTime(LocalTime(t)) - 1900.
|
||||
---*/
|
||||
|
||||
assert.sameValue(new Date(1899, 0).getYear(), -1, '1899: first millisecond');
|
||||
assert.sameValue(
|
||||
new Date(1899, 11, 31, 23, 59, 59, 999).getYear(),
|
||||
-1,
|
||||
'1899: final millisecond'
|
||||
);
|
||||
|
||||
assert.sameValue(new Date(1900, 0).getYear(), 0, '1900: first millisecond');
|
||||
assert.sameValue(
|
||||
new Date(1900, 11, 31, 23, 59, 59, 999).getYear(),
|
||||
0,
|
||||
'1900: final millisecond'
|
||||
);
|
||||
|
||||
assert.sameValue(new Date(1970, 0).getYear(), 70, '1970: first millisecond');
|
||||
assert.sameValue(
|
||||
new Date(1970, 11, 31, 23, 59, 59, 999).getYear(),
|
||||
70,
|
||||
'1970: final millisecond'
|
||||
);
|
||||
|
||||
assert.sameValue(new Date(2000, 0).getYear(), 100, '2000: first millisecond');
|
||||
assert.sameValue(
|
||||
new Date(2000, 11, 31, 23, 59, 59, 999).getYear(),
|
||||
100,
|
||||
'2000: final millisecond'
|
||||
);
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.getyear
|
||||
es6id: B.2.4.1
|
||||
es5id: B.2.4
|
||||
description: Behavior when `this` value has no [[DateValue]] internal slot
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
---*/
|
||||
|
||||
var getYear = Date.prototype.getYear;
|
||||
|
||||
assert.sameValue(typeof getYear, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getYear.call({});
|
||||
}, 'object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getYear.call(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getYear.call(null);
|
||||
}, 'null');
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Check type of various properties
|
||||
es5id: B.2.5
|
||||
description: Checking properties of the Date object (setYear)
|
||||
---*/
|
||||
|
||||
if (typeof Date.prototype.setYear !== "function") $ERROR('#1: typeof Date.prototype.setYear === "function". Actual: ' + (typeof Date.prototype.setYear ));
|
||||
if (typeof Date.prototype['setYear'] !== "function") $ERROR('#2: typeof Date.prototype["setYear"] === "function". Actual: ' + (typeof Date.prototype["setYear"] ));
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: Behavior when "this" value has no [[DateValue]] internal slot
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
---*/
|
||||
|
||||
var setYear = Date.prototype.setYear;
|
||||
|
||||
assert.sameValue(typeof setYear, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
setYear.call({}, 1);
|
||||
}, 'object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
setYear.call(undefined, 1);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
setYear.call(null, 1);
|
||||
}, 'null');
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the [[DateValue]] internal slot of "this" value is NaN
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t).
|
||||
---*/
|
||||
|
||||
var date = new Date({});
|
||||
var expected = new Date(1971, 0).valueOf();
|
||||
|
||||
assert.sameValue(date.setYear(71), expected, 'method return value');
|
||||
assert.sameValue(date.valueOf(), expected, '[[DateValue]] internal slot');
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the [[DateValue]] internal slot of "this" value is an integer
|
||||
value
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t).
|
||||
---*/
|
||||
|
||||
var date = new Date(1970, 1, 2, 3, 4, 5);
|
||||
var expected = new Date(1971, 1, 2, 3, 4, 5).valueOf();
|
||||
|
||||
assert.sameValue(date.setYear(71), expected, 'method return value');
|
||||
assert.sameValue(date.valueOf(), expected, '[[DateValue]] internal slot');
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: Clipping of new time value
|
||||
info: |
|
||||
[...]
|
||||
9. Set the [[DateValue]] internal slot of this Date object to
|
||||
TimeClip(date).
|
||||
10. Return the value of the [[DateValue]] internal slot of this Date
|
||||
object.
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date(1970, 8, 12, 20, 0, 0, 0);
|
||||
|
||||
assert.notSameValue(
|
||||
date.setYear(275760), NaN, 'method return value (valid date)'
|
||||
);
|
||||
assert.notSameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (valid date)'
|
||||
);
|
||||
|
||||
date = new Date(1970, 8, 12, 20, 0, 0, 1);
|
||||
|
||||
assert.sameValue(
|
||||
date.setYear(275760), NaN, 'method return value (invalid date)'
|
||||
);
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (invalid date)'
|
||||
);
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: Behavior when year value coerces to NaN
|
||||
info: |
|
||||
[...]
|
||||
3. Let y be ? ToNumber(year).
|
||||
4. If y is NaN, set the [[DateValue]] internal slot of this Date object to
|
||||
NaN and return NaN.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date();
|
||||
assert.sameValue(date.setYear(), NaN, 'return value (no argument)');
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (no argument)'
|
||||
);
|
||||
|
||||
date = new Date();
|
||||
assert.sameValue(date.setYear(NaN), NaN, 'return value (literal NaN)');
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (literal NaN)'
|
||||
);
|
||||
|
||||
date = new Date();
|
||||
assert.sameValue(
|
||||
date.setYear('not a number'), NaN, 'return value (NaN from ToNumber)'
|
||||
);
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (NaN from ToNumber)'
|
||||
);
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the integer representation of the specified `year` is not
|
||||
relative to 1900
|
||||
info: |
|
||||
[...]
|
||||
5. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) +
|
||||
1900.
|
||||
6. Else, let yyyy be y.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(-1);
|
||||
assert.sameValue(date.getFullYear(), -1);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(100);
|
||||
assert.sameValue(date.getFullYear(), 100);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(1899);
|
||||
assert.sameValue(date.getFullYear(), 1899);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(1900);
|
||||
assert.sameValue(date.getFullYear(), 1900);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(1999);
|
||||
assert.sameValue(date.getFullYear(), 1999);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(2000);
|
||||
assert.sameValue(date.getFullYear(), 2000);
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the integer representation of the specified `year` is
|
||||
relative to 1900
|
||||
info: |
|
||||
[...]
|
||||
5. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) +
|
||||
1900.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(-0.9999999);
|
||||
assert.sameValue(date.getFullYear(), 1900, 'y = -0.999999');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(-0);
|
||||
assert.sameValue(date.getFullYear(), 1900, 'y = -0');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(0);
|
||||
assert.sameValue(date.getFullYear(), 1900, 'y = 0');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(50);
|
||||
assert.sameValue(date.getFullYear(), 1950, 'y = 50');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(50.999999);
|
||||
assert.sameValue(date.getFullYear(), 1950, 'y = 50.999999');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(99);
|
||||
assert.sameValue(date.getFullYear(), 1999, 'y = 99');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(99.999999);
|
||||
assert.sameValue(date.getFullYear(), 1999, 'y = 99.999999');
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when calling ToNumber on year value returns an abrupt completion
|
||||
info: |
|
||||
[...]
|
||||
3. Let y be ? ToNumber(year).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var date = new Date();
|
||||
var symbol = Symbol('');
|
||||
var year = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
date.setYear(year);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
date.setYear(symbol);
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Check type of various properties
|
||||
es5id: B.2.6
|
||||
description: Checking properties of the Date object (toGMTString)
|
||||
---*/
|
||||
|
||||
if (typeof Date.prototype.toGMTString !== "function") $ERROR('#1: typeof Date.prototype.toGMTString === "function". Actual: ' + (typeof Date.prototype.toGMTString ));
|
||||
if (typeof Date.prototype['toGMTString'] !== "function") $ERROR('#2: typeof Date.prototype["toGMTString"] === "function". Actual: ' + (typeof Date.prototype["toGMTString"] ));
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (C) 2015 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: B.2.4.3
|
||||
description: >
|
||||
Date.prototype.toGMTString.length is 0.
|
||||
info: >
|
||||
Date.prototype.toGMTString ( )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
Every built-in Function object, including constructors, has a length
|
||||
property whose value is an integer. Unless otherwise specified, this
|
||||
value is equal to the largest number of named arguments shown in the
|
||||
subclause headings for the function description, including optional
|
||||
parameters. However, rest parameters shown using the form “...name”
|
||||
are not included in the default argument count.
|
||||
|
||||
Unless otherwise specified, the length property of a built-in Function
|
||||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Date.prototype.toGMTString.length, 0);
|
||||
|
||||
verifyNotEnumerable(Date.prototype.toGMTString, "length");
|
||||
verifyNotWritable(Date.prototype.toGMTString, "length");
|
||||
verifyConfigurable(Date.prototype.toGMTString, "length");
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2015 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: B.2.4.3
|
||||
description: >
|
||||
Date.prototype.toGMTString.name is "toUTCString".
|
||||
info: >
|
||||
Date.prototype.toGMTString ( )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
Every built-in Function object, including constructors, that is not
|
||||
identified as an anonymous function has a name property whose value
|
||||
is a String.
|
||||
|
||||
Unless otherwise specified, the name property of a built-in Function
|
||||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Date.prototype.toGMTString.name, "toUTCString");
|
||||
|
||||
verifyNotEnumerable(Date.prototype.toGMTString, "name");
|
||||
verifyNotWritable(Date.prototype.toGMTString, "name");
|
||||
verifyConfigurable(Date.prototype.toGMTString, "name");
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-date.prototype.togmtstring
|
||||
es6id: B.2.4.3
|
||||
es5id: B.2.6
|
||||
description: Value of `Date.prototype.toGMTString`
|
||||
info: >
|
||||
The function object that is the initial value of Date.prototype.toGMTString
|
||||
is the same function object that is the initial value of
|
||||
Date.prototype.toUTCString.
|
||||
---*/
|
||||
|
||||
assert.sameValue(Date.prototype.toGMTString, Date.prototype.toUTCString);
|
Loading…
Reference in New Issue