test262/test/built-ins/Temporal/Now/plainDate/toPlainDate-override.js

49 lines
1.3 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.plaindate
description: PlainDateTime.toPlainDate is not observably called
includes: [compareArray.js]
features: [Temporal]
---*/
const actual = [];
const expected = [
"has timeZone.timeZone",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
Object.defineProperty(Temporal.PlainDateTime.prototype, "toPlainDate", {
get() {
actual.push("get Temporal.PlainDateTime.prototype.toPlainDate");
return function() {
actual.push("call Temporal.PlainDateTime.prototype.toPlainDate");
};
},
});
const timeZone = new Proxy({
getOffsetNanosecondsFor(instant) {
actual.push("call timeZone.getOffsetNanosecondsFor");
assert.sameValue(instant instanceof Temporal.Instant, true, "Instant");
return 86399_999_999_999;
},
}, {
has(target, property) {
actual.push(`has timeZone.${property}`);
return property in target;
},
get(target, property) {
actual.push(`get timeZone.${property}`);
return target[property];
},
});
const result = Temporal.Now.plainDate("iso8601", timeZone);
assert.notSameValue(result, undefined);
assert.sameValue(result instanceof Temporal.PlainDate, true);
assert.compareArray(actual, expected);