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

38 lines
1001 B
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.timezone.from
description: An object is returned unchanged
features: [Temporal]
---*/
class CustomTimeZone extends Temporal.TimeZone {}
const objects = [
new Temporal.TimeZone("UTC"),
new CustomTimeZone("UTC"),
{ id: "Etc/Custom", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null },
];
const thisValues = [
Temporal.TimeZone,
CustomTimeZone,
{},
null,
undefined,
7,
];
for (const thisValue of thisValues) {
for (const object of objects) {
const result = Temporal.TimeZone.from.call(thisValue, object);
assert.sameValue(result, object);
}
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
const fromZdt = Temporal.TimeZone.from.call(thisValue, zdt);
assert.notSameValue(fromZdt, zdt.getTimeZone(), "from() creates a new object from a string slot value");
assert.sameValue(fromZdt.id, "UTC");
}