Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple mapping of native methods to javascript implementations. #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johanvos
Copy link
Contributor

This fixes #42
As an example, native methods in JavaFX rendering code
For example:

private static native void nTexSubImage2D0(int target, int level,
            int xoffset, int yoffset, int width, int height, int format,
            int type, Object pixels, int pixelsByteOffset);

(see https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java#L185)

maps to

function native_com_sun_prism_es2_GLContext_nTexSubImage2D0(target, level,
        xoffset, yoffset, width, height, format, type, pixels, pixelsByteOffset) {

(see https://github.com/gluonhq/uongl/blob/master/src/main/javascript/uongl.js#L451)

This allows existing libraries with JNI to be used without having access to the code.

@jtulach
Copy link
Owner

jtulach commented Jul 28, 2021

Where does the native_com_sun_prism_es2_GLContext_nTexSubImage2D0 method come from? From a global scope? That's nasty. Bck2Brwsr tries to limit the number of globally visible symbols - only bck2brwsr symbol is available after booting. The rest is hidden in each Bck2Brwsr generated .js file.

Exposing new contract via global scope seems a bit too hacky. I'd rather recommend to use (more verbose, but) existing contract as shown in fe5bdfa. It should cover the same cases (except when the native method is called in static class initializer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow native methods to be implemented by javascript code
2 participants