Open REASY opened 4 years ago
Hi @REASY
thanks for your report. I can confirm this is not working at the moment.
The problem on your side should be easy to fix. You are using a ProxyObject
in https://github.com/REASY/graalvm-js-bind-issue/blob/main/src/main/java/com/examples/graalvm/blink/Document.java and from the error message above I take that's what you try to bind. This will fail just like binding a plain JavaScript object would fail: you have to bind something that represents a function. Solution is simple here: just implement ProxyExecutable
additionally.
(edit: just saw you actually return a ProxyExecutable
from your proxy).
This, however, does not suffice to bind
the proxy, as we have not implemented this case currently. The current interop protocol does not allow to specify the this
when calling, so we cannot implement bind
with correct semantics at the moment. We could just call the function and ignore the bound this
, but that could be very surprising to the users.
We are currently investigating our options.
Best, Christian
Hi, @wirthi
Thanks for the reply. Yes, for now I'm wrapping the code by JS function and it works, something like this:
val jsWindow = ctx.eval("js", "window;")
// Document has method `createElement0`
jsWindow.putMember("document", new Document)
// Wrap
ctx.eval(Source.newBuilder("js", "document.createElement=function(){ return document.createElement0(arguments); };",
"init.js").build)
Hi @REASY
the workaround seems fine. But why did you try to bind it then in the first place? The effect of binding is to change the this
, and your workaround is fine without that, so why bind
in the first place? Was that just convenience to a function outside the scope of document
?
Thanks, Christian
@wirthi it is some existing JS code, I just experienced that behavior in case of GraalJS
The following JS code works in Google Chrome:
And produces
But when I use GraaJS v20.2.0 with proxy Document objec: https://github.com/REASY/graalvm-js-bind-issue/blob/8402fbb326125db62414a4348ed63cbc70fee6f6/src/main/java/com/examples/graalvm/blink/Document.java#L9t to execute that code https://github.com/REASY/graalvm-js-bind-issue/blob/main/src/main/scala/com/examples/graalvm/BindExample.scala#L20-L23, I get the exception
org.graalvm.polyglot.PolyglotException: TypeError: com.examples.graalvm.blink.Document$1@103441bb is not a function
:GraalVM params:
GraalVM version: 20.2.0 JVM: Oracle JDK 1.8.0_251 Repo: https://github.com/REASY/graalvm-js-bind-issue