Bug 1769093 - Test262 Update: May 2022 r=yulia

Differential Revision: https://phabricator.services.mozilla.com/D146219
This commit is contained in:
Matthew Gaudet 2022-05-12 17:56:25 +00:00
Родитель 4b7e774817
Коммит b94f0dd091
1106 изменённых файлов: 29286 добавлений и 5352 удалений

Просмотреть файл

@ -671,6 +671,12 @@ fails-if(!xulRuntime.shell) script test262/built-ins/SharedArrayBuffer/prototype
skip script test262/intl402/NumberFormat/prototype/format/format-rounding-priority-more-precision.js
# Update required for https://github.com/tc39/ecma262/pull/2550
# See bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1769088
skip script test262/built-ins/Date/year-zero.js
skip script test262/built-ins/Date/parse/year-zero.js
##############################################
# Enable Iterator Helpers tests in the shell #
##############################################

Просмотреть файл

@ -1,8 +1,5 @@
commit d7c0a2076c2b0c1531aef7069d4abe70eec44ee3
Author: Shu-yu Guo <syg@chromium.org>
Date: Mon Apr 4 16:36:56 2022 -0700
commit 2e7cdfbe18eae4309677033673bb4b5ac6b1de40
Author: legendecas <legendecas@gmail.com>
Date: Mon May 2 22:56:46 2022 +0800
Remove check for per-comparator call detach check in TypedArray.prototype.sort
This updates tests in line with the normative change in
https://github.com/tc39/ecma262/pull/2723
Fix generator clean fail on .DS_Store

Просмотреть файл

@ -18,9 +18,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/
assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);
var a = [];
a.constructor = {};

Просмотреть файл

@ -19,9 +19,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/
assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);
var a = [];
var callCount = 0;
var cb = function() {
@ -33,7 +40,7 @@ a.constructor[Symbol.species] = parseInt;
assert.throws(TypeError, function() {
a.filter(cb);
});
}, 'a.filter(cb) throws a TypeError exception');
assert.sameValue(callCount, 0);
reportCompare(0, 0);

Просмотреть файл

@ -19,9 +19,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/
assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);
var a = [];
var callCount = 0;
var cb = function() {
@ -33,7 +40,7 @@ a.constructor[Symbol.species] = parseInt;
assert.throws(TypeError, function() {
a.map(cb);
});
}, 'a.map(cb) throws a TypeError exception');
assert.sameValue(callCount, 0);
reportCompare(0, 0);

Просмотреть файл

@ -19,9 +19,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/
assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);
var a = [];
a.constructor = {};
@ -29,6 +36,6 @@ a.constructor[Symbol.species] = parseInt;
assert.throws(TypeError, function() {
a.slice();
});
}, 'a.slice() throws a TypeError exception');
reportCompare(0, 0);

Просмотреть файл

@ -19,9 +19,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/
assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);
var a = [];
a.constructor = {};
@ -29,6 +36,6 @@ a.constructor[Symbol.species] = parseInt;
assert.throws(TypeError, function() {
a.splice();
});
}, 'a.splice() throws a TypeError exception');
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,22 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-expanded-years
description: Negative zero, as an extended year, is rejected
info: |
The year 0 is considered positive and must be prefixed with a + sign. The
representation of the year 0 as -000000 is invalid.
---*/
const invalidStrings = [
"-000000-03-31T00:45Z",
"-000000-03-31T01:45",
"-000000-03-31T01:45:00+01:00"
];
for (const str of invalidStrings) {
assert.sameValue(Date.parse(str), NaN, "reject minus zero as extended year");
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,22 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-expanded-years
description: Negative zero, as an extended year, is rejected
info: |
The year 0 is considered positive and must be prefixed with a + sign. The
representation of the year 0 as -000000 is invalid.
---*/
const invalidStrings = [
"-000000-03-31T00:45Z",
"-000000-03-31T01:45",
"-000000-03-31T01:45:00+01:00"
];
for (const str of invalidStrings) {
assert.sameValue(+new Date(str), NaN, "reject minus zero as extended year");
}
reportCompare(0, 0);

Просмотреть файл

@ -12,7 +12,7 @@ info: |
esid: sec-error-message
features: [error-cause]
includes: [deepEqual.js]
includes: [compareArray.js]
---*/
var message = "my-message";
@ -34,6 +34,6 @@ new Error(
},
);
assert.deepEqual(sequence, [ "toString", "cause" ], "accessing own properties on sequence");
assert.compareArray(sequence, [ "toString", "cause" ], "accessing own properties on sequence");
reportCompare(0, 0);

Просмотреть файл

@ -1,333 +1,4 @@
// GENERATED, DO NOT EDIT
// file: deepEqual.js
// Copyright 2019 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Compare two values structurally
defines: [assert.deepEqual]
---*/
assert.deepEqual = function(actual, expected, message) {
var format = assert.deepEqual.format;
assert(
assert.deepEqual._compare(actual, expected),
`Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}`
);
};
assert.deepEqual.format = function(value, seen) {
switch (typeof value) {
case 'string':
return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`;
case 'number':
case 'boolean':
case 'symbol':
case 'bigint':
return value.toString();
case 'undefined':
return 'undefined';
case 'function':
return `[Function${value.name ? `: ${value.name}` : ''}]`;
case 'object':
if (value === null) return 'null';
if (value instanceof Date) return `Date "${value.toISOString()}"`;
if (value instanceof RegExp) return value.toString();
if (!seen) {
seen = {
counter: 0,
map: new Map()
};
}
let usage = seen.map.get(value);
if (usage) {
usage.used = true;
return `[Ref: #${usage.id}]`;
}
usage = { id: ++seen.counter, used: false };
seen.map.set(value, usage);
if (typeof Set !== "undefined" && value instanceof Set) {
return `Set {${Array.from(value).map(value => assert.deepEqual.format(value, seen)).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`;
}
if (typeof Map !== "undefined" && value instanceof Map) {
return `Map {${Array.from(value).map(pair => `${assert.deepEqual.format(pair[0], seen)} => ${assert.deepEqual.format(pair[1], seen)}}`).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`;
}
if (Array.isArray ? Array.isArray(value) : value instanceof Array) {
return `[${value.map(value => assert.deepEqual.format(value, seen)).join(', ')}]${usage.used ? ` as #${usage.id}` : ''}`;
}
let tag = Symbol.toStringTag in value ? value[Symbol.toStringTag] : 'Object';
if (tag === 'Object' && Object.getPrototypeOf(value) === null) {
tag = '[Object: null prototype]';
}
return `${tag ? `${tag} ` : ''}{ ${Object.keys(value).map(key => `${key.toString()}: ${assert.deepEqual.format(value[key], seen)}`).join(', ')} }${usage.used ? ` as #${usage.id}` : ''}`;
default:
return typeof value;
}
};
assert.deepEqual._compare = (function () {
var EQUAL = 1;
var NOT_EQUAL = -1;
var UNKNOWN = 0;
function deepEqual(a, b) {
return compareEquality(a, b) === EQUAL;
}
function compareEquality(a, b, cache) {
return compareIf(a, b, isOptional, compareOptionality)
|| compareIf(a, b, isPrimitiveEquatable, comparePrimitiveEquality)
|| compareIf(a, b, isObjectEquatable, compareObjectEquality, cache)
|| NOT_EQUAL;
}
function compareIf(a, b, test, compare, cache) {
return !test(a)
? !test(b) ? UNKNOWN : NOT_EQUAL
: !test(b) ? NOT_EQUAL : cacheComparison(a, b, compare, cache);
}
function tryCompareStrictEquality(a, b) {
return a === b ? EQUAL : UNKNOWN;
}
function tryCompareTypeOfEquality(a, b) {
return typeof a !== typeof b ? NOT_EQUAL : UNKNOWN;
}
function tryCompareToStringTagEquality(a, b) {
var aTag = Symbol.toStringTag in a ? a[Symbol.toStringTag] : undefined;
var bTag = Symbol.toStringTag in b ? b[Symbol.toStringTag] : undefined;
return aTag !== bTag ? NOT_EQUAL : UNKNOWN;
}
function isOptional(value) {
return value === undefined
|| value === null;
}
function compareOptionality(a, b) {
return tryCompareStrictEquality(a, b)
|| NOT_EQUAL;
}
function isPrimitiveEquatable(value) {
switch (typeof value) {
case 'string':
case 'number':
case 'bigint':
case 'boolean':
case 'symbol':
return true;
default:
return isBoxed(value);
}
}
function comparePrimitiveEquality(a, b) {
if (isBoxed(a)) a = a.valueOf();
if (isBoxed(b)) b = b.valueOf();
return tryCompareStrictEquality(a, b)
|| tryCompareTypeOfEquality(a, b)
|| compareIf(a, b, isNaNEquatable, compareNaNEquality)
|| NOT_EQUAL;
}
function isNaNEquatable(value) {
return typeof value === 'number';
}
function compareNaNEquality(a, b) {
return isNaN(a) && isNaN(b) ? EQUAL : NOT_EQUAL;
}
function isObjectEquatable(value) {
return typeof value === 'object';
}
function compareObjectEquality(a, b, cache) {
if (!cache) cache = new Map();
return getCache(cache, a, b)
|| setCache(cache, a, b, EQUAL) // consider equal for now
|| cacheComparison(a, b, tryCompareStrictEquality, cache)
|| cacheComparison(a, b, tryCompareToStringTagEquality, cache)
|| compareIf(a, b, isValueOfEquatable, compareValueOfEquality)
|| compareIf(a, b, isToStringEquatable, compareToStringEquality)
|| compareIf(a, b, isArrayLikeEquatable, compareArrayLikeEquality, cache)
|| compareIf(a, b, isStructurallyEquatable, compareStructuralEquality, cache)
|| compareIf(a, b, isIterableEquatable, compareIterableEquality, cache)
|| cacheComparison(a, b, fail, cache);
}
function isBoxed(value) {
return value instanceof String
|| value instanceof Number
|| value instanceof Boolean
|| typeof Symbol === 'function' && value instanceof Symbol
|| typeof BigInt === 'function' && value instanceof BigInt;
}
function isValueOfEquatable(value) {
return value instanceof Date;
}
function compareValueOfEquality(a, b) {
return compareIf(a.valueOf(), b.valueOf(), isPrimitiveEquatable, comparePrimitiveEquality)
|| NOT_EQUAL;
}
function isToStringEquatable(value) {
return value instanceof RegExp;
}
function compareToStringEquality(a, b) {
return compareIf(a.toString(), b.toString(), isPrimitiveEquatable, comparePrimitiveEquality)
|| NOT_EQUAL;
}
function isArrayLikeEquatable(value) {
return (Array.isArray ? Array.isArray(value) : value instanceof Array)
|| (typeof Uint8Array === 'function' && value instanceof Uint8Array)
|| (typeof Uint8ClampedArray === 'function' && value instanceof Uint8ClampedArray)
|| (typeof Uint16Array === 'function' && value instanceof Uint16Array)
|| (typeof Uint32Array === 'function' && value instanceof Uint32Array)
|| (typeof Int8Array === 'function' && value instanceof Int8Array)
|| (typeof Int16Array === 'function' && value instanceof Int16Array)
|| (typeof Int32Array === 'function' && value instanceof Int32Array)
|| (typeof Float32Array === 'function' && value instanceof Float32Array)
|| (typeof Float64Array === 'function' && value instanceof Float64Array)
|| (typeof BigUint64Array === 'function' && value instanceof BigUint64Array)
|| (typeof BigInt64Array === 'function' && value instanceof BigInt64Array);
}
function compareArrayLikeEquality(a, b, cache) {
if (a.length !== b.length) return NOT_EQUAL;
for (var i = 0; i < a.length; i++) {
if (compareEquality(a[i], b[i], cache) === NOT_EQUAL) {
return NOT_EQUAL;
}
}
return EQUAL;
}
function isStructurallyEquatable(value) {
return !(typeof Promise === 'function' && value instanceof Promise // only comparable by reference
|| typeof WeakMap === 'function' && value instanceof WeakMap // only comparable by reference
|| typeof WeakSet === 'function' && value instanceof WeakSet // only comparable by reference
|| typeof Map === 'function' && value instanceof Map // comparable via @@iterator
|| typeof Set === 'function' && value instanceof Set); // comparable via @@iterator
}
function compareStructuralEquality(a, b, cache) {
var aKeys = [];
for (var key in a) aKeys.push(key);
var bKeys = [];
for (var key in b) bKeys.push(key);
if (aKeys.length !== bKeys.length) {
return NOT_EQUAL;
}
aKeys.sort();
bKeys.sort();
for (var i = 0; i < aKeys.length; i++) {
var aKey = aKeys[i];
var bKey = bKeys[i];
if (compareEquality(aKey, bKey, cache) === NOT_EQUAL) {
return NOT_EQUAL;
}
if (compareEquality(a[aKey], b[bKey], cache) === NOT_EQUAL) {
return NOT_EQUAL;
}
}
return compareIf(a, b, isIterableEquatable, compareIterableEquality, cache)
|| EQUAL;
}
function isIterableEquatable(value) {
return typeof Symbol === 'function'
&& typeof value[Symbol.iterator] === 'function';
}
function compareIteratorEquality(a, b, cache) {
if (typeof Map === 'function' && a instanceof Map && b instanceof Map ||
typeof Set === 'function' && a instanceof Set && b instanceof Set) {
if (a.size !== b.size) return NOT_EQUAL; // exit early if we detect a difference in size
}
var ar, br;
while (true) {
ar = a.next();
br = b.next();
if (ar.done) {
if (br.done) return EQUAL;
if (b.return) b.return();
return NOT_EQUAL;
}
if (br.done) {
if (a.return) a.return();
return NOT_EQUAL;
}
if (compareEquality(ar.value, br.value, cache) === NOT_EQUAL) {
if (a.return) a.return();
if (b.return) b.return();
return NOT_EQUAL;
}
}
}
function compareIterableEquality(a, b, cache) {
return compareIteratorEquality(a[Symbol.iterator](), b[Symbol.iterator](), cache);
}
function cacheComparison(a, b, compare, cache) {
var result = compare(a, b, cache);
if (cache && (result === EQUAL || result === NOT_EQUAL)) {
setCache(cache, a, b, /** @type {EQUAL | NOT_EQUAL} */(result));
}
return result;
}
function fail() {
return NOT_EQUAL;
}
function setCache(cache, left, right, result) {
var otherCache;
otherCache = cache.get(left);
if (!otherCache) cache.set(left, otherCache = new Map());
otherCache.set(right, result);
otherCache = cache.get(right);
if (!otherCache) cache.set(right, otherCache = new Map());
otherCache.set(left, result);
}
function getCache(cache, left, right) {
var otherCache;
var result;
otherCache = cache.get(left);
result = otherCache && otherCache.get(right);
if (result) return result;
otherCache = cache.get(right);
result = otherCache && otherCache.get(left);
if (result) return result;
return UNKNOWN;
}
return deepEqual;
})();
// file: isConstructor.js
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

Просмотреть файл

@ -13,12 +13,15 @@ info: |
5. Let targetHasLength be ? HasOwnProperty(Target, "length").
6. If targetHasLength is true, then
a. Let targetLen be ? Get(Target, "length").
b. If Type(targetLen) is not Number, let L be 0.
c. Else,
i. Set targetLen to ! ToInteger(targetLen).
ii. Let L be the larger of 0 and the result of targetLen minus the number of elements of args.
7. Else, let L be 0.
8. Perform ! SetFunctionLength(F, L).
b. If Type(targetLen) is Number, then
i. If targetLen is +𝔽, set L to +.
ii. Else if targetLen is -𝔽, set L to 0.
iii. Else,
1. Let targetLenAsInt be ! ToIntegerOrInfinity(targetLen).
2. Assert: targetLenAsInt is finite.
3. Let argCount be the number of elements in args.
4. Set L to max(targetLenAsInt - argCount, 0).
7. Perform ! SetFunctionLength(F, L).
[...]
ToInteger ( argument )
@ -40,10 +43,12 @@ Object.defineProperty(fn, "length", {value: -0});
assert.sameValue(fn.bind().length, 0);
Object.defineProperty(fn, "length", {value: Infinity});
assert.sameValue(fn.bind().length, Infinity);
assert.sameValue(fn.bind().length, Infinity, "target length of infinity, zero bound arguments");
assert.sameValue(fn.bind(0, 0).length, Infinity, "target length of infinity, one bound argument");
Object.defineProperty(fn, "length", {value: -Infinity});
assert.sameValue(fn.bind().length, 0);
assert.sameValue(fn.bind().length, 0, "target length of negative infinity, zero bound arguments");
assert.sameValue(fn.bind(0, 0).length, 0, "target length of negative infinity, one bound argument");
Object.defineProperty(fn, "length", {value: 3.66});
assert.sameValue(fn.bind().length, 3);

Просмотреть файл

@ -27,7 +27,7 @@ info: |
a. Let realm be ? GetFunctionRealm(constructor).
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
Return proto.
features: [AggregateError]
features: [AggregateError, Reflect.construct]
---*/
var custom = { x: 42 };

Просмотреть файл

@ -53,7 +53,7 @@ function printStringCodePoints(string) {
function testPropertyEscapes(regExp, string, expression) {
if (!regExp.test(string)) {
for (const symbol of string) {
printCodePoint(symbol.codePointAt(0));
const hex = printCodePoint(symbol.codePointAt(0));
assert(
regExp.test(symbol),
`\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)`

Просмотреть файл

@ -53,7 +53,7 @@ function printStringCodePoints(string) {
function testPropertyEscapes(regExp, string, expression) {
if (!regExp.test(string)) {
for (const symbol of string) {
printCodePoint(symbol.codePointAt(0));
const hex = printCodePoint(symbol.codePointAt(0));
assert(
regExp.test(symbol),
`\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)`

Просмотреть файл

@ -90,7 +90,7 @@ function printStringCodePoints(string) {
function testPropertyEscapes(regExp, string, expression) {
if (!regExp.test(string)) {
for (const symbol of string) {
printCodePoint(symbol.codePointAt(0));
const hex = printCodePoint(symbol.codePointAt(0));
assert(
regExp.test(symbol),
`\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)`

Просмотреть файл

@ -5,6 +5,8 @@
info: RegExp.prototype.toString has not prototype property
es5id: 15.10.6.4_A6
description: Checking RegExp.prototype.toString.prototype
includes: [isConstructor.js]
features: [Reflect.construct]
---*/
assert.sameValue(
RegExp.prototype.toString.prototype,
@ -12,4 +14,10 @@ assert.sameValue(
'The value of RegExp.prototype.toString.prototype is expected to equal undefined'
);
assert.sameValue(
isConstructor(RegExp.prototype.toString),
false,
'isConstructor(RegExp.prototype.toString) must return false'
);
reportCompare(0, 0);

Просмотреть файл

@ -5,6 +5,8 @@
info: RegExp.prototype.toString can't be used as constructor
es5id: 15.10.6.4_A7
description: Checking if creating the RegExp.prototype.toString object fails
includes: [isConstructor.js]
features: [Reflect.construct]
---*/
var __FACTORY = RegExp.prototype.toString;
@ -20,6 +22,12 @@ try {
);
}
assert.sameValue(
isConstructor(RegExp.prototype.toString),
false,
'isConstructor(RegExp.prototype.toString) must return false'
);
// TODO: Convert to assert.throws() format.
reportCompare(0, 0);

Просмотреть файл

@ -90,7 +90,7 @@ function printStringCodePoints(string) {
function testPropertyEscapes(regExp, string, expression) {
if (!regExp.test(string)) {
for (const symbol of string) {
printCodePoint(symbol.codePointAt(0));
const hex = printCodePoint(symbol.codePointAt(0));
assert(
regExp.test(symbol),
`\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)`

Просмотреть файл

@ -66,4 +66,28 @@ assert.sameValue(
'globalThis.constructor is Object'
);
assert.sameValue(
r.evaluate(`
let result;
try {
globalThis.__proto__ = {x: 2};
result = true;
} catch (e) {
result = false;
}
result;
`),
true,
'Can assign to globalThis.__proto__ directly'
);
assert.sameValue(
r.evaluate(`
Reflect.set(globalThis, '__proto__', {x: 1}) &&
Reflect.setPrototypeOf(globalThis.__proto__, {x: 2});
`),
true,
'Can set an ordinary globalThis.__proto__'
);
reportCompare(0, 0);

Просмотреть файл

@ -4,7 +4,7 @@
/*---
esid: sec-shadowrealm.prototype.importvalue
description: >
ShadowRealm.prototype.importValue coerces exportName to string.
ShadowRealm.prototype.importValue throws if exportName is not a string.
features: [ShadowRealm]
---*/
@ -24,10 +24,10 @@ const exportName = {
}
};
assert.throws(Test262Error, () => {
assert.throws(TypeError, () => {
r.importValue('', exportName);
});
assert.sameValue(count, 1);
assert.sameValue(count, 0);
reportCompare(0, 0);

Просмотреть файл

@ -90,7 +90,7 @@ function printStringCodePoints(string) {
function testPropertyEscapes(regExp, string, expression) {
if (!regExp.test(string)) {
for (const symbol of string) {
printCodePoint(symbol.codePointAt(0));
const hex = printCodePoint(symbol.codePointAt(0));
assert(
regExp.test(symbol),
`\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)`

Просмотреть файл

@ -0,0 +1,30 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: A number is converted to a string, then to Temporal.Calendar
features: [Temporal]
---*/
const arg = 19761118;
const result = Temporal.Calendar.from(arg);
assert.sameValue(result.id, "iso8601", "19761118 is a valid ISO string for Calendar");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => Temporal.Calendar.from(arg),
`Number ${arg} does not convert to a valid ISO string for Calendar`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/
let arg = "2016-12-31T23:59:60";
const result1 = Temporal.Calendar.from(arg);
assert.sameValue(
result1.id,
"iso8601",
"leap second is a valid ISO string for Calendar"
);
arg = { calendar: "2016-12-31T23:59:60" };
const result2 = Temporal.Calendar.from(arg);
assert.sameValue(
result2.id,
"iso8601",
"leap second is a valid ISO string for Calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,33 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for Calendar
features: [BigInt, Symbol, Temporal]
---*/
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => Temporal.Calendar.from(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Calendar.from(arg), `${description} is not a valid object and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -0,0 +1,33 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: A number is converted to a string, then to Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Leap second is a valid ISO string for a calendar in a property bag
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result1,
1976, 11, "M11", 18,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result2,
1976, 11, "M11", 18,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,45 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: A number as calendar in a property bag is converted to a string, then to a calendar
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -56,7 +56,7 @@ const instance = new Temporal.Calendar("iso8601");
for (const arg of invalidStrings) {
assert.throws(
RangeError,
() => instance.dateAdd(arg),
() => instance.dateAdd(arg, new Temporal.Duration()),
`"${arg}" should not be a valid ISO string for a PlainDate`
);
}

Просмотреть файл

@ -16,7 +16,7 @@ const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg),
() => instance.dateAdd(arg, new Temporal.Duration()),
"String with UTC designator should not be valid as a PlainDate"
);
});

Просмотреть файл

@ -0,0 +1,39 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,30 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Leap second is a valid ISO string for PlainDate
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result1,
2016, 12, "M12", 31,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result2,
2016, 12, "M12", 31,
"second: 60 is ignored in property bag for PlainDate"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,26 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: TypeError thrown when options argument is a primitive
features: [BigInt, Symbol, Temporal]
---*/
const badOptions = [
null,
true,
"some string",
Symbol(),
1,
2n,
];
const instance = new Temporal.Calendar("iso8601");
for (const value of badOptions) {
assert.throws(TypeError, () => instance.dateAdd(new Temporal.PlainDate(1976, 11, 18), new Temporal.Duration(1), value),
`TypeError on wrong options type ${typeof value}`);
};
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -8,13 +8,19 @@ description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const arg = "-000000-10-31";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
assert.throws(
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => { instance.dateAdd(arg); },
() => instance.dateAdd(arg, new Temporal.Duration()),
"reject minus zero as extended year"
);
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,26 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.datefromfields
description: TypeError thrown when options argument is a primitive
features: [BigInt, Symbol, Temporal]
---*/
const badOptions = [
null,
true,
"some string",
Symbol(),
1,
2n,
];
const instance = new Temporal.Calendar("iso8601");
for (const value of badOptions) {
assert.throws(TypeError, () => instance.dateFromFields({ year: 1976, month: 11, day: 18 }, value),
`TypeError on wrong options type ${typeof value}`);
};
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -0,0 +1,40 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: A number is converted to a string, then to Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (second argument)");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 18)),
`Number ${arg} does not convert to a valid ISO string for PlainDate (first argument)`
);
assert.throws(
RangeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 18), arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate (second argument)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,28 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: Leap second is a valid ISO string for a calendar in a property bag
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (second argument)");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (nested property, first argument)");
const result4 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result4, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (nested property, second argument)");
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,59 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: A number as calendar in a property bag is converted to a string, then to a calendar
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (second argument)");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)");
const result4 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result4, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property, second argument)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
`Number ${calendar} does not convert to a valid ISO string for calendar (first argument)`
);
assert.throws(
RangeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (second argument)`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property, first argument)`
);
assert.throws(
RangeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property, second argument)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,55 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (first argument)`);
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (second argument)`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (nested property, first argument)`);
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (nested property, second argument)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (first argument)`);
assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (nested property, first argument)`);
assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} is not a valid property bag and does not convert to a string (nested property, second argument)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `nested undefined calendar property is always a RangeError (first argument)`);
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `nested undefined calendar property is always a RangeError (second argument)`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
"reject minus zero as extended year (first argument)"
);
assert.throws(
RangeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
"reject minus zero as extended year (second argument)"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,42 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (first argument)`);
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (first argument)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (second argument)`);
assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,26 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: Leap second is a valid ISO string for PlainDate
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
let result = instance.dateUntil(arg, new Temporal.PlainDate(2017, 1, 1));
TemporalHelpers.assertDuration(result, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for PlainDate (first argument)");
result = instance.dateUntil(new Temporal.PlainDate(2017, 1, 1), arg);
TemporalHelpers.assertDuration(result, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for PlainDate (second argument)");
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
result = instance.dateUntil(arg, new Temporal.PlainDate(2017, 1, 1));
TemporalHelpers.assertDuration(result, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "second: 60 is ignored in property bag for PlainDate (first argument)");
result = instance.dateUntil(new Temporal.PlainDate(2017, 1, 1), arg);
TemporalHelpers.assertDuration(result, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "second: 60 is ignored in property bag for PlainDate (second argument)");
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,26 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: TypeError thrown when options argument is a primitive
features: [BigInt, Symbol, Temporal]
---*/
const badOptions = [
null,
true,
"some string",
Symbol(),
1,
2n,
];
const instance = new Temporal.Calendar("iso8601");
for (const value of badOptions) {
assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1976, 11, 18), new Temporal.PlainDate(1984, 5, 31), value),
`TypeError on wrong options type ${typeof value}`);
};
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -10,18 +10,25 @@ features: [Temporal]
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2);
const bad = "-000000-03-14";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
assert.throws(
RangeError,
() => calendar.dateUntil(bad, date),
"cannot use minus zero as extended date (first argument)"
);
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => calendar.dateUntil(arg, date),
"cannot use minus zero as extended date (first argument)"
);
assert.throws(
RangeError,
() => calendar.dateUntil(date, bad),
"cannot use minus zero as extended date (second argument)"
);
assert.throws(
RangeError,
() => calendar.dateUntil(date, arg),
"cannot use minus zero as extended date (second argument)"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: A number is converted to a string, then to Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.day(arg);
assert.sameValue(result, 18, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.day(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,31 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: Leap second is a valid ISO string for a calendar in a property bag
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.day(arg);
assert.sameValue(
result1,
18,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.day(arg);
assert.sameValue(
result2,
18,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,44 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: A number as calendar in a property bag is converted to a string, then to a calendar
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.day(arg);
assert.sameValue(result1, 18, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.day(arg);
assert.sameValue(result2, 18, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.day(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.day(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.day(arg), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.day(arg), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.day(arg), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.day(arg),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,39 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.day(arg), `${description} is not a valid property bag and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,29 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: Leap second is a valid ISO string for PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.day(arg);
assert.sameValue(
result1,
31,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.day(arg);
assert.sameValue(
result2,
31,
"second: 60 is ignored in property bag for PlainDate"
);
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -8,13 +8,19 @@ description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const arg = "-000000-10-31";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
assert.throws(
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => { instance.day(arg); },
() => instance.day(arg),
"reject minus zero as extended year"
);
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: A number is converted to a string, then to Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.dayOfWeek(arg);
assert.sameValue(result, 4, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.dayOfWeek(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,31 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: Leap second is a valid ISO string for a calendar in a property bag
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dayOfWeek(arg);
assert.sameValue(
result1,
4,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dayOfWeek(arg);
assert.sameValue(
result2,
4,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,44 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: A number as calendar in a property bag is converted to a string, then to a calendar
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dayOfWeek(arg);
assert.sameValue(result1, 4, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dayOfWeek(arg);
assert.sameValue(result2, 4, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.dayOfWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.dayOfWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.dayOfWeek(arg), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.dayOfWeek(arg), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.dayOfWeek(arg), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dayOfWeek(arg),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,39 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.dayOfWeek(arg), `${description} is not a valid property bag and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,29 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: Leap second is a valid ISO string for PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.dayOfWeek(arg);
assert.sameValue(
result1,
6,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.dayOfWeek(arg);
assert.sameValue(
result2,
6,
"second: 60 is ignored in property bag for PlainDate"
);
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -8,13 +8,19 @@ description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const arg = "-000000-10-31";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
assert.throws(
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => { instance.dayOfWeek(arg); },
() => instance.dayOfWeek(arg),
"reject minus zero as extended year"
);
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: A number is converted to a string, then to Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.dayOfYear(arg);
assert.sameValue(result, 323, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.dayOfYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,31 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Leap second is a valid ISO string for a calendar in a property bag
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dayOfYear(arg);
assert.sameValue(
result1,
323,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dayOfYear(arg);
assert.sameValue(
result2,
323,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,44 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: A number as calendar in a property bag is converted to a string, then to a calendar
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dayOfYear(arg);
assert.sameValue(result1, 323, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dayOfYear(arg);
assert.sameValue(result2, 323, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.dayOfYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.dayOfYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.dayOfYear(arg), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.dayOfYear(arg), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.dayOfYear(arg), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dayOfYear(arg),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,39 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.dayOfYear(arg), `${description} is not a valid property bag and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,29 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Leap second is a valid ISO string for PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.dayOfYear(arg);
assert.sameValue(
result1,
366,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.dayOfYear(arg);
assert.sameValue(
result2,
366,
"second: 60 is ignored in property bag for PlainDate"
);
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -8,13 +8,19 @@ description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const arg = "-000000-10-31";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
assert.throws(
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => { instance.dayOfYear(arg); },
() => instance.dayOfYear(arg),
"reject minus zero as extended year"
);
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: A number is converted to a string, then to Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.daysInMonth(arg);
assert.sameValue(result, 30, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.daysInMonth(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,31 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: Leap second is a valid ISO string for a calendar in a property bag
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInMonth(arg);
assert.sameValue(
result1,
30,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInMonth(arg);
assert.sameValue(
result2,
30,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,44 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: A number as calendar in a property bag is converted to a string, then to a calendar
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInMonth(arg);
assert.sameValue(result1, 30, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInMonth(arg);
assert.sameValue(result2, 30, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.daysInMonth(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.daysInMonth(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.daysInMonth(arg), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.daysInMonth(arg), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.daysInMonth(arg), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.daysInMonth(arg),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,39 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.daysInMonth(arg), `${description} is not a valid property bag and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,29 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinmonth
description: Leap second is a valid ISO string for PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.daysInMonth(arg);
assert.sameValue(
result1,
31,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.daysInMonth(arg);
assert.sameValue(
result2,
31,
"second: 60 is ignored in property bag for PlainDate"
);
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -8,13 +8,19 @@ description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const arg = "-000000-10-31";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
assert.throws(
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => { instance.daysInMonth(arg); },
() => instance.daysInMonth(arg),
"reject minus zero as extended year"
);
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: A number is converted to a string, then to Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.daysInWeek(arg);
assert.sameValue(result, 7, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.daysInWeek(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,31 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: Leap second is a valid ISO string for a calendar in a property bag
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInWeek(arg);
assert.sameValue(
result1,
7,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInWeek(arg);
assert.sameValue(
result2,
7,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,44 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: A number as calendar in a property bag is converted to a string, then to a calendar
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInWeek(arg);
assert.sameValue(result1, 7, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInWeek(arg);
assert.sameValue(result2, 7, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.daysInWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.daysInWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.daysInWeek(arg), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.daysInWeek(arg), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.daysInWeek(arg), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.daysInWeek(arg),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,39 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.daysInWeek(arg), `${description} is not a valid property bag and does not convert to a string`);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,29 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinweek
description: Leap second is a valid ISO string for PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.daysInWeek(arg);
assert.sameValue(
result1,
7,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.daysInWeek(arg);
assert.sameValue(
result2,
7,
"second: 60 is ignored in property bag for PlainDate"
);
reportCompare(0, 0);

Просмотреть файл

@ -172,20 +172,21 @@ var TemporalHelpers = {
},
/*
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
*
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) {
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
assert.sameValue(yearMonth.era, era, `${description} era result`);
assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`);
assert.sameValue(yearMonth.year, year, `${description} year result`);
assert.sameValue(yearMonth.month, month, `${description} month result`);
assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`);
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
},
/*
@ -259,39 +260,6 @@ var TemporalHelpers = {
});
},
/*
* checkFractionalSecondDigitsOptionWrongType(temporalObject):
*
* Checks the string-or-number type handling of the fractionalSecondDigits
* option to the various types' toString() methods. temporalObject is an
* instance of the Temporal type under test.
*/
checkFractionalSecondDigitsOptionWrongType(temporalObject) {
// null is not a number, and converts to the string "null", which is an invalid string value
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: null }), "null");
// Booleans are not numbers, and convert to the strings "true" or "false", which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: true }), "true");
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: false }), "false");
// Symbols are not numbers and cannot convert to strings
assert.throws(TypeError, () => temporalObject.toString({ fractionalSecondDigits: Symbol() }), "symbol");
// BigInts are not numbers and convert to strings which are invalid
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: 2n }), "bigint");
// Objects are not numbers and prefer their toString() methods when converting to a string
assert.throws(RangeError, () => temporalObject.toString({ fractionalSecondDigits: {} }), "plain object");
const toStringExpected = temporalObject.toString({ fractionalSecondDigits: 'auto' });
const expected = [
"get fractionalSecondDigits.toString",
"call fractionalSecondDigits.toString",
];
const actual = [];
const observer = TemporalHelpers.toPrimitiveObserver(actual, "auto", "fractionalSecondDigits");
const result = temporalObject.toString({ fractionalSecondDigits: observer });
assert.sameValue(result, toStringExpected, "object with toString");
assert.compareArray(actual, expected, "order of operations");
},
/*
* checkPlainDateTimeConversionFastPath(func):
*

Просмотреть файл

@ -8,13 +8,19 @@ description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const arg = "-000000-10-31";
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
assert.throws(
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => { instance.daysInWeek(arg); },
() => instance.daysInWeek(arg),
"reject minus zero as extended year"
);
);
});
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,32 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinyear
description: A number is converted to a string, then to Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.daysInYear(arg);
assert.sameValue(result, 366, "19761118 is a valid ISO string for PlainDate");
const numbers = [
1,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
RangeError,
() => instance.daysInYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,31 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinyear
description: Leap second is a valid ISO string for a calendar in a property bag
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInYear(arg);
assert.sameValue(
result1,
366,
"leap second is a valid ISO string for calendar"
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInYear(arg);
assert.sameValue(
result2,
366,
"leap second is a valid ISO string for calendar (nested property)"
);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,44 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinyear
description: A number as calendar in a property bag is converted to a string, then to a calendar
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInYear(arg);
assert.sameValue(result1, 366, "19970327 is a valid ISO string for calendar");
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInYear(arg);
assert.sameValue(result2, 366, "19970327 is a valid ISO string for calendar (nested property)");
const numbers = [
1,
-19970327,
1234567890,
];
for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.daysInYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.daysInYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,50 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinyear
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.daysInYear(arg), `${description} does not convert to a valid ISO string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.daysInYear(arg), `${description} does not convert to a valid ISO string (nested property)`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"], // TypeError due to missing dateFromFields()
[Temporal.Calendar, "Temporal.Calendar, object"], // ditto
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.daysInYear(arg), `${description} is not a valid property bag and does not convert to a string`);
arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.daysInYear(arg), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}
const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.daysInYear(arg), `nested undefined calendar property is always a RangeError`);
reportCompare(0, 0);

Просмотреть файл

@ -0,0 +1,27 @@
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.daysinyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.daysInYear(arg),
"reject minus zero as extended year"
);
});
reportCompare(0, 0);

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше