1
0
mirror of https://github.com/quinton-ashley/java2js synced 2024-12-29 10:11:54 +01:00
This commit is contained in:
Quinton Ashley 2021-12-07 18:27:38 -05:00
parent 744a0d4887
commit 026eadeec8
3 changed files with 18 additions and 14 deletions

18
jdk.js
View File

@ -50,7 +50,7 @@
async init(root) { async init(root) {
this.root = root || 'https://unpkg.com/java2js'; this.root = root || 'https://unpkg.com/java2js';
this.java = {}; this.java = {};
let pkgs = ['com', 'lang', 'org', 'io', 'util']; let pkgs = ['com', 'lang', 'org', 'io', 'util', 'time'];
for (let pkg of pkgs) { for (let pkg of pkgs) {
this.java[pkg] = {}; this.java[pkg] = {};
} }
@ -274,21 +274,11 @@
script.onerror = (e) => { script.onerror = (e) => {
reject(e); reject(e);
}; };
// prevent page loading from the browser's cache
// if (QuintOS.context == 'live') {
// src += '?' + Date.now();
// }
script.innerHTML = trans; script.innerHTML = trans;
document.body.appendChild(script); document.body.appendChild(script);
}); });
// try {
// eval(trans);
// } catch (e) {
// console.error(e);
// if (this.ide) this.log.value += e;
// }
} }
} }
window.jdk = new JDK(); window.jdk = new JDK();
@ -19211,9 +19201,11 @@
case 'ArrayAccess': case 'ArrayAccess':
// TODO support for three dimensional arrays // TODO support for three dimensional arrays
if (expr.array.array) { if (expr.array.array) {
return `${expr.array.array.identifier}[${parseExpr(expr.array.index)}][${parseExpr(expr.index)}]`; return `${assignParent(expr.array.array.identifier)}[${parseExpr(expr.array.index)}][${parseExpr(
expr.index
)}]`;
} }
return `${expr.array.identifier}[${parseExpr(expr.index)}]`; return `${assignParent(expr.array.identifier)}[${parseExpr(expr.index)}]`;
case 'ParenthesizedExpression': case 'ParenthesizedExpression':
return `(${parseExpr(expr.expression)})`; return `(${parseExpr(expr.expression)})`;
default: default:

12
jdk/java/time/Instant.js Normal file
View File

@ -0,0 +1,12 @@
jdk.imports['java.time.Instant'].load = async () => {
class Instant {}
Instant.now = () => {
return {
toEpochMilli: () => {
return Date.now();
}
};
};
jdk.java.time.Instant = Instant;
};

View File

@ -1,6 +1,6 @@
{ {
"name": "java2js", "name": "java2js",
"version": "1.0.10", "version": "1.0.11",
"description": "Converts Java to JavaScript with support for p5.js and QuintOS.", "description": "Converts Java to JavaScript with support for p5.js and QuintOS.",
"main": "jdk.js", "main": "jdk.js",
"scripts": { "scripts": {