mirror of
https://github.com/tc39/test262.git
synced 2025-07-19 20:14:56 +02:00
Rewrite tests that relied on previous branding behaviour
A follow up to the previous commit, this rewrites some tests that relied on the lack of brand checks for certain Temporal.TimeZone methods. https://github.com/tc39/proposal-temporal/pull/1693 added brand checks to these methods. We can no longer use a plain object time zone or even a Proxy with a real branded Temporal.TimeZone object as its handler to do these tests, so we instead create an instance of Temporal.TimeZone and define own accessor properties on it in order to test the observable property accesses that we need to see according to the spec text. This requires an improvement to TemporalHelpers.observeProperty() in order to be able to log property accesses to Symbol-valued properties.
This commit is contained in:
parent
f3c485d6da
commit
9af34ce28c
@ -1191,13 +1191,23 @@ var TemporalHelpers = {
|
||||
* will log any calls to its accessors to the array @calls.
|
||||
*/
|
||||
observeProperty(calls, object, propertyName, value) {
|
||||
let displayName = propertyName;
|
||||
if (typeof propertyName === 'symbol') {
|
||||
if (Symbol.keyFor(propertyName) !== undefined) {
|
||||
displayName = `[Symbol.for('${Symbol.keyFor(propertyName)}')]`;
|
||||
} else if (propertyName.description.startsWith('Symbol.')) {
|
||||
displayName = `[${propertyName.description}]`;
|
||||
} else {
|
||||
displayName = `[Symbol('${propertyName.description}')]`
|
||||
}
|
||||
}
|
||||
Object.defineProperty(object, propertyName, {
|
||||
get() {
|
||||
calls.push(`get ${propertyName}`);
|
||||
calls.push(`get ${displayName}`);
|
||||
return value;
|
||||
},
|
||||
set(v) {
|
||||
calls.push(`set ${propertyName}`);
|
||||
calls.push(`set ${displayName}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -10,28 +10,18 @@ features: [Temporal]
|
||||
|
||||
const actual = [];
|
||||
const expected = [
|
||||
"get timeZone.getOffsetNanosecondsFor",
|
||||
"get getOffsetNanosecondsFor",
|
||||
"call timeZone.getOffsetNanosecondsFor",
|
||||
];
|
||||
|
||||
const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
|
||||
const timeZone = new Proxy({
|
||||
getOffsetNanosecondsFor(instantArg) {
|
||||
actual.push("call timeZone.getOffsetNanosecondsFor");
|
||||
assert.sameValue(instantArg, instant);
|
||||
return 9876543210123;
|
||||
},
|
||||
}, {
|
||||
has(target, property) {
|
||||
actual.push(`has timeZone.${property}`);
|
||||
return property in target;
|
||||
},
|
||||
get(target, property) {
|
||||
actual.push(`get timeZone.${property}`);
|
||||
return target[property];
|
||||
},
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
TemporalHelpers.observeProperty(actual, timeZone, "getOffsetNanosecondsFor", function (instantArg) {
|
||||
actual.push("call timeZone.getOffsetNanosecondsFor");
|
||||
assert.sameValue(instantArg, instant);
|
||||
return 9876543210123;
|
||||
});
|
||||
|
||||
const result = Temporal.TimeZone.prototype.getPlainDateTimeFor.call(timeZone, instant);
|
||||
const result = timeZone.getPlainDateTimeFor(instant);
|
||||
TemporalHelpers.assertPlainDateTime(result, 1975, 2, "M02", 2, 17, 10, 12, 666, 666, 912);
|
||||
assert.compareArray(actual, expected);
|
||||
|
27
test/built-ins/Temporal/TimeZone/prototype/id/custom-timezone.js
vendored
Normal file
27
test/built-ins/Temporal/TimeZone/prototype/id/custom-timezone.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-temporal.timezone.prototype.id
|
||||
description: Getter calls toString() and returns its value
|
||||
includes: [compareArray.js, temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const actual = [];
|
||||
const expected = [
|
||||
"get [Symbol.toPrimitive]",
|
||||
"get toString",
|
||||
"call timeZone.toString",
|
||||
];
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined);
|
||||
TemporalHelpers.observeProperty(actual, timeZone, "toString", function () {
|
||||
actual.push("call timeZone.toString");
|
||||
return "time zone";
|
||||
});
|
||||
|
||||
const result = timeZone.id;
|
||||
assert.compareArray(actual, expected);
|
||||
assert.sameValue(result, "time zone");
|
@ -21,6 +21,5 @@ Object.defineProperty(timeZone, "toString", {
|
||||
},
|
||||
});
|
||||
|
||||
const descriptor = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "id");
|
||||
assert.throws(TypeError, () => descriptor.get.call(timeZone));
|
||||
assert.throws(TypeError, () => timeZone.id);
|
||||
assert.compareArray(actual, expected);
|
||||
|
@ -1,45 +0,0 @@
|
||||
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-temporal.timezone.prototype.id
|
||||
description: Getter calls toString() and returns its value
|
||||
includes: [compareArray.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const actual = [];
|
||||
const expected = [
|
||||
"get timeZone[@@toPrimitive]",
|
||||
"get timeZone.toString",
|
||||
"call timeZone.toString",
|
||||
];
|
||||
|
||||
const timeZone = new Proxy({
|
||||
toString() {
|
||||
actual.push("call timeZone.toString");
|
||||
return "time zone";
|
||||
},
|
||||
}, {
|
||||
has(target, property) {
|
||||
if (property === Symbol.toPrimitive) {
|
||||
actual.push('has timeZone[@@toPrimitive]');
|
||||
} else {
|
||||
actual.push(`has timeZone.${property}`);
|
||||
}
|
||||
return property in target;
|
||||
},
|
||||
get(target, property) {
|
||||
if (property === Symbol.toPrimitive) {
|
||||
actual.push('get timeZone[@@toPrimitive]');
|
||||
} else {
|
||||
actual.push(`get timeZone.${property}`);
|
||||
}
|
||||
return target[property];
|
||||
},
|
||||
});
|
||||
|
||||
const descriptor = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "id");
|
||||
const result = descriptor.get.call(timeZone);
|
||||
assert.compareArray(actual, expected);
|
||||
assert.sameValue(result, "time zone");
|
@ -4,44 +4,24 @@
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.tojson
|
||||
description: toJSON() calls toString() and returns its value
|
||||
includes: [compareArray.js]
|
||||
includes: [compareArray.js, temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const actual = [];
|
||||
const expected = [
|
||||
'get timeZone[@@toPrimitive]',
|
||||
'get timeZone.toString',
|
||||
'get [Symbol.toPrimitive]',
|
||||
'get toString',
|
||||
'call timeZone.toString',
|
||||
];
|
||||
|
||||
const timeZone = new Proxy(
|
||||
{
|
||||
toString() {
|
||||
actual.push(`call timeZone.toString`);
|
||||
return 'Etc/TAI';
|
||||
}
|
||||
},
|
||||
{
|
||||
has(target, property) {
|
||||
if (property === Symbol.toPrimitive) {
|
||||
actual.push('has timeZone[@@toPrimitive]');
|
||||
} else {
|
||||
actual.push(`has timeZone.${property}`);
|
||||
}
|
||||
return property in target;
|
||||
},
|
||||
get(target, property) {
|
||||
if (property === Symbol.toPrimitive) {
|
||||
actual.push('get timeZone[@@toPrimitive]');
|
||||
} else {
|
||||
actual.push(`get timeZone.${property}`);
|
||||
}
|
||||
return target[property];
|
||||
}
|
||||
}
|
||||
);
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined);
|
||||
TemporalHelpers.observeProperty(actual, timeZone, "toString", function () {
|
||||
actual.push("call timeZone.toString");
|
||||
return "Etc/TAI";
|
||||
});
|
||||
|
||||
const result = Temporal.TimeZone.prototype.toJSON.call(timeZone);
|
||||
const result = timeZone.toJSON();
|
||||
assert.sameValue(result, 'Etc/TAI', 'toString');
|
||||
assert.compareArray(actual, expected);
|
||||
|
@ -4,40 +4,21 @@
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.tojson
|
||||
description: TypeError thrown when toString property not present
|
||||
includes: [compareArray.js]
|
||||
includes: [compareArray.js, temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const actual = [];
|
||||
const expected = [
|
||||
'get timeZone[@@toPrimitive]',
|
||||
'get timeZone.toString',
|
||||
'get timeZone.valueOf',
|
||||
'get [Symbol.toPrimitive]',
|
||||
'get toString',
|
||||
'get valueOf',
|
||||
];
|
||||
|
||||
const timeZone = new Proxy(
|
||||
{
|
||||
toString: undefined
|
||||
},
|
||||
{
|
||||
has(target, property) {
|
||||
if (property === Symbol.toPrimitive) {
|
||||
actual.push('has timeZone[@@toPrimitive]');
|
||||
} else {
|
||||
actual.push(`has timeZone.${property}`);
|
||||
}
|
||||
return property in target;
|
||||
},
|
||||
get(target, property) {
|
||||
if (property === Symbol.toPrimitive) {
|
||||
actual.push('get timeZone[@@toPrimitive]');
|
||||
} else {
|
||||
actual.push(`get timeZone.${property}`);
|
||||
}
|
||||
return target[property];
|
||||
}
|
||||
}
|
||||
);
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined);
|
||||
TemporalHelpers.observeProperty(actual, timeZone, "toString", undefined);
|
||||
TemporalHelpers.observeProperty(actual, timeZone, "valueOf", Object.prototype.valueOf);
|
||||
|
||||
assert.throws(TypeError, () => Temporal.TimeZone.prototype.toJSON.call(timeZone));
|
||||
assert.throws(TypeError, () => timeZone.toJSON());
|
||||
assert.compareArray(actual, expected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user