Using `...` syntax on exposed API.
Author: phenomnomnominalCreated Dec 14, 2020Updated Feb 11, 2025
Hey team, I just had some fun debugging this! I have some code where I essentially do:
function blah (...args) {
const api = Comlink.wrap(worker);
return api[name](...args);
}Where the splat function call transpiles to:
return api[name].apply(api, args);The .apply triggers the get trap on the Proxy which returns another Proxy, and chaos ensues
I guess you could maybe add another guard to the get trap for this case? For now I'll just target ES2015!
Source: GoogleChromeLabs/comlink