Giter Club home page Giter Club logo

bck2brwsr's People

Contributors

dependabot[bot] avatar eppleton avatar jamescarter avatar jhorvath avatar johanvos avatar jtulach avatar ondrej-douda avatar rqu avatar sjrd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bck2brwsr's Issues

Calling java method from javascript [Question]

I need to call some static java methods from javascript but I am unable to find a reference or tutorial to accompolish this. As far as I can see from the source code, There is a method name notation, but there isn't a reference explaining that. Is there an easier way to call some java methods from an external javascript code.

Passing byte array to javascript

I didnt check how the byte array is generated(Int8Array?) by the transpiler but, Is it possible to pass a byte array to javascript by reference (such as Int8Array) ?

Calls to System.Logger fail

The Logger interface that has been added to the System class is not available yet.
Since this is expected to be in the System class, I think it's best to add it there, rather than to have an external library providing it.

no support for System.setProperty

There is currently no support for System.getProperty() or System.getProperty().
I can add this to rt/emul/compact/src/main/java/java/lang/System.java

Missing AccessControlContext

Some functionality fails because there is no class AccessControlContext -- even though that context is not well defined.

Class.getMethod(String, Class[]) fails with null argument

The following code snippet fails. When providing a (Class[])null, an error will be reported:

java.lang.NullPointerException:TypeError: Cannot read property 'length' of null
When passing an empty Class array, it works.

  @Compare
    public boolean emptyArrayClass() {
        Class[] empty = new Class[0];
        Class klass = DummyClass.class;
        int a = 0;
        try {
            klass.getMethod("getInstance", (Class[])null);
         //   klass.getMethod("getInstance", empty); // uncomment to make it work
            a = 1;
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(JFXIssuesTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(JFXIssuesTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        return (a == 0);
    }

Allow threads to start (without guarantees when)

Although there are no guarantees that Thread.start() should start immediately, it would be useful if the method is at least implemented (not throwing a SecurityException).
I realize this might create false promises, with developers expecting their code to be executed "within a reasonable time" and if their current thread is never released, the new Thread won't start. However, in many cases with short-lived threads, it's perfectly ok.

missing comma in arguments

The following code will generate javascript code that misses a comma between the this argument and the first parameter:

       setOnKeyPressed(new EventHandler<KeyEvent>() {
            @Override public void handle(KeyEvent ke) {
                switch (ke.getCode()) {
                    case LEFT:
                        if (getEffectiveNodeOrientation() == NodeOrientation.RIGHT_TO_LEFT) {
                            processRightKey(ke);
                        } else {
                            processLeftKey(ke);
                        }
                        break;

The processRightKey(ke) is converted into the following:

(refs_com_sun_javafx_scene_control_ContextMenuContent || (refs_com_sun_javafx_scene_control_ContextMenuContent = com_sun_javafx_scene_control_ContextMenuContent(false))).processRightKey__VLjavafx_scene_input_KeyEvent_2.call(lcA0['fld_com_sun_javafx_scene_control_ContextMenuContent$1_this$0']lcA1);

Manually changing this in

(refs_com_sun_javafx_scene_control_ContextMenuContent || (refs_com_sun_javafx_scene_control_ContextMenuContent = com_sun_javafx_scene_control_ContextMenuContent(false))).processRightKey__VLjavafx_scene_input_KeyEvent_2.call(lcA0['fld_com_sun_javafx_scene_control_ContextMenuContent$1_this$0'],lcA1);

works

Occasional failures with lambda's due to missing semicolon

generated lambda code doesn't end with a semicolon. This seems to be a problem in some cases, where the code on the next line is considered part of the previous line.
While it might not be strictly needed, it is probably better to always end the generated code with a semicolon.

fatal error when an empty jar is in the classpath

When an empty jar is on the classpath, the compile process will generate an IOException in the generateEpilogue method (in case the exportedCount == 0 ).
There are cases where an artifact contains a pom file and a jar file without classes, in which case the pom file contains dependencies to a specific classifier (e.g. in javafx-graphics.jar is empty, but its pom will refer to e.g. javafx-graphics-linux.jar)

I recommend replacing the throw Exception with a Logger.info() statement.

@JavaScriptBody cannot handle props.render.@X call

--- a/src/main/java/X.java
+++ b/src/main/java/X.java
@@ -47,7 +47,10 @@
     @JavaScriptBody(args = {"namespace", "name"}, javacall = true, body = "" +
             "namespace.__custom = namespace.__custom || {};\n" +
             "if (!namespace.__custom[name]) {\n" +
-            "    namespace.__custom[name] = function (props) { return props.render.@X::render()(); }\n" +
+            "    namespace.__custom[name] = function (props) {\n" +
+            "       let r = props.render;\n" +
+            "       return r.@X::render()();\n" +
+            "    }\n" +
             "\n}; " +
             "return namespace.__custom[name];\n")
     public static native Object customComponent(Object namespace, String name);

insecure websocket

When running a transpiled app locally, everything works fine.
When running on a remote webserver, I get following fatal error:
Mixed Content: The page at 'https://abc.de/web/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://download2.gluonhq.com/heartbeat'. This request has been blocked; this endpoint must be available over WSS.

This seems to be introduced with c1fb566

Elemental2 porting

Hi,

I'm trying to convert Elemental2 to Bck2Brwsr to provide a migration path from GWT, but I'm not able to compile an initial test.

I've attached the source code adapted from the bck2brwser archetype. Do you think I'm am in the correct path?

Thanks!

xjsi.zip

The keyboard shortcut allowing to open the console of the web browser is wrong in the tutorial "Let's get started with Maven and Bck2Brwsr VM"

Hello

You wrote

While in browser console (press F12 to open it)

here whereas it's not the correct keyboard shortcut in Mozilla Firefox as you can see in its list of keyboard shortcuts. Actually, it opens the developer tools and selects the most recently used tab in Mozilla Firefox. Personally, I would rewrite the sentence to tell that F12 opens the developer tools and then you have to select the right tab to show the console as there is no way of opening the web console with exactly the same keyboard shortcut on all web browsers (Microsoft Edge uses Control + 2 where Mozilla Firefox uses Control + Shift + K).

double backslash fails in stringConcat indy

When doing something similar to

String s = a + "\" + b;

the result will only have a single backslash, which will acts as an escape for the next character, hence leading to a corrupt string.
In the constantpool, the value is as utf8:
\u0001\\\u0001

Allow native methods to be implemented by javascript code

A number of applications/libs use JNI with platform-specific implementations of native Java methods.
This can currently be done with bck2brwsr already with a JavaScript implementation, but it requires the addition of an annotation to the Java code.
By providing a simple mechanism in the bytecode2javascript generator, we can as a last resort, when there is on annotation on a native method, check if there is a javascript method that has the signature of the native method, and if so invoke it.

message in Exception not escaped

The following code snippet compiles, but will give an error at runtime:

 throw new NegativeArraySizeException("Can't resize");

It will generate:

var stA0 = new vm.java_lang_NegativeArraySizeException;
var stA1 = stA0;var stA2 = 'Can't resize to negative value: '

( the ' is not escaped)

access violation when method on superclass has same name

When a class Bar extends another class Foo, and Bar has a method with the same signature (private void sayHi) as the one om Foo, and when that method is invoked on an instance of Bar, but in a context where a Foo instance is expected, the private method on the subclass (Bar) is called instead of the method on Foo.

The bytecode contains an invokevirtual method to the method on Foo, but the translated javascript code calls the function on the passed instance (of Bar) and invokes that method (e.g. lca0.sayHi() with lca0 an instance of Bar.

The output of the program below is Hi Foo with hotspot/GraalVM, but it is Hi Bar after being converted with bck2brwsr.


package hellofx;
  
public class HelloFX {

    public static void main(String[] args) {
        Bar bar = new Bar();
        Foo.Helper.sayHello(bar);
    }
}

class Foo {
    static class Helper {
        public static void sayHello(Foo f) {
            f.sayHi();
        }
    }

    private void sayHi() {
        System.err.println("Hi Foo");
    }
}

class Bar extends Foo {

    private void sayHi() {
        System.err.println("Hi Bar");
    }
}

Class.cast and underscore doesn't work

When a package name contains _ then following code yields a class cast exception:

Obj obj = new Obj();
Obj.class.cast(obj);

caused by non-performed mangling in Class.cast - the underscore should be converted to _1.

Did Truffle run on bck2brwsr?

Hi @jtulach @JaroslavTulach

While browsing the codebase, it seems there are good bit of Truffle code or test code. Was Truffle ever run on bck2brwsr or in browser?

If yes, is it possible in theory to run or port Truffle on either bck2brwsr or other such technologies like TeaVM?

Thanks!

cast is only performed as a check

This code

    public static void superProcessCSS(Node node) {
        ((ParentHelper) getHelper(node)).superProcessCSSImpl(node);
    }

get transpiled into

    m = c.superProcessCSS__VLjavafx_scene_Node_2 = function(lcA0) {
var stA0 = c.getHelper__Lcom_sun_javafx_scene_NodeHelper_2Ljavafx_scene_Node_2(lcA0);
if (stA0 !== null && !stA0['$instOf_com_sun_javafx_scene_ParentHelper']) vm.java_lang_Class(false).castEx(stA0, 'com.sun.javafx.scene.ParentHelper');
stA0.superProcessCSSImpl__VLjavafx_scene_Node_2(lcA0);
return;
};

The value of stA0 is initially (correctly) assigned to an instance of ControlHelper which extends ParentHelper. When the object is casted to a (ParentHelper), the method invocation should use the method body from the ParentHelper, and not that of the ControlHelper.

Frequent test failure in paintTheGridOnClick test

There is a random test failure on Mac when running on top of GraalVM:

org.apidesign.bck2brwsr.vmtest.impl.Bck2BrwsrCase.paintTheGridOnClick[fxbrwsr] (from org.apidesign.bck2brwsr.kofx.KnockoutFXTest)
Failing for the past 2 builds (Since Unstable#37 )
Took 10 sec.
Error Message

timeout(101)

Stacktrace

java.lang.InterruptedException: timeout(101)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.apidesign.bck2brwsr.vmtest.impl.Bck2BrwsrCase.executeCode(Bck2BrwsrCase.java:102)

Standard Error

May 16, 2018 5:54:37 AM org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher$1 service
INFO: Request for 11 case. Sending net.java.html.json.tests.MinesTest.paintTheGridOnClick
May 16, 2018 5:54:48 AM org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher$1 service
INFO: Received result for case 11 = java.lang.InterruptedException:timeout(101)

consider making the test more stable.

Failure with lambda with equals method

    private static final Comparator<GlassScene> DIRTY_SCENE_SORTER = (o1, o2) -> {
        int i1 = o1.isSynchronous() ? 1 : 0;
        int i2 = o2.isSynchronous() ? 1 : 0;
        return i1 - i2;
    };

gets compiled into

var stA0 = (refs_java_util_Comparator || (refs_java_util_Comparator = vm.java_util_Comparator(false))).constructor.$class.$lambda([], function(args1, args2) {
      var type = c;
      var ret = type.lambda$static$0__ILcom_sun_javafx_tk_quantum_GlassScene_2Lcom_sun_javafx_tk_quantum_GlassScene_2(args2[0], args2[1]);
      ret = (refs_java_lang_Integer || (refs_java_lang_Integer = vm.java_lang_Integer(false))).valueOf__Ljava_lang_Integer_2I(ret);
      return ret;
   });
c._DIRTY_SCENE_SORTER(stA0);

which fails at runtime with

TypeError: (refs_java_util_Comparator || (intermediate value)(intermediate value)).constructor.$class.$lambda is not a function

bck2brwsr incompatible with AWS Cognito

Trying to use Amazon Cognito SDK on the same webpage as bck2brwsr. When bck2brwsr isn't initialized, this code works fine:

var login = function (e) {
               
                var user = document.getElementById("username").value;
                var password = document.getElementById("password").value;
                var loginscreen = document.getElementById("loginscreen");
                var authenticationData = {
                    Username: user,
                    Password: password
                };
                var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
                var poolData = {UserPoolId: 'eu-central-1_something',
                    ClientId: 'somethingsomething'
                };
                var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
                var userData = {
                    Username: user,
                    Pool: userPool
                };
                var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
                cognitoUser.authenticateUser(authenticationDetails, {
                    onSuccess: function (result) {
                        var accessToken = result.getAccessToken().getJwtToken();
                        // startBck2Brwsr(); <- this is my current workaround
                    },
                    onFailure: function (err) {
                        ko.dataFor(loginscreen).loginFailed();
                    }
                });
            }

When running with bck2brwsr I get a:

TypeError: undefined is not an object (evaluating 'this.config.params')

The object in question is a "this" reference inside aws-cognito-sdk.min.js . Inspecting the Object it is titled "java.lang.Object".

It's probably difficult to test this from my description alone, but I can give you private access to the project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.