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') + '}';
|
||||
});
|
||||
|
||||
trans.replace(/catch \(\w*/gm, 'catch (');
|
||||
|
||||
trans = trans.replace(/(\([^\(\)]*\) =>)/gm, 'async $1');
|
||||
|
||||
let prefix = `(jdk.imports['${packageName}.${className}'] = {}).load = async () => {\n\n`;
|
||||
@ -250,6 +252,7 @@
|
||||
|
||||
let suffix = '\n';
|
||||
suffix += `window.${className} = ${className};\n`;
|
||||
suffix += `console.log("loaded ${className}.java");\n`;
|
||||
suffix += '};';
|
||||
|
||||
trans = prefix + trans + suffix;
|
||||
@ -19116,7 +19119,17 @@
|
||||
const classVarsMap = {};
|
||||
|
||||
let asyncMethods = {
|
||||
Scanner: ['next', 'nextLine', 'nextInt', 'nextShort', 'nextLong', 'nextFloat', 'nextDouble']
|
||||
Scanner: [
|
||||
'hasNext',
|
||||
'hasNextLine',
|
||||
'next',
|
||||
'nextLine',
|
||||
'nextInt',
|
||||
'nextShort',
|
||||
'nextLong',
|
||||
'nextFloat',
|
||||
'nextDouble'
|
||||
]
|
||||
};
|
||||
if (typeof QuintOS != 'undefined') {
|
||||
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.getProperty = (prop) => {
|
||||
return '';
|
||||
};
|
||||
|
||||
System.arraycopy = (src, srcPos, dest, destPos, numElements) => {
|
||||
if (
|
||||
(dest instanceof Float64Array || dest instanceof Int32Array) &&
|
||||
|
@ -1,29 +1,38 @@
|
||||
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 {
|
||||
constructor(input) {
|
||||
if (input instanceof File) {
|
||||
this.inputType = 'File';
|
||||
throw 'unsupported Scanner input type: File';
|
||||
if (input.getAbsolutePath) {
|
||||
this._loading = true;
|
||||
this._filePath = input.getAbsolutePath();
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return pattern.test(this.in.stream.slice(this.in.mark));
|
||||
}
|
||||
// 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');
|
||||
}
|
||||
async nextLine() {
|
||||
return await this.next(/.*\n/);
|
||||
}
|
||||
async next(pattern) {
|
||||
while (!this.hasNext(pattern)) {
|
||||
while (this._loading || !this.hasNext(pattern)) {
|
||||
await new Promise((done) => setTimeout(() => done(), 100));
|
||||
}
|
||||
let buf = this.in.stream.slice(this.in.mark);
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "java2js",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.4",
|
||||
"description": "Converts Java to JavaScript and runs it with a JS JDK",
|
||||
"main": "jdk.js",
|
||||
"scripts": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user