Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal.TimeZone.prototype.equals: Missing call to ToTemporalTimeZoneSlotValue #41

Closed
ptomato opened this issue Sep 25, 2023 · 8 comments · Fixed by #42
Closed

Temporal.TimeZone.prototype.equals: Missing call to ToTemporalTimeZoneSlotValue #41

ptomato opened this issue Sep 25, 2023 · 8 comments · Fixed by #42

Comments

@ptomato
Copy link
Contributor

ptomato commented Sep 25, 2023

From @anba in https://github.com/tc39/proposal-temporal/issues/2682:

Step 3:

Return ? TimeZoneEquals(timeZone, other).

But other first needs to be converted to a time-zone value through ToTemporalTimeZoneSlotValue.

@ptomato
Copy link
Contributor Author

ptomato commented Sep 25, 2023

I missed this during stage 3 review, unfortunately. I think we should just fix it since it's pretty clear what the intention was. However the current behaviour doesn't violate any assertions and would be observable, so I suspect it's technically a normative change. What do you think?

@ptomato
Copy link
Contributor Author

ptomato commented Sep 25, 2023

Thinking about it some more, maybe the change does not have to be a normative change after all. By my reading, here's what I see happening for four different inputs, (1) string identifier of built-in time zone, (2) other string, (3) instance of Temporal.TimeZone, (4) plain object implementing TimeZone protocol, (5) other plain object, (6) other non-string non-object value.

  1. timeZone.equals("America/Vancouver")
  • TimeZoneEquals step 3 calls ToTemporalTimeZoneIdentifier("America/Vancouver")
  • ToTemporalTimeZoneIdentifier step 1.b returns the value unchanged.
  • TimeZoneEquals step 6 does not throw because the identifier conforms to the TimeZoneIdentifier grammar.
  • The rest of the operation completes normally.
  • No change from what would happen with ToTemporalTimeZoneSlotValue.
  1. timeZone.equals("not a time zone")
  • TimeZoneEquals step 3 calls ToTemporalTimeZoneIdentifier("not a time zone")
  • Assertion failure in ToTemporalTimeZoneIdentifier step 1.a.
  • Current spec is unimplementable. ToTemporalTimeZoneSlotValue should throw in step 3 in this case.
  1. class MyTimeZone extends Temporal.TimeZone {}; timeZone.equals(new MyTimeZone("UTC"))
  • TimeZoneEquals step 3 calls ToTemporalTimeZoneIdentifer and passes the MyTimeZone instance.
  • ToTemporalTimeZoneIdentifier step 2 observably calls Get("id") on the MyTimeZone instance
  • ToTemporalTimeZoneIdentifier step 4 returns "UTC".
  • The rest of the operation completes normally.
  • No change from what would happen with ToTemporalTimeZoneSlotValue.
  1. timeZone.equals({ getOffsetNanosecondsFor() {}, getPossibleInstantsFor() {}, id: "UTC" })
  • TimeZoneEquals step 3 calls ToTemporalTimeZoneIdentifier and passes the plain object.
  • ToTemporalTimeZoneIdentifier step 2 observably calls Get("id") on the plain object.
  • ToTemporalTimeZoneIdentifier step 4 returns "UTC".
  • The rest of the operation completes normally.
  • Changed: with ToTemporalTimeZoneSlotValue, we would see observable Has calls on the plain object in ObjectImplementsTemporalTimeZoneProtocol.
  1. timeZone.equals({})
  • TimeZoneEquals step 3 calls ToTemporalTimeZoneIdentifier and passes the plain object.
  • ToTemporalTimeZoneIdentifier step 2 observably calls Get("id") on the plain object.
  • ToTemporalTimeZoneIdentifier step 3 throws a TypeError because the value is undefined.
  • Changed: with ToTemporalTimeZoneSlotValue, we would see observable Has calls on the plain object in ObjectImplementsTemporalTimeZoneProtocol.
  1. timeZone.equals(true)
  • TimeZoneEquals step 3 calls ToTemporalTimeZoneIdentifier(true).
  • Assertion failure because ToTemporalTimeZoneIdentifier takes a String or Object parameter.
  • Current spec is unimplementable. ToTemporalTimeZoneSlotValue should throw in step 2 in this case.

So it looks like the spec is unimplementable as written and therefore this may be classified as an editorial change after all. What do you think?

ptomato added a commit to ptomato/proposal-canonical-tz that referenced this issue Sep 25, 2023
Without this, we will fail some assertions in the case of a non-string
argument, or a string argument that's not a valid time zone identifier.
In the plain object case, we'll also miss some Has calls in
ObjectImplementsTemporalTimeZoneProtocol.

Closes: tc39#41
@ptomato
Copy link
Contributor Author

ptomato commented Sep 25, 2023

#42 is a possible fix.

@anba
Copy link
Contributor

anba commented Sep 25, 2023

So it looks like the spec is unimplementable as written and therefore this may be classified as an editorial change after all. What do you think?

Yes, that's correct. The current spec isn't actually implementable.

@justingrant
Copy link
Collaborator

justingrant commented Sep 25, 2023

Good catch finding this! Given that this proposal has already been merged into Temporal, I assume that the fix should be on the Temporal side?

We can also fix it here too for comprehensiveness, but the fix that really matters for implementers will be in Temporal, right?

@ptomato
Copy link
Contributor Author

ptomato commented Sep 25, 2023

Yes, I'd copy the fix into Temporal once it landed here.

@justingrant
Copy link
Collaborator

Cool. I'll review the PR shortly and so we should be able to turn this around quickly. And I agree that this is editorial because the current spec is not implementable.

justingrant pushed a commit that referenced this issue Sep 25, 2023
Without this, we will fail some assertions in the case of a non-string
argument, or a string argument that's not a valid time zone identifier.
In the plain object case, we'll also miss some Has calls in
ObjectImplementsTemporalTimeZoneProtocol.

Closes: #41
@justingrant
Copy link
Collaborator

Approved and merged here. @ptomato, ball is in your court now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants