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

Editorial: combine safety check steps into new section #251

Merged
merged 3 commits into from
May 4, 2023

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented Apr 13, 2023

Closes #237


Preview | Diff

Comment on lines +523 to +474
<p>
The <dfn>common safety checks</dfn> for a {{Document}}
|document:Document| are the following steps:
</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make these throw an exception. Web IDL will do the conversion from a thrown exception to a rejected promise. Returning an exception is very weird.

Alternatively you could return a(n) (string) enum and branch on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yeah, good point... will make them throw directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sooooo... these all throw now. And yes, the IDL layer would automatically wrap the exceptions.

However, just from the sake of clarity and consistency, I'd still like to use "Return a promise rejected with X" for .lock(). I've had instances in the past of reviewers getting confused about methods throwing even though they always return a promise.

Similarly, for .unlock(), just for clarity, I have it re-throw and abort the steps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's okay, but I'd rather we explain the mechanism in a note so implementations with correct binding layers don't do this redundantly as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be way cleaner. I'd also rather just be writing:

  • If X throw {{WhateverError}}.
  • If Y throw {{OtherError}}.

And so on... It feels like WebIDL's [=exception/throw=] should include such a note. Currently, it's not super clear what should happen and every example in WebIDL is using [=return a promise rejected with=].

I'll raise an issue on WebIDL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone interested whatwg/webidl#1301

<li data-tests="hidden_document.html">If |document|'s
[=Document/visibility state=] is "hidden", [=exception/throw=]
{{"SecurityError"}} {{DOMException}}.
</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It strikes me that if you adopt whatwg/html@2db564c here (and I think you should in a follow-up) you won't get to distinguish exceptions, but that's probably okay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's ok. And yeah, will do that as a followup.

Comment on lines +523 to +474
<p>
The <dfn>common safety checks</dfn> for a {{Document}}
|document:Document| are the following steps:
</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's okay, but I'd rather we explain the mechanism in a note so implementations with correct binding layers don't do this redundantly as well.

@marcoscaceres marcoscaceres merged commit ee9acbc into gh-pages May 4, 2023
@marcoscaceres marcoscaceres deleted the common-checks branch May 4, 2023 05:47
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 this pull request may close these issues.

Split out the safety checks into a shared algorithm
2 participants