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

Promise-returning operations should return Promise.reject on invalid argument #79

Closed
danyao opened this issue Oct 6, 2017 · 7 comments · Fixed by #200
Closed

Promise-returning operations should return Promise.reject on invalid argument #79

danyao opened this issue Oct 6, 2017 · 7 comments · Fixed by #200

Comments

@danyao
Copy link
Contributor

danyao commented Oct 6, 2017

If an interface defines a Promise-returning operation with required arguments, the generated wrapper throws TypeError if insufficient number of arguments are provided. I believe the expected behavior is to return a Promise.reject that throws.

E.g.

interface Foo {
  Promise<string> greet(string name);
};

Generates:

Foo.prototype.greet = function greet(name) {
  ...
  if (arguments.length < 1) {
    throw new TypeError(
      "Failed to execute 'greet' on 'Foo': " + "1 argument required, but only " + arguments.length + " present."
    );  // [*]
  }

  ...
}

[*] should be:

return Promise.reject(new TypeError("<error message>"));

I couldn't find exact wording in WebIDL spec about this. However, the return-rejected-promise behavior is what Web Platform Test's idlharness.js enforces.

@domenic
Copy link
Member

domenic commented Oct 6, 2017

FYI https://help.github.com/articles/creating-and-highlighting-code-blocks/ for putting code in GitHub. I'll edit your post to do that :)

@danyao
Copy link
Contributor Author

danyao commented Oct 6, 2017

Thanks! Will do next time.

@TimothyGu
Copy link
Member

Web IDL reference: https://heycam.github.io/webidl/#dfn-create-operation-function step 2:

...
And then, if an exception E was thrown:

  1. If op has a return type that is a promise type, then return ! Call(%Promise_reject%, %Promise%, «E»).
  2. Otherwise, end these steps and allow the exception to propagate.

Likewise we should fix this for attribute getters and setters, which has a similar clause.

stevedorries pushed a commit to stevedorries/webidl2js that referenced this issue Jan 27, 2020
@domenic
Copy link
Member

domenic commented Apr 15, 2020

This is blocking the Streams Standard reference implementation from migrating to webidl2js. If anyone is excited about taking this I would very much appreciate it. Otherwise I'll try to find time soon!

@Sebmaster
Copy link
Member

We could probably implement this rather easily by just marking the functions async if they have a Promise return type nowadays since our node requirements are high enough, yeah?

@domenic
Copy link
Member

domenic commented Apr 15, 2020

True, I think that would probably do it!

domenic added a commit to whatwg/streams that referenced this issue Apr 16, 2020
domenic added a commit that referenced this issue Apr 17, 2020
Closes #79.

This removes support for overloading promise operations and non-promise operations, since that would require a more ambitious approach and doesn't seem to appear on the web.
@ExE-Boss
Copy link
Contributor

ExE-Boss commented Apr 22, 2020

The thing is, WebIDL creates a rejected Promise synchronously in that case, whereas async functions only begin executing as a macrotask.

This is also why #172 and #194 use try‑catch instead of async function, because there the user callback would otherwise begin executing asynchronously, which can potentially be detected.

domenic added a commit that referenced this issue Apr 26, 2020
Closes #79.

This removes support for overloading promise operations and non-promise operations, since that would require a more ambitious approach and doesn't seem to appear on the web.
domenic added a commit that referenced this issue Apr 26, 2020
Closes #79.

This removes support for overloading promise operations and non-promise operations, since that would require a more ambitious approach and doesn't seem to appear on the web.
domenic added a commit that referenced this issue Apr 26, 2020
Closes #79.

This removes support for overloading promise operations and non-promise operations, since that would require a more ambitious approach and doesn't seem to appear on the web.
domenic added a commit that referenced this issue Apr 27, 2020
Closes #79.

This removes support for overloading promise operations and non-promise operations, per whatwg/webidl#776.
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.

5 participants