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

Wrap generic return values #108

Closed
wants to merge 2 commits into from
Closed

Wrap generic return values #108

wants to merge 2 commits into from

Conversation

qwtel
Copy link

@qwtel qwtel commented Jun 22, 2018

Fixes wrapping of implementation classes for Promise, sequence, and record return types.

Currently, when a operation returns a promise, array, or object, the generated output will be

return utils.tryWrapperForImpl(${callOn}.${implFunc}(${argsSpread}))

which does not accomplish the goal of wrapping the implementation class for the objects contained inside.

Using promises as an example, the output should instead be:

const res = ${callOn}.${implFunc}(${argsSpread});
return res && res.then ? res.then(utils.tryWrapperForImpl) : res;

@qwtel qwtel changed the title Wrapreturn Wrap generic return values Jun 22, 2018
case "Promise": {
str += `
const res = ${callOn}.${implFunc}(${argsSpread});
return res && res.then ? res.then(utils.tryWrapperForImpl) : res;
Copy link
Member

@TimothyGu TimothyGu Jun 24, 2018

Choose a reason for hiding this comment

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

Let's make the code stricter. Only check res is null if the return type is nullable, and if it's not null (or the return type is not nullable) just do res.then(utils.tryWrapperForImpl).

if (returnType.nullable) {
  str += `
    if (res === null) {
      return res;
    } else {
  `;
}
str += `return res.then(utils.tryWrapperForImpl);`
if (returnType.nullable) {
  str += "}";
}

Ditto for the two blocks below.

@@ -13,6 +13,7 @@ class Operation {
this.idls = [idl];
this.name = idl.name;
this.static = idl.static;
this.generic = idl.idlType.generic;
Copy link
Member

Choose a reason for hiding this comment

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

This assumes that the return type of all potential overloads are the same. (That's why this.idls is an array – all overloaded operations with the same name are grouped into the same Operation object.)

stevedorries pushed a commit to stevedorries/webidl2js that referenced this pull request Jan 27, 2020
* remove m postfix

* add test

normalize \r\n to \n on the test runner + make line-comment absorb \r\n correctly.
@domenic
Copy link
Member

domenic commented Apr 17, 2020

Resurrecting this would be helpful for the Streams Standard reference implementation, which has a tee() method that returns an array. Currently I need to manually map the results using wrapperForImpl.

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.

3 participants