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

Fix generator for variadic arguments #119

Open
sigmundch opened this issue Dec 7, 2023 · 3 comments
Open

Fix generator for variadic arguments #119

sigmundch opened this issue Dec 7, 2023 · 3 comments

Comments

@sigmundch
Copy link
Member

Some IDLs contain variadic arguments, see for example https://www.npmjs.com/package/@webref/idl/v/3.39.1?activeTab=code:

[Exposed=(Window,Worker)]
interface TrustedTypePolicy {
  readonly attribute DOMString name;
  TrustedHTML createHTML(DOMString input, any... arguments);
  TrustedScript createScript(DOMString input, any... arguments);
  TrustedScriptURL createScriptURL(DOMString input, any... arguments);
};

We currently expose createScriptURL taking two arguments:

  external TrustedScriptURL createScriptURL(String input, JSAny? arguments);

We should probably instead expose:

  external TrustedScriptURL createScriptURL(String input, [JSAny? argument1, JSAny? argument2, JSAny? argument3]);

See workaround in https://github.com/flutter/packages/pull/5581/files#diff-fef182cc76f54d7074aee070ced4ddd44ad9233ebf438472221dc834f5f342d9

cc @ditman @srujzs

@ditman
Copy link
Member

ditman commented Dec 7, 2023

external TrustedScriptURL createScriptURL(String input, [JSAny? argument1, JSAny? argument2, JSAny? argument3]);

I tried to do this to have a variadic console.log a while back, and in one of the JS compilers (can't exactly remember which one!), all the unpassed argumentX ended up being passed as null.

Is there a better JS-interop solution to that than this?

createScriptURL(String input, [JSAny? arg1, JSAny? arg2, ..., argN]) {
  // Figure out what _createScriptURL_N to call
}
@JS('createScriptURL')
external _createScriptURL_0(String input);
...
@JS('createScriptURL')
external _createScriptURL_N(String input, JSAny? arg1, JSAny? arg2, ..., JSAny? argN)

@sigmundch
Copy link
Member Author

@srujzs - now that we do a call-size expansion of the external calls, are we still passing placeholder values for optional args? Or are we leaving them out?

@srujzs
Copy link
Contributor

srujzs commented Dec 7, 2023

now that we do a call-size expansion of the external calls, are we still passing placeholder values for optional args? Or are we leaving them out?

We should be leaving them out. We used to have procedure-level lowerings for static interop at some point earlier in the year, but we moved to call-site level lowerings, meaning that if users did not provide an argument, we do not include it in the call. @ditman, this means that that first external member you have should work as expected e.g. createScriptURL(input, 0.toJS) => createScriptURL(input, 0.toJS) and not createScriptURL(input, 0.toJS, null, null...). If this is not the case, please file a bug on the SDK!

Re: the original bug, agreed we should generate several optional parameters. How many is up to us, but 3-6 has been our range in past interop offerings.

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

No branches or pull requests

3 participants