Skip to content

Fix ECMAScript to IDL Promise type conversion #219

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

Merged
merged 4 commits into from
May 5, 2020

Conversation

ExE-Boss
Copy link
Contributor

@ExE-Boss ExE-Boss commented May 2, 2020

Most notably, this fixes the bug where rejected promises were being converted into resolved promises and that Promise.resolve(x) returns x when x is a Promise object from the same realm as the Promise.resolve function, whereas WebIDL requires the conversion to always return a new Promise object.


Note that there still is a small timing difference for non‑void promises due to the fact that the IDL conversion and promise reaction are being performed in separate then callbacks, whereas WebIDL runs them in the same then callback. (See the “to react to a Promise<T> algorithm)

Fixing this minor timing discrepancy would require the type conversion to be performed manually in implementation classes or overriding the then method of the converted Promise instance.


P.S.: If you still want then to be called with two arguments, then the correct callback is:

reason => {
	throw reason;
}

Which is the default behaviour when null or undefined is passed.

@domenic
Copy link
Member

domenic commented May 2, 2020

Can you remove the T conversion entirely? As I pointed out, it does not exist in the Web IDL spec.

@ExE-Boss
Copy link
Contributor Author

ExE-Boss commented May 2, 2020

It does exist in the “to react to a Promise<T> algorithm.

@domenic
Copy link
Member

domenic commented May 2, 2020

Right. When the spec reacts to it, it can do the conversion. We shouldn't do it automatically, especially since nobody reacts to return types.

@domenic
Copy link
Member

domenic commented May 2, 2020

I'm sorry, perhaps I wasn't clear enough. The type conversion logic should not live in webidl2js at all.

@ExE-Boss ExE-Boss force-pushed the fix/types/es-to-promise-conversion branch from 4c047c2 to a0c5036 Compare May 2, 2020 16:28
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Thank you! Confirmed this fixes whatwg/streams in combination with #194.

When we add promise-accepting APIs to jsdom we can consider adding utils.transformPromise or something which does the appropriate type conversions.

@domenic domenic merged commit 2aab61c into jsdom:master May 5, 2020
@ExE-Boss ExE-Boss deleted the fix/types/es-to-promise-conversion branch May 5, 2020 20:49
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.

2 participants