0
votes

This is admittedly weird, but bear with me:

I'm using Dart's js-interop package so that I can call from Dart into JavaScript.

The system I have to work with has a communication path via a particular global JavaScript object - this object is inserted into the JavaScript context as a way to call into native code, but it's not a true JavaScript object; it's a little hacky.

I can't make a Dart Proxy directly to this object because the Proxy code depends on certain constructors and aspects of the prototype chain that don't exist for this hacky object. Specifically, the JsObject_JsObject function generated by dart2js tries to call "constr.bind.apply" where constr is the constructor of the JS object. This object doesn't have a .bind property since it doesn't inherit correctly from other stuff, and all my attempts to add/fix the prototype chain have failed so far.

If I could fix that, it'd be great. But my other option is to proxy a proxy - make a true Javascript object that wraps and proxies the wacky-hacky-native-object, then a Dart Proxy for that.

I'm curious what the cleanest way to make that JS proxy would be - I'd like to call various functions from Dart, with varying numbers of parameters, and have the calls pass through cleanly to the native object, without having to constantly maintain my JS proxy by making sure any functions added to the native object are added to the proxy.

Does anybody have any great/creepy ideas to make this proxy idiot-proof so that it doesn't need a lot of maintenance, but just automagically redirects calls to the native object?

1

1 Answers

0
votes

constr.bind.apply is only call on Js Object creation from Dart. You can simply make a JS function that creates your particular JS Object (for instance createWtfObject()). Once created on JS side (by calling from Dart context.callMethod('createWtfObject')) you should be able to use it without problem from Dart side.