This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): make it work to some extent
- Loading branch information
Showing
6 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
package run.slicer.poke.js; | ||
|
||
import org.teavm.jso.JSBody; | ||
import org.teavm.jso.JSByRef; | ||
import org.teavm.jso.JSExport; | ||
import org.teavm.jso.core.JSObjects; | ||
import org.teavm.jso.core.JSPromise; | ||
import org.teavm.jso.typedarrays.Uint8Array; | ||
import run.slicer.poke.Analyzer; | ||
|
||
public class Main { | ||
static { | ||
// effectively disable parallel processing support | ||
// the proper fix would be to stop proguard-core from casting threads to its own objects, | ||
// but I really can't be bothered to stub that all out | ||
System.setProperty("parallel.threads", "1"); | ||
|
||
// FIXME: InstructionSequencesReplacer breaks TeaVM | ||
System.setProperty("run.slicer.poke.peephole", "false"); | ||
} | ||
|
||
@JSExport | ||
public static @JSByRef byte[] analyze(@JSByRef byte[] data, Options options) { | ||
public static JSPromise<Uint8Array> analyze(@JSByRef byte[] data, Options options) { | ||
return analyze0(data, options == null || JSObjects.isUndefined(options) ? JSObjects.create() : options); | ||
} | ||
|
||
private static byte[] analyze0(byte[] data, Options options) { | ||
final Analyzer analyzer = Analyzer.builder() | ||
.passes(options.passes()) | ||
.optimize(options.optimize()) | ||
.verify(options.verify()) | ||
.build(); | ||
private static JSPromise<Uint8Array> analyze0(byte[] data, Options options) { | ||
return new JSPromise<>((resolve, reject) -> { | ||
new Thread(() -> { | ||
final Analyzer analyzer = Analyzer.builder() | ||
.passes(options.passes()) | ||
.optimize(options.optimize()) | ||
.verify(options.verify()) | ||
.build(); | ||
|
||
return analyzer.analyze(data); | ||
resolve.accept(wrapByteArray(analyzer.analyze(data))); | ||
}).start(); | ||
}); | ||
} | ||
|
||
@JSBody(params = {"data"}, script = "return data;") | ||
private static native Uint8Array wrapByteArray(@JSByRef byte[] data); | ||
} |
4 changes: 4 additions & 0 deletions
4
js/src/teavm/java/run/slicer/poke/js/teavm/classlib/java/util/concurrent/TThreadFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package run.slicer.poke.js.teavm.classlib.java.util.concurrent; | ||
|
||
public interface TThreadFactory { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mapClass|run.slicer.poke.js.teavm.classlib.java.util.concurrent.TExecutors=java.util.concurrent.Executors | ||
mapClass|run.slicer.poke.js.teavm.classlib.java.util.concurrent.TExecutorService=java.util.concurrent.ExecutorService | ||
mapClass|run.slicer.poke.js.teavm.classlib.java.util.concurrent.TFuture=java.util.concurrent.Future | ||
mapClass|run.slicer.poke.js.teavm.classlib.java.util.concurrent.TFuture=java.util.concurrent.Future | ||
mapClass|run.slicer.poke.js.teavm.classlib.java.util.concurrent.TThreadFactory=java.util.concurrent.ThreadFactory |