Add compute api to js engine.

This commit is contained in:
2025-09-02 22:15:54 +08:00
parent fa2dbd79f6
commit dfee65c3af
9 changed files with 243 additions and 13 deletions

View File

@@ -4,6 +4,18 @@ Venera JavaScript Library
This library provides a set of APIs for interacting with the Venera app.
*/
/**
* @function sendMessage
* @global
* @param {Object} message
* @returns {any}
*/
/**
* Set a timeout to execute a callback function after a specified delay.
* @param callback {Function}
* @param delay {number} - delay in milliseconds
*/
function setTimeout(callback, delay) {
sendMessage({
method: 'delay',
@@ -1411,4 +1423,19 @@ function getClipboard() {
return sendMessage({
method: 'getClipboard'
})
}
}
/**
* Compute a function with arguments. The function will be executed in the engine pool which is not in the main thread.
* @param func {string} - A js code string which can be evaluated to a function. The function will receive the args as its only argument.
* @param args {any[] | null | undefined} - The arguments to pass to the function.
* @returns {Promise<any>} - The result of the function.
* @since 1.5.0
*/
function compute(func, args) {
return sendMessage({
method: 'compute',
function: func,
args: args
})
}