alicorn-systems/v8-adapter

Add ability to read data from V8 JS object

Closed this issue · 6 comments

Right now when class is "injected" to V8, it's methods could have arguments as

  • primitives & String
  • or another Java class, which was injected from Java to V8 previously.

For example, there is no way to read data from JS object {y: 'done'} when it passed to java method - following exception is thrown:

IllegalArgumentException: No signature exists for readJsObjectAsJavaObjectAndTryGetY with parameters [[object Object], ].

Instead, when there is call similar to x.readJsObjectAsMapAndGetY({y: 'done'}), it should try to "translate" the content of the JS object to Java object, e.g. Map.
Here x is our Java class.

Pull request is ready: #8

Meanwhile I will check is something similar needed/possible for JS arrays.

Btw, issue #5 looks similar, but for JS function.

caer commented

Awesome, will review your PR and leave any comments on this feature there. Please do look into arrays; I remember them being a complicated problem that I couldn't justify work for at the time...would be interested to see what you find.

I've responded to #5 just now; it looks like it can be solved using our dynamic interface generation feature, so I am going to close it for now.

@crahda thanks for taking care of this pull request for fast.
For the array I have only added possibility to be read as list (and V8Array just in case). I will look once again on all the array's code later.
Concerning #5 - I don't see how we can call v8 function with native JS code from Java now without using V8Function (having only Functional interface). But I will try to add unit test and check if it's actually working.

Btw, all the changes in the pull request - #9

caer commented

Excellent! I will review #9 ; there's a lot of code there.

Refer to this test:

https://github.com/alicorn-systems/v8-adapter/blob/master/src/test/java/io/alicorn/v8/V8JavaAdapterTest.java#L288

For an example of dynamic function injection.

@crahda I have checked this Junit test and related functionality and it's great.
(Looks like since I have not used yet this JS call-backs - I have missed it.)

caer commented

Awesome, glad to hear it!