SE-0216: User-defined dynamically callable types

Thanks for bringing this up! Some people discussed JavaScript interopability (including the binding problem) in the pitch threads for @dynamicCallable (here and here).

A useful starting point for JavaScript interop is working through how to add callable behavior for a specific implementation (e.g. extending JSValue from JavaScriptCore with callable behavior).

JSValue in particular defines the following method for performing JavaScript method calls:

extension JSValue {
  func invokeMethod(_ method: String!, withArguments arguments: [Any]!) -> JSValue!
}

At a glance, this seems exactly like something @dynamicMemberCallable can sugar.


I wonder if there are other implementations of JavaScript interop besides JSValue; thinking about how to extend those would be useful too.

2 Likes