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

Import (and fix) the promises guide #490

Closed
annevk opened this issue Dec 6, 2017 · 5 comments · Fixed by #772 or w3c/screen-wake-lock#236
Closed

Import (and fix) the promises guide #490

annevk opened this issue Dec 6, 2017 · 5 comments · Fixed by #772 or w3c/screen-wake-lock#236

Comments

@annevk
Copy link
Member

annevk commented Dec 6, 2017

Most of the algorithms in https://www.w3.org/2001/tag/doc/promises-guide for resolving and rejecting should be part of IDL (and formalized in the process). Resolving from "in parallel" should be something that HTML defines I think.

@tobie
Copy link
Collaborator

tobie commented Dec 6, 2017

Mmm. I was sure we already had an open issue for this but can't find it.

@annevk
Copy link
Member Author

annevk commented Dec 6, 2017

It's not linked from w3ctag/promises-guide#27 (and now this is).

@domenic
Copy link
Member

domenic commented Jan 18, 2019

As background, one of the major things wrong with the promises guide is that it was written before I was bought into the Web IDL ecosystem, so it tries to be usable from JS specs as well. A lot of the definitions take as arguments JS values or JS functions, whereas you really want to be using them with IDL values or lists of steps.

https://www.w3.org/2001/tag/doc/promises-guide#shorthand-phrases is the section in question, mainly.

Here is what I would do for this issue, if I had the time to do so.

  • Redefine "a promise resolved with" to use PromiseResolve(%Promise%, x converted from Web IDL to JS).
  • Redefine "a promise rejected with" to use %Promise_reject%.
  • Fix all call sites of "resolve a promise" etc. to explicitly queue a task, instead of the current implicit task queuing. This fixes Promise-manipulation shorthands have underdefined behavior w3ctag/promises-guide#52.
  • Make the Web IDL promise type a wrapper around a PromiseCapability record, not just a JS Promise object.
  • Formalize "resolve" and "reject" on Web IDL promise types using the [[Resolve]] and [[Reject]] record fields. Insert type conversions as appropriate. Potentially separate out "resolved with" and "resolved with an arbitrary value".
  • Re-do Web IDL's "perform some steps once a promise is settled" to use PerformPromiseThen (with no resultCapability).
    • Add examples of how to use "perform some steps once a promise is settled". Draw on existing usages of "upon fulfillment" and "upon rejection" in promise-heavy specs (e.g. Streams, Service Worker, maybe HTML) to ensure that this pattern is ergonomic.
    • If the pattern is not ergonomic, then update "upon fulfillment" and "upon rejection" to be specializations of "perform some steps once a promise is settled". If it is ergonomic, delete those terms and update all specs to use "perform some steps once a promise is settled".
    • Fix "perform some steps once a promise is settled" to handle type conversion errors in step 2.2.2.
  • Formalize "transforming" in terms of PerformPromiseThen with a resultCapability. This will require care around the various conversions involved. Be sure to survey existing usages to make sure they're compatible.
  • Import "wait for all" and "get a promise for waiting for all". Those were recently rewritten in Re-do "waiting for all" w3ctag/promises-guide#55 so they should be on OK ground; they just need some conversions between Web IDL and JS type systems.
  • Promise-calling may be obsolete (subsumed by "invoking" a callback type with a Promise return value). Survey any existing usages. They may be all in streams, in which case it can move there.
  • Add realm arguments to the newly-formalized mechanisms, per Uses of "resolving x as a promise" and so forth need to specify the global w3ctag/promises-guide#46 and possibly some other issues.
  • Deal with https://www.w3.org/2001/tag/doc/promises-guide#examples. Some options:
    • Delete
    • Keep as a reference for JS developers, gutting all spec-person-facing content.
    • Rewrite to be Web IDL-based, using the new algorithms
    • Rewrite to be Web IDL-based, and move it into the Web IDL spec
  • Do another pass through the guide to make it more Web IDL focused.

I think this could be done relatively piecemeal. Some steps are definitely separable (e.g. fixing realm usage, separating two variants of resolve, maybe fixing the task-queuing). You could also do it definition by definition, if you were willing to add a warning to the promises guide saying "during the transition period, these not-yet-migrated definitions will sometimes be used on Web IDL promise types; if so, that roughly means this."

@Ms2ger
Copy link
Member

Ms2ger commented Feb 12, 2019

Make the Web IDL promise type a wrapper around a PromiseCapability record, not just a JS Promise object.

Is there a way to get this record out of an arbitrary Promise object? I believe this would be needed for https://heycam.github.io/webidl/#es-to-promise (as it exists today), since Promise.resolve() returns its argument if it already is a promise.

@domenic
Copy link
Member

domenic commented Feb 12, 2019

It seems like using https://tc39.github.io/ecma262/#sec-createresolvingfunctions (and then adding a [[Promise]] field to the result) would work, although I'm a bit unsure about the consequences of a promise floating around with multiple resolve/reject functions associated with it (one from user code and one from the UA).

Ideally UA code should not be resolving/rejecting user-provided promises. So maybe there is a better structure than the one I outlined above, hmm.

For example, [[Resolve]] and [[Reject]] could be null for user-provided promises, and the first steps of "resolve a promise"/"reject a promise" could assert they are non-null, i.e. assert that the promise was UA-created and not user-created?

Ms2ger added a commit that referenced this issue Aug 20, 2019
Ms2ger added a commit that referenced this issue Aug 20, 2019
Ms2ger added a commit that referenced this issue Aug 27, 2019
Ms2ger added a commit that referenced this issue Aug 27, 2019
rakuco pushed a commit to rakuco/wake-lock that referenced this issue Oct 11, 2019
The old anchor in the TAG's "Writing Promise-Using Specifications" no longer
exists, as the text was moved to the WebIDL specification to fix
whatwg/webidl#490.

Reference the right spec to fix our validation checks.
rakuco pushed a commit to rakuco/wake-lock that referenced this issue Oct 11, 2019
* Fix reference to "a new promise". The old anchor in the TAG's "Writing
  Promise-Using Specifications" no longer exists, as the text was moved to
  the WebIDL specification to fix whatwg/webidl#490. Fixes

  ```
  page was found but not the anchor from output.html to
  https://www.w3.org/2001/tag/doc/promises-guide#a-new-promise
  ```

* Fix the reference to DOM's AbortSignal's "added" definition:

  ```
  ReSpec error: Couldn't match "**added**" to anything in the document or in
  any other document cited in this specification: `dom`, `feature-policy`,
  `fetch`, `html`, `infra`, `permissions`, `url`, `webidl`.
  ```
rakuco pushed a commit to w3c/screen-wake-lock that referenced this issue Oct 11, 2019
* Fix reference to "a new promise". The old anchor in the TAG's "Writing
  Promise-Using Specifications" no longer exists, as the text was moved to
  the WebIDL specification to fix whatwg/webidl#490. Fixes

  ```
  page was found but not the anchor from output.html to
  https://www.w3.org/2001/tag/doc/promises-guide#a-new-promise
  ```

* Fix the reference to DOM's AbortSignal's "added" definition:

  ```
  ReSpec error: Couldn't match "**added**" to anything in the document or in
  any other document cited in this specification: `dom`, `feature-policy`,
  `fetch`, `html`, `infra`, `permissions`, `url`, `webidl`.
  ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants