diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index 6f76d4d8e5..3a2ed5e4d4 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -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}`); } }); }, diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/custom-timezone.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/custom-timezone.js index 7b831f0f11..906d3dfef8 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/custom-timezone.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/custom-timezone.js @@ -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); diff --git a/test/built-ins/Temporal/TimeZone/prototype/id/custom-timezone.js b/test/built-ins/Temporal/TimeZone/prototype/id/custom-timezone.js new file mode 100644 index 0000000000..1ea8713ab2 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/id/custom-timezone.js @@ -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"); diff --git a/test/built-ins/Temporal/TimeZone/prototype/id/no-toString.js b/test/built-ins/Temporal/TimeZone/prototype/id/no-toString.js index d9d457a1c4..ae849b0f83 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/id/no-toString.js +++ b/test/built-ins/Temporal/TimeZone/prototype/id/no-toString.js @@ -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); diff --git a/test/built-ins/Temporal/TimeZone/prototype/id/plain-custom-timezone.js b/test/built-ins/Temporal/TimeZone/prototype/id/plain-custom-timezone.js deleted file mode 100644 index d5cf02a59b..0000000000 --- a/test/built-ins/Temporal/TimeZone/prototype/id/plain-custom-timezone.js +++ /dev/null @@ -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"); diff --git a/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-call.js b/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-call.js index 537a7c3e15..2d59752680 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-call.js +++ b/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-call.js @@ -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); diff --git a/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-undefined-custom.js b/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-undefined-custom.js index d3411cbd6e..bf9b82e08e 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-undefined-custom.js +++ b/test/built-ins/Temporal/TimeZone/prototype/toJSON/tostring-undefined-custom.js @@ -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);