Describe your motivation
For any non-trivial executeJs expression, it's good practice to extract each positional parameter such as $0 into a named variable, e.g. const foo = $0;. This enables using the value based on the name as doSomething(foo) instead of doSomething($0).
Describe the solution you'd like
Make it possible to provide explicitly named parameters from the server so that the JS expression can directly use that name without ever mentioning $0.
Usage could look like this:
element.executeJs("doSomething(foo)").withParameter("foo", "Some value");
PendingJavaScriptResult is also used by callJsFunction where a separate withParameter makes no sense. We should thus introduce a subtype of PendingJavaScriptResult with named parameter support that is used only by executeJs but not callJsFunction.
It should also not be allowed to add new parameters after isSentToBrowser() has changed to true.
A similar method should also be added to the JsFunction API.
Describe alternatives you've considered
As an alternative to chaining on the return value, a map of named parameters could also be passed directly to executeJs. The problem is that this would be ambiguous with a regular map Map since executeJs(script, Map.of("foo", "Some value")); could also be seen as passing a map as $0. That could be made compatible either by also passing the map as $0 or by introducing a new dedicated type that won't be used in existing code. I still prefer withParameter since it's more ergonomic to continue on the existing method rather than separately building a Map or a dedicated parameter-passing object.
Describe your motivation
For any non-trivial
executeJsexpression, it's good practice to extract each positional parameter such as$0into a named variable, e.g.const foo = $0;. This enables using the value based on the name asdoSomething(foo)instead ofdoSomething($0).Describe the solution you'd like
Make it possible to provide explicitly named parameters from the server so that the JS expression can directly use that name without ever mentioning
$0.Usage could look like this:
PendingJavaScriptResultis also used bycallJsFunctionwhere a separatewithParametermakes no sense. We should thus introduce a subtype ofPendingJavaScriptResultwith named parameter support that is used only byexecuteJsbut notcallJsFunction.It should also not be allowed to add new parameters after
isSentToBrowser()has changed totrue.A similar method should also be added to the
JsFunctionAPI.Describe alternatives you've considered
As an alternative to chaining on the return value, a map of named parameters could also be passed directly to
executeJs. The problem is that this would be ambiguous with a regular mapMapsinceexecuteJs(script, Map.of("foo", "Some value"));could also be seen as passing a map as$0. That could be made compatible either by also passing the map as$0or by introducing a new dedicated type that won't be used in existing code. I still preferwithParametersince it's more ergonomic to continue on the existing method rather than separately building aMapor a dedicated parameter-passing object.