From 0232d97415ea8334709d6c90d98acf33c302b8d5 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Fri, 10 Sep 2021 17:25:34 -0400 Subject: [PATCH] Add tests for Temporal.Now.plainDateTimeISO --- .../Now/plainDateTimeISO/extensible.js | 12 +++ .../Temporal/Now/plainDateTimeISO/length.js | 25 ++++++ .../Temporal/Now/plainDateTimeISO/name.js | 20 +++++ .../Now/plainDateTimeISO/not-a-constructor.js | 14 ++++ .../Now/plainDateTimeISO/prop-desc.js | 14 ++++ .../Now/plainDateTimeISO/return-value.js | 18 +++++ .../plainDateTimeISO/time-zone-undefined.js | 35 +++++++++ ...zone-getoffsetnanosecondsfor-invocation.js | 28 +++++++ ...one-getoffsetnanosecondsfor-non-integer.js | 17 ++++ ...zone-getoffsetnanosecondsfor-non-method.js | 15 ++++ ...ne-getoffsetnanosecondsfor-not-a-number.js | 37 +++++++++ ...ne-getoffsetnanosecondsfor-out-of-range.js | 17 ++++ ...mezone-getoffsetnanosecondsfor-poisoned.js | 17 ++++ ...timezone-getoffsetnanosecondsfor-throws.js | 17 ++++ ...zone-getoffsetnanosecondsfor-wrong-type.js | 21 +++++ .../timezone-object-fail-call-tostring.js | 20 +++++ .../timezone-object-fail-get-timezone.js | 17 ++++ ...imezone-object-fail-has-nested-timezone.js | 21 +++++ .../timezone-object-fail-has-timezone.js | 19 +++++ .../Now/plainDateTimeISO/timezone-object.js | 77 +++++++++++++++++++ .../timezone-string-datetime.js | 24 ++++++ 21 files changed, 485 insertions(+) create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/extensible.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/length.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/name.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/not-a-constructor.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/prop-desc.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/return-value.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/time-zone-undefined.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-invocation.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-integer.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-method.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-not-a-number.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-out-of-range.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-poisoned.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-throws.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-wrong-type.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-call-tostring.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-get-timezone.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-nested-timezone.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-timezone.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string-datetime.js diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/extensible.js b/test/built-ins/Temporal/Now/plainDateTimeISO/extensible.js new file mode 100644 index 0000000000..91742a5556 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/extensible.js @@ -0,0 +1,12 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Temporal.Now.plainDateTimeISO is extensible. +features: [Temporal] +---*/ + +assert( + Object.isExtensible(Temporal.Now.plainDateTimeISO), + 'Object.isExtensible(Temporal.Now.plainDateTimeISO) must return true' +); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/length.js b/test/built-ins/Temporal/Now/plainDateTimeISO/length.js new file mode 100644 index 0000000000..50b51971b2 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/length.js @@ -0,0 +1,25 @@ +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: The `length` property of Temporal.Now.plainDateTimeISO +info: | + Every built-in function object, including constructors, has a "length" property whose value is + an integer. Unless otherwise specified, this value is equal to the largest number of named + arguments shown in the subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which are shown using the form + «...name») are not included in the default argument count. + + Unless otherwise specified, the "length" property of a built-in function object has the + attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Temporal] +---*/ + +verifyProperty(Temporal.Now.plainDateTimeISO, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/name.js b/test/built-ins/Temporal/Now/plainDateTimeISO/name.js new file mode 100644 index 0000000000..dc3dbb4651 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/name.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plainDateTimeISO +description: Temporal.Now.plainDateTimeISO.name is "plainDateTimeISO". +includes: [propertyHelper.js] +features: [Temporal] +---*/ + +assert.sameValue( + Temporal.Now.plainDateTimeISO.name, + 'plainDateTimeISO', + 'The value of Temporal.Now.plainDateTimeISO.name is expected to be "plainDateTimeISO"' +); + +verifyProperty(Temporal.Now.plainDateTimeISO, 'name', { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/not-a-constructor.js b/test/built-ins/Temporal/Now/plainDateTimeISO/not-a-constructor.js new file mode 100644 index 0000000000..e432b8970a --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/not-a-constructor.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Temporal.Now.plainDateTimeISO does not implement [[Construct]] +includes: [isConstructor.js] +features: [Reflect.construct, Temporal, arrow-function] +---*/ + +assert.sameValue(isConstructor(Temporal.Now.plainDateTimeISO), false, 'isConstructor(Temporal.Now.plainDateTimeISO) must return false'); + +assert.throws(TypeError, () => { + new Temporal.Now.plainDateTimeISO(); +}, 'new Temporal.Now.plainDateTimeISO() throws a TypeError exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/prop-desc.js b/test/built-ins/Temporal/Now/plainDateTimeISO/prop-desc.js new file mode 100644 index 0000000000..8f764a6bf0 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/prop-desc.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: The "plainDateTimeISO" property of Temporal.Now +includes: [propertyHelper.js] +features: [Temporal] +---*/ + +verifyProperty(Temporal.Now, 'plainDateTimeISO', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/return-value.js b/test/built-ins/Temporal/Now/plainDateTimeISO/return-value.js new file mode 100644 index 0000000000..c0de72cb6d --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/return-value.js @@ -0,0 +1,18 @@ +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Return value describes the start of a day +features: [BigInt, Temporal] +---*/ +const timeZone = { + getOffsetNanosecondsFor(instant) { + return -Number(instant.epochNanoseconds % 86400000000000n); + } +}; + +const result = Temporal.Now.plainDateTimeISO(timeZone); + +for (const property of ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']) { + assert.sameValue(result[property], 0, 'The value of result[property] is expected to be 0'); +} diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/time-zone-undefined.js b/test/built-ins/Temporal/Now/plainDateTimeISO/time-zone-undefined.js new file mode 100644 index 0000000000..6d719c2e91 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/time-zone-undefined.js @@ -0,0 +1,35 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Functions when time zone argument is omitted +includes: [compareArray.js] +features: [Temporal] +---*/ + +const actual = []; +const expected = []; + +Object.defineProperty(Temporal.TimeZone, "from", { + get() { + actual.push("get Temporal.TimeZone.from"); + return undefined; + }, +}); + +const resultExplicit = Temporal.Now.plainDateTimeISO(undefined); +assert( + resultExplicit instanceof Temporal.PlainDateTime, + 'The result of evaluating (resultExplicit instanceof Temporal.PlainDateTime) is expected to be true' +); + +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); + +const resultImplicit = Temporal.Now.plainDateTimeISO(); +assert( + resultImplicit instanceof Temporal.PlainDateTime, + 'The result of evaluating (resultImplicit instanceof Temporal.PlainDateTime) is expected to be true' +); + +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-invocation.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-invocation.js new file mode 100644 index 0000000000..4cf8cd2011 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-invocation.js @@ -0,0 +1,28 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Correctly invokes `getOffsetNanosecondsFor` method of TimeZone-like objects +features: [Temporal] +---*/ + +var calls = []; +var timeZone = { + getOffsetNanosecondsFor: function() { + calls.push({ + args: arguments, + this: this + }); + return 0; + }, +}; + +Temporal.Now.plainDateTimeISO(timeZone); + +assert.sameValue(calls.length, 1, 'The value of calls.length is expected to be 1'); +assert.sameValue(calls[0].args.length, 1, 'The value of calls[0].args.length is expected to be 1'); +assert( + calls[0].args[0] instanceof Temporal.Instant, + 'The result of evaluating (calls[0].args[0] instanceof Temporal.Instant) is expected to be true' +); +assert.sameValue(calls[0].this, timeZone, 'The value of calls[0].this is expected to equal the value of timeZone'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-integer.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-integer.js new file mode 100644 index 0000000000..4cbb76f254 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-integer.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds +features: [Temporal, arrow-function] +includes: [temporalHelpers.js] +---*/ +[3600000000000.5, NaN].forEach(wrongOffset => { + const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); + + assert.throws( + RangeError, + () => Temporal.Now.plainDateTimeISO(timeZone), + 'Temporal.Now.plainDateTimeISO(timeZone) throws a RangeError exception' + ); +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-method.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-method.js new file mode 100644 index 0000000000..9b46ca6c9d --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-non-method.js @@ -0,0 +1,15 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Rejects when `getOffsetNanosecondsFor` property is not a method +features: [Temporal] +---*/ + +var timeZone = { + getOffsetNanosecondsFor: 7 +}; + +assert.throws(TypeError, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a TypeError exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-not-a-number.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-not-a-number.js new file mode 100644 index 0000000000..57f5304812 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-not-a-number.js @@ -0,0 +1,37 @@ +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Rejects non-numeric nanosecond values reported by TimeZone-like object +features: [BigInt, Symbol, Temporal, arrow-function] +---*/ +const invalidValues = [ + undefined, + null, + true, + '2020-01-01T12:45:36', + Symbol(), + 2n, + {}, + Temporal.PlainDateTime, + Temporal.PlainDateTime.prototype +]; + +for (const dateTime of invalidValues) { + let callCount = 0; + + const timeZone = { + getOffsetNanosecondsFor(instant, calendar) { + callCount += 1; + return dateTime; + } + }; + + assert.throws( + TypeError, + () => Temporal.Now.plainDateTimeISO(timeZone), + 'Temporal.Now.plainDateTimeISO(timeZone) throws a TypeError exception' + ); + + assert.sameValue(callCount, 1, 'The value of callCount is expected to be 1'); +} diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-out-of-range.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-out-of-range.js new file mode 100644 index 0000000000..7e2f9db70a --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-out-of-range.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: RangeError thrown if time zone reports an offset that is out of range +features: [Temporal, arrow-function] +includes: [temporalHelpers.js] +---*/ +[-86400000000001, 86400000000001, -Infinity, Infinity].forEach(wrongOffset => { + const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); + + assert.throws( + RangeError, + () => Temporal.Now.plainDateTimeISO(timeZone), + 'Temporal.Now.plainDateTimeISO(timeZone) throws a RangeError exception' + ); +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-poisoned.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-poisoned.js new file mode 100644 index 0000000000..822e6a6b6d --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-poisoned.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Forwards error when accessing `getOffsetNanosecondsFor` property throws +features: [Temporal] +---*/ + +var timeZone = { + get getOffsetNanosecondsFor() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a Test262Error exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-throws.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-throws.js new file mode 100644 index 0000000000..2c87fdf471 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-throws.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Forwards error when `getOffsetNanosecondsFor` throws +features: [Temporal] +---*/ + +var timeZone = { + getOffsetNanosecondsFor() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a Test262Error exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-wrong-type.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-wrong-type.js new file mode 100644 index 0000000000..6c31922e85 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-getoffsetnanosecondsfor-wrong-type.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: TypeError thrown if time zone reports an offset that is not a Number +features: [BigInt, Symbol, Temporal, arrow-function] +includes: [temporalHelpers.js] +---*/ +[undefined, null, true, '+01:00', Symbol(), 3600000000000n, {}, { + valueOf() { + return 3600000000000; + } +}].forEach(wrongOffset => { + const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); + + assert.throws( + TypeError, + () => Temporal.Now.plainDateTimeISO(timeZone), + 'Temporal.Now.plainDateTimeISO(timeZone) throws a TypeError exception' + ); +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-call-tostring.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-call-tostring.js new file mode 100644 index 0000000000..80277327d2 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-call-tostring.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Forwards error thrown by invoking "toString" property +features: [Temporal] +---*/ + +var timeZone = { + timeZone: { + timeZone: true, + toString: function() { + throw new Test262Error(); + }, + } +}; + +assert.throws(Test262Error, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a Test262Error exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-get-timezone.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-get-timezone.js new file mode 100644 index 0000000000..37cc21b8cc --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-get-timezone.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Forwards error thrown by retrieving value of "timeZone" property +features: [Temporal] +---*/ + +var timeZone = { + get timeZone() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a Test262Error exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-nested-timezone.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-nested-timezone.js new file mode 100644 index 0000000000..dc75b42302 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-nested-timezone.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Forwards error thrown by checking presence of nested "timeZone" property +features: [Proxy, Temporal] +---*/ + +var timeZone = { + timeZone: new Proxy({}, { + has: function(target, property) { + if (property === 'timeZone') { + throw new Test262Error(); + } + }, + }) +}; + +assert.throws(Test262Error, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a Test262Error exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-timezone.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-timezone.js new file mode 100644 index 0000000000..86850e3c79 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object-fail-has-timezone.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Forwards error thrown by checking presence of "timeZone" property +features: [Proxy, Temporal] +---*/ + +var timeZone = new Proxy({}, { + has: function(target, property) { + if (property === 'timeZone') { + throw new Test262Error(); + } + }, +}); + +assert.throws(Test262Error, function() { + Temporal.Now.plainDateTimeISO(timeZone); +}, 'Temporal.Now.plainDateTimeISO(timeZone) throws a Test262Error exception'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object.js new file mode 100644 index 0000000000..f81bd4ad15 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-object.js @@ -0,0 +1,77 @@ +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Observable interactions with the provided timezone-like object +includes: [compareArray.js] +features: [BigInt, Proxy, Temporal] +---*/ +const actual = []; + +const expected = [ + 'has timeZone.timeZone', + 'get timeZone.timeZone', + 'has nestedTimeZone.timeZone', + 'get nestedTimeZone.getOffsetNanosecondsFor', + 'call nestedTimeZone.getOffsetNanosecondsFor' +]; + +const nestedTimeZone = new Proxy({ + getOffsetNanosecondsFor(instant) { + actual.push('call nestedTimeZone.getOffsetNanosecondsFor'); + + assert.sameValue( + instant instanceof Temporal.Instant, + true, + 'The result of evaluating (instant instanceof Temporal.Instant) is expected to be true' + ); + + return -Number(instant.epochNanoseconds % 86400000000000n); + } +}, { + has(target, property) { + actual.push(`has nestedTimeZone.${String(property)}`); + return property in target; + }, + + get(target, property) { + actual.push(`get nestedTimeZone.${String(property)}`); + return target[property]; + } +}); + +const timeZone = new Proxy({ + timeZone: nestedTimeZone, + + getOffsetNanosecondsFor(instant) { + actual.push('call timeZone.getOffsetNanosecondsFor'); + + assert.sameValue( + instant instanceof Temporal.Instant, + true, + 'The result of evaluating (instant instanceof Temporal.Instant) is expected to be true' + ); + + return -Number(instant.epochNanoseconds % 86400000000000n); + } +}, { + has(target, property) { + actual.push(`has timeZone.${property}`); + return property in target; + }, + + get(target, property) { + actual.push(`get timeZone.${property}`); + return target[property]; + } +}); + +Object.defineProperty(Temporal.TimeZone, 'from', { + get() { + actual.push('get Temporal.TimeZone.from'); + return undefined; + } +}); + +Temporal.Now.plainDateTimeISO(timeZone); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string-datetime.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string-datetime.js new file mode 100644 index 0000000000..5c1515d888 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string-datetime.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.now.plaindatetimeiso +description: Conversion of ISO date-time strings to Temporal.TimeZone instances +features: [Temporal] +---*/ + +let timeZone = "2021-08-19T17:30"; +assert.throws(RangeError, () => Temporal.Now.plainDateTimeISO(timeZone), "bare date-time string is not a time zone"); +assert.throws(RangeError, () => Temporal.Now.plainDateTimeISO({ timeZone }), "bare date-time string is not a time zone"); + +// The following are all valid strings so should not throw: + +[ + "2021-08-19T17:30Z", + "2021-08-19T17:30-07:00", + "2021-08-19T17:30[America/Vancouver]", + "2021-08-19T17:30Z[America/Vancouver]", + "2021-08-19T17:30-07:00[America/Vancouver]", +].forEach((timeZone) => { + Temporal.Now.plainDateTimeISO(timeZone); + Temporal.Now.plainDateTimeISO({ timeZone }); +});