mirror of
https://github.com/quinton-ashley/java2js
synced 2024-12-29 10:11:54 +01:00
1.2.4
This commit is contained in:
parent
099404d57b
commit
d1290927ab
15
jdk.js
15
jdk.js
@ -229,6 +229,8 @@
|
|||||||
return '() => {' + p1.replaceAll('\\n', '\n') + '}';
|
return '() => {' + p1.replaceAll('\\n', '\n') + '}';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
trans.replace(/catch \(\w*/gm, 'catch (');
|
||||||
|
|
||||||
trans = trans.replace(/(\([^\(\)]*\) =>)/gm, 'async $1');
|
trans = trans.replace(/(\([^\(\)]*\) =>)/gm, 'async $1');
|
||||||
|
|
||||||
let prefix = `(jdk.imports['${packageName}.${className}'] = {}).load = async () => {\n\n`;
|
let prefix = `(jdk.imports['${packageName}.${className}'] = {}).load = async () => {\n\n`;
|
||||||
@ -250,6 +252,7 @@
|
|||||||
|
|
||||||
let suffix = '\n';
|
let suffix = '\n';
|
||||||
suffix += `window.${className} = ${className};\n`;
|
suffix += `window.${className} = ${className};\n`;
|
||||||
|
suffix += `console.log("loaded ${className}.java");\n`;
|
||||||
suffix += '};';
|
suffix += '};';
|
||||||
|
|
||||||
trans = prefix + trans + suffix;
|
trans = prefix + trans + suffix;
|
||||||
@ -19116,7 +19119,17 @@
|
|||||||
const classVarsMap = {};
|
const classVarsMap = {};
|
||||||
|
|
||||||
let asyncMethods = {
|
let asyncMethods = {
|
||||||
Scanner: ['next', 'nextLine', 'nextInt', 'nextShort', 'nextLong', 'nextFloat', 'nextDouble']
|
Scanner: [
|
||||||
|
'hasNext',
|
||||||
|
'hasNextLine',
|
||||||
|
'next',
|
||||||
|
'nextLine',
|
||||||
|
'nextInt',
|
||||||
|
'nextShort',
|
||||||
|
'nextLong',
|
||||||
|
'nextFloat',
|
||||||
|
'nextDouble'
|
||||||
|
]
|
||||||
};
|
};
|
||||||
if (typeof QuintOS != 'undefined') {
|
if (typeof QuintOS != 'undefined') {
|
||||||
Object.assign(asyncMethods, {
|
Object.assign(asyncMethods, {
|
||||||
|
4
jdk/java/io/FileNotFoundException.js
Normal file
4
jdk/java/io/FileNotFoundException.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
jdk.imports['java.io.FileNotFoundException'].load = async () => {
|
||||||
|
class FileNotFoundException {}
|
||||||
|
jdk.java.io.FileNotFoundException = FileNotFoundException;
|
||||||
|
};
|
@ -12,6 +12,10 @@ jdk.imports['java.lang.System'].load = async () => {
|
|||||||
System.in.mark += length;
|
System.in.mark += length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
System.getProperty = (prop) => {
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
System.arraycopy = (src, srcPos, dest, destPos, numElements) => {
|
System.arraycopy = (src, srcPos, dest, destPos, numElements) => {
|
||||||
if (
|
if (
|
||||||
(dest instanceof Float64Array || dest instanceof Int32Array) &&
|
(dest instanceof Float64Array || dest instanceof Int32Array) &&
|
||||||
|
@ -1,29 +1,38 @@
|
|||||||
jdk.imports['java.util.Scanner'].load = async () => {
|
jdk.imports['java.util.Scanner'].load = async () => {
|
||||||
const File = await jdk.import('java.io.File');
|
const InputStream = await jdk.import('java.io.InputStream');
|
||||||
|
|
||||||
class Scanner {
|
class Scanner {
|
||||||
constructor(input) {
|
constructor(input) {
|
||||||
if (input instanceof File) {
|
if (input.getAbsolutePath) {
|
||||||
this.inputType = 'File';
|
this._loading = true;
|
||||||
throw 'unsupported Scanner input type: File';
|
this._filePath = input.getAbsolutePath();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.in = input;
|
this.in = input;
|
||||||
}
|
}
|
||||||
hasNext(pattern) {
|
async _loadFile(filePath) {
|
||||||
|
this.in = new InputStream();
|
||||||
|
this.in.stream = await (await fetch(filePath)).text();
|
||||||
|
this._loading = false;
|
||||||
|
}
|
||||||
|
async hasNext(pattern) {
|
||||||
|
if (this._loading) {
|
||||||
|
await this._loadFile(this._filePath);
|
||||||
|
}
|
||||||
if (pattern instanceof RegExp) {
|
if (pattern instanceof RegExp) {
|
||||||
return pattern.test(this.in.stream.slice(this.in.mark));
|
return pattern.test(this.in.stream.slice(this.in.mark));
|
||||||
}
|
}
|
||||||
// if pattern is string
|
// if pattern is string
|
||||||
return this.in.stream.includes(pattern);
|
return this.in.stream.slice(this.in.mark).includes(pattern);
|
||||||
}
|
}
|
||||||
hasNextLine() {
|
async hasNextLine() {
|
||||||
return this.hasNext('\n');
|
return this.hasNext('\n');
|
||||||
}
|
}
|
||||||
async nextLine() {
|
async nextLine() {
|
||||||
return await this.next(/.*\n/);
|
return await this.next(/.*\n/);
|
||||||
}
|
}
|
||||||
async next(pattern) {
|
async next(pattern) {
|
||||||
while (!this.hasNext(pattern)) {
|
while (this._loading || !this.hasNext(pattern)) {
|
||||||
await new Promise((done) => setTimeout(() => done(), 100));
|
await new Promise((done) => setTimeout(() => done(), 100));
|
||||||
}
|
}
|
||||||
let buf = this.in.stream.slice(this.in.mark);
|
let buf = this.in.stream.slice(this.in.mark);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "java2js",
|
"name": "java2js",
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"description": "Converts Java to JavaScript and runs it with a JS JDK",
|
"description": "Converts Java to JavaScript and runs it with a JS JDK",
|
||||||
"main": "jdk.js",
|
"main": "jdk.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user