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 2022-04-29 12:19:43 -05:00
parent bafdc47b1d
commit 84a01e3215
3 changed files with 8 additions and 7 deletions

13
jdk.js
View File

@ -49,6 +49,9 @@
async init(root) {
this.root = root || './jdk';
if (location.hostname == 'localhost' || location.hostname == '127.0.0.1') {
this.workerPath = this.root.split('/').slice(0, -1).join('/') + '/java2js_transpile_worker.js';
}
this.java = {};
let pkgs = ['com', 'io', 'lang', 'org', 'security', 'time', 'util'];
for (let pkg of pkgs) {
@ -222,10 +225,8 @@
let packageName = (file.match(/package\s+([^;]+)/gm) || [])[1] || 'default';
let trans;
let workerPath = this.root.split('/').slice(0, -1).join('/') + '/transpile_worker.js';
try {
let worker = new Worker(workerPath);
if (this.workerPath) {
let worker = new Worker(this.workerPath);
worker.postMessage(file);
await new Promise((resolve, reject) => {
worker.onmessage = (e) => {
@ -233,9 +234,9 @@
resolve();
};
});
} catch (ror) {
} else {
console.warn(
'Due to a likely CORS error, java2js was unable to transpile with multithreaded worker: ' + workerPath
"If you'd like java2js to transpile with the multithreaded worker (faster), due to CORS security block 'jav2js_transpile_worker.js' must be loaded from your own domain"
);
trans = java_to_javascript(file);
}

View File

@ -1,6 +1,6 @@
{
"name": "java2js",
"version": "1.2.9",
"version": "1.2.10",
"description": "Converts Java to JavaScript and runs it with a JS JDK",
"main": "jdk.js",
"scripts": {