web
web copied to clipboard
Fix generator for variadic arguments
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
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)
@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?
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.