-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from eaglerforge/main
Update stable to latest build
- Loading branch information
Showing
14 changed files
with
210 additions
and
816 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//SUCCESS - While there is no TeaVM thread actively running, I am able to run an asyncronous function, and get a result. | ||
ModAPI.hooks._teavm.$rt_startThread(() => { | ||
return ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI(ModAPI.util.str("data:text/plain,hi")) | ||
}, function (...args) { console.log(this, args) }) | ||
|
||
|
||
//WIP - Pausing and resuming client thread | ||
globalThis.suspendTest = function (...args) { | ||
if (!ModAPI.util.isCritical()) { | ||
var thread = ModAPI.hooks._teavm.$rt_nativeThread(); | ||
var javaThread = ModAPI.hooks._teavm.$rt_getThread(); | ||
globalThis.testThread = thread; | ||
console.log("BeforeAnything: ", thread.stack); | ||
thread.suspend(function () { | ||
console.log("Pausing for 10 seconds.", thread.stack); | ||
setTimeout(function () { | ||
console.log("Resuming...", thread.stack); | ||
ModAPI.hooks._teavm.$rt_setThread(javaThread); | ||
thread.resume(); | ||
console.log("After resume: ", thread.stack); | ||
}, 10000); | ||
}); | ||
} | ||
return suspendTest.apply(this, args); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
function jl_Thread_sleep$_asyncCall_$(millis) { | ||
var thread = $rt_nativeThread(); | ||
var javaThread = $rt_getThread(); | ||
var callback = function () { }; | ||
callback.$complete = function (val) { | ||
thread.attribute = val; | ||
$rt_setThread(javaThread); | ||
thread.resume(); | ||
}; | ||
callback.$error = function (e) { | ||
thread.attribute = $rt_exception(e); | ||
$rt_setThread(javaThread); | ||
thread.resume(); | ||
}; | ||
callback = otpp_AsyncCallbackWrapper_create(callback); | ||
thread.suspend(function () { | ||
try { | ||
jl_Thread_sleep0(millis, callback); | ||
} catch ($e) { | ||
callback.$error($rt_exception($e)); | ||
} | ||
}); | ||
return null; | ||
} | ||
function jl_Thread_sleep0($millis, $callback) { | ||
var $current, $handler; | ||
$current = jl_Thread_currentThread(); | ||
$handler = new jl_Thread$SleepHandler; | ||
$handler.$thread = $current; | ||
$handler.$callback = $callback; | ||
$handler.$scheduleId = otp_Platform_schedule($handler, Long_ge($millis, Long_fromInt(2147483647)) ? 2147483647 : Long_lo($millis)); | ||
$current.$interruptHandler = $handler; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Babel plugin to transform functions and calls | ||
const ASYNC_PLUGIN_1 = function ({ types: t }) { | ||
return { | ||
visitor: { | ||
FunctionDeclaration(path) { | ||
console.log(path); | ||
path.node.async = true; | ||
}, | ||
ArrowFunctionExpression(path) { | ||
console.log(path); | ||
path.node.async = true; | ||
}, | ||
CallExpression(path) { | ||
console.log(path); | ||
if (path.parent.type !== 'AwaitExpression') { | ||
path.replaceWith( | ||
t.awaitExpression(path.node) | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
async function asyncify(input) { | ||
let isHtml = true; | ||
let inputHtml = input; | ||
|
||
// Check if the input is raw JavaScript | ||
if (!input.trim().startsWith('<')) { | ||
isHtml = false; | ||
inputHtml = `<script>${input}</script>`; | ||
} | ||
|
||
_status("[ASYNC_PLUGIN_1] Parsing html..."); | ||
await wait(50); | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(inputHtml, 'text/html'); | ||
const scriptTags = doc.querySelectorAll('script'); | ||
|
||
for (let i = 0; i < scriptTags.length; i++) { | ||
const scriptTag = scriptTags[i]; | ||
const code = scriptTag.textContent; | ||
_status("[ASYNC_PLUGIN_1] Transpiling script #" + (i + 1) + " of length " + Math.round(code.length / 1000) + "k..."); | ||
await wait(50); | ||
|
||
|
||
const output = Babel.transform(code, { | ||
plugins: [ASYNC_PLUGIN_1] | ||
}); | ||
scriptTag.textContent = output.code; | ||
} | ||
|
||
_status("[ASYNC_PLUGIN_1] Job complete!"); | ||
await wait(50); | ||
|
||
if (isHtml) { | ||
return doc.documentElement.outerHTML; | ||
} else { | ||
return doc.querySelector('script').textContent; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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 @@ | ||
globalThis.modapi_postinitasync = "(" + (() => { | ||
//EaglerForge post initialization code for async. | ||
|
||
}).toString() + ")();"; |
Oops, something went wrong.