Philip Chimento d6a24fe906 Validate required methods of Temporal TimeZone protocol
Checking whether an object implements the TimeZone protocol is now done by
means of HasProperty operations for each of the required methods unless
the object already has the TimeZone brand.

Discussion:
https://github.com/tc39/proposal-temporal/issues/2104#issuecomment-1409549753

Corresponding normative PR:
https://github.com/tc39/proposal-temporal/pull/2485
2023-04-10 08:36:08 -07:00

41 lines
1.2 KiB
JavaScript

// 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.plaindatetime
description: Behavior when provided calendar value is a function
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Proxy, Temporal]
---*/
const actual = [];
const expected = [
'has timeZone.getOffsetNanosecondsFor',
'has timeZone.getPossibleInstantsFor',
'has timeZone.id',
'get timeZone.getOffsetNanosecondsFor',
'call timeZone.getOffsetNanosecondsFor'
];
const calendar = function() {};
const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getOffsetNanosecondsFor(instant) {
return -Number(instant.epochNanoseconds % 86400000000000n);
},
});
Object.defineProperty(Temporal.Calendar, 'from', {
get() {
actual.push('get Temporal.Calendar.from');
return undefined;
}
});
const result = Temporal.Now.plainDateTime(calendar, 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');
}
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');