jtulach / bck2brwsr Goto Github PK
View Code? Open in Web Editor NEWBck2Brwsr VM to transpile Java bytecode to JavaScript
Home Page: http://bck2brwsr.apidesign.org
License: Other
Bck2Brwsr VM to transpile Java bytecode to JavaScript
Home Page: http://bck2brwsr.apidesign.org
License: Other
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
--- 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);
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!
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
Some functionality fails because there is no class AccessControlContext -- even though that context is not well defined.
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) ?
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.
where it takes jvm assembly code and assembles it into jvm bytecode and vice-versa?
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.
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.
Is there capability to compile java bytecode to wasm?
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.
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);
}
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
.
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");
}
}
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.
bck2brwsr.js should be able to detect the web worker environment and run the code that does not need to interact with the DOM.
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.
java.lang.Class.getPackage() is not yet implemented
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
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)
Hi,
I'm trying to put a @net.java.html.js.JavaScriptBody
in a constructor but it generates wrong code.
Is it supported?
Thanks!
underscores are used to escape .
, but if a class has an underscore in its name (which happens to be the case with classes holding shader functionality in openjfx), this makes it impossible to retrieve them via class.forName
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
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!
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.
Is there an option to merge bck2brwsr.js with the produced code into a single javascript file?
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
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.
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.
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).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.