Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-ui-dev] Coding an Eclipse plugin with HTML, JS (and Eclipse Browser)

Bug 510905

On Fri, Mar 31, 2017 at 2:49 PM, Christian Pontesegger <christian.pontesegger@xxxxxx> wrote:



On 31.03.2017 19:10, Leo Ufimtsev wrote:

Yea, officially, as per evaluate(), only the following types are supported:
 * <li>_javascript_ null or undefined -> <code>null</code></li>
 * <li>_javascript_ number -> <code>java.lang.Double</code></li>
 * <li>_javascript_ string -> <code>java.lang.String</code></li>
 * <li>_javascript_ boolean -> <code>java.lang.Boolean</code></li>
 * <li>_javascript_ array whose elements are all of supported types -> <code>java.lang.Object[]</code></li>
Yes, I did read about that in the slideset mentioned by Mickael. Does this also hold true within a script block?
I did see that I could call
  new java.lang.String("")
in the Interpreter. I guess if that works I could instantiate anything the classloader has access to, right? Then could I bind a java Object to a variable and access the java object in the next line?

Well, in general what happens is that we take the _javascript_ string that we get in Browser and execute it in Webkit. Then Webkit executes it in Native C code inside it's _javascript_Core engine, and when it's ready it does a callback back to java. Java then tries to read the return value. If it recognizes one of the primitive types, it converts them into java Objects (not primitives). If we get some non-recognized object, an exception is thrown. Technically it would be possible to implement other return types, but this would require Win32/Cocoa cooperation.

Browser function goes the other way. It allows you to register a function into _javascript_, so that when _javascript_ calls that function a callback is made back to java. This way some _javascript_ event can invoke Java.
Note: At time of writing, on webkit2, the browser function works, but at the end of the call, java does not return a value back to _javascript_ because webkit2 api is async.   See: Bug 510905
But this is not used as much in practice. (from the 956 repos on git.eclipse, only nebular/rich text editor uses it).


eg
var file = new java.io.File("...")
file.exists()

If that would be possible the limits of passing basic Datatypes would only apply for results returned by a script, not for script internal processes.
 
Further the code is running in the UI thread, which may not be nice for long running scripts. For UI callbacks it would be sufficient I guess

On webkit2, technically the _javascript_/webkit2 runs in a separate process, but SWT ui thread loops in the gtk_event_loop until webkit2 finishes the call to be compliant to the SWT api (which is sync). I.e, technically it would be possible to implement an async call / return mechanism, but that would require OS X and Win32 to implement something similar on their end also.
Would be something to think about in case this scenario gets interesting for a larger community. Lets see how many interested people step up here in this thread.
 

Christian

_______________________________________________
platform-ui-dev mailing list
platform-ui-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-ui-dev



--
Leo Ufimtsev
Software Engineer, Eclipse team.
Toronto, Canada

Red Hat, Inc.
Leonidas@xxxxxxxxxx | http://DeveloperBlog.RedHat.com/

Back to the top