mirror of
https://github.com/quinton-ashley/java2js
synced 2024-12-29 10:11:54 +01:00
1.2.6
This commit is contained in:
parent
7770050412
commit
ab8675e241
@ -16,7 +16,7 @@ java2js can translate simple Java programs to JavaScript and runs them using a J
|
||||
| Double | Exception | Float |
|
||||
| Integer | Long | Short |
|
||||
| String | StringBuilder | System |
|
||||
| Thread | Throwable | |
|
||||
| Thread | | |
|
||||
|
||||
| `java.security` |
|
||||
| :-------------- |
|
||||
|
6
jdk.js
6
jdk.js
@ -66,6 +66,7 @@
|
||||
let names = [
|
||||
'Character',
|
||||
'Double',
|
||||
'Exception',
|
||||
'Float',
|
||||
'Integer',
|
||||
'Long',
|
||||
@ -19129,12 +19130,13 @@
|
||||
'nextLong',
|
||||
'nextFloat',
|
||||
'nextDouble'
|
||||
]
|
||||
],
|
||||
Thread: ['sleep']
|
||||
};
|
||||
if (typeof QuintOS != 'undefined') {
|
||||
Object.assign(asyncMethods, {
|
||||
Sprite: ['move'],
|
||||
window: ['alert', 'delay', 'erase', 'eraseRect', 'frame', 'play', 'prompt', 'text', 'textRect']
|
||||
window: ['alert', 'delay', 'eraseRect', 'frame', 'play', 'prompt', 'text', 'textRect']
|
||||
});
|
||||
}
|
||||
if (!asyncMethods.window) asyncMethods.window = [];
|
||||
|
@ -0,0 +1,13 @@
|
||||
jdk.imports['java.lang.Exception'].load = async () => {
|
||||
// TODO: should accept a PrintStream or PrintWriter
|
||||
Error.prototype.printStackTrace = function (p) {
|
||||
log(this.stack);
|
||||
};
|
||||
Error.prototype.getStackTrace = function () {
|
||||
return this.stack;
|
||||
};
|
||||
Error.prototype.getMessage = function () {
|
||||
return this.message;
|
||||
};
|
||||
jdk.java.lang.Exception = Error;
|
||||
};
|
@ -1,8 +1,9 @@
|
||||
jdk.imports['java.lang.Thread'].load = async () => {
|
||||
class Thread {
|
||||
async sleep(millis) {
|
||||
await setTimeout(millis);
|
||||
}
|
||||
}
|
||||
class Thread {}
|
||||
Thread.sleep = (millis) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, millis);
|
||||
});
|
||||
};
|
||||
jdk.java.lang.Thread = Thread;
|
||||
};
|
||||
|
@ -25,37 +25,40 @@ jdk.imports['java.util.Scanner'].load = async () => {
|
||||
// if pattern is string
|
||||
return this.in.stream.slice(this.in.mark).includes(pattern);
|
||||
}
|
||||
async hasNextLine() {
|
||||
hasNextLine() {
|
||||
return this.hasNext('\n');
|
||||
}
|
||||
async nextLine() {
|
||||
return await this.next(/.*\n/);
|
||||
nextLine() {
|
||||
return this.next(/.*/);
|
||||
}
|
||||
async next(pattern) {
|
||||
while (this._loading || !(await this.hasNext(pattern))) {
|
||||
await new Promise((done) => setTimeout(() => done(), 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
}
|
||||
let buf = this.in.stream.slice(this.in.mark);
|
||||
let substr = buf.match(pattern)[0];
|
||||
let start = buf.indexOf(substr);
|
||||
let end = buf.indexOf('\n');
|
||||
if (end == -1) {
|
||||
throw 'NoSuchElementException: No ' + pattern.toString() + ' found in buffer ' + buf;
|
||||
}
|
||||
this.in.read(end - start + 1);
|
||||
return buf.slice(start, end);
|
||||
return buf.slice(start, substr.length);
|
||||
}
|
||||
async nextShort() {
|
||||
return await this.nextInt();
|
||||
nextShort() {
|
||||
return this.nextInt();
|
||||
}
|
||||
async nextInt() {
|
||||
return Number(await this.next(/\d+\D/));
|
||||
return Number(await this.next(/\d+/));
|
||||
}
|
||||
async nextLong() {
|
||||
return await this.nextInt();
|
||||
nextLong() {
|
||||
return this.nextInt();
|
||||
}
|
||||
async nextFloat() {
|
||||
return Number(await this.next(/[0-9\.]+[^0-9\.]/));
|
||||
return Number(await this.next(/[0-9\.]+/));
|
||||
}
|
||||
async nextDouble() {
|
||||
return await this.nextFloat();
|
||||
nextDouble() {
|
||||
return this.nextFloat();
|
||||
}
|
||||
close() {}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "java2js",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"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