Javascript app runner.
More...
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <core/pubsub.h>
Go to the source code of this file.
|
|
#define | RECORD_JS_RUNNER "js_runner" |
| |
|
|
typedef struct JsRunner | JsRunner |
| |
|
typedef enum JsRunnerError | JsRunnerError |
| |
|
typedef enum JsRunnerFatal | JsRunnerFatal |
| |
|
typedef enum JsRunnerConsoleSeverity | JsRunnerConsoleSeverity |
| |
|
typedef enum JsRunnerConsoleSeparator | JsRunnerConsoleSeparator |
| |
|
typedef void(* | JsRunnerConsoleOutCallback) (JsRunnerConsoleSeverity severity, const char *buf, size_t size, JsRunnerConsoleSeparator separator, void *context) |
| |
|
typedef struct JsRunnerContextHandle | JsRunnerContextHandle |
| |
|
typedef struct JsRunnerContextInitResult | JsRunnerContextInitResult |
| |
|
typedef struct JsRunnerExecutionHandle | JsRunnerExecutionHandle |
| |
|
typedef struct JsRunnerRunResult | JsRunnerRunResult |
| |
|
typedef void(* | JsRunnerEventCallback) (const JsRunnerEvent *event, void *context) |
| |
|
| enum | JsRunnerError {
JsRunnerErrorNone = 0
, JsRunnerErrorUnknown
, JsRunnerErrorFilesystem
, JsRunnerErrorOutOfMemory
,
JsRunnerErrorParseException
, JsRunnerErrorInvalidAppId
, JsRunnerErrorResource
, JsRunnerErrorTimeout
,
JsRunnerErrorMax
} |
| |
| enum | JsRunnerFatal { JsRunnerFatalGeneric
, JsRunnerFatalOutOfMemory
} |
| |
| enum | JsRunnerConsoleSeverity { JsRunnerConsoleSeverityLog
, JsRunnerConsoleSeverityInfo
, JsRunnerConsoleSeverityWarn
, JsRunnerConsoleSeverityError
} |
| |
| enum | JsRunnerConsoleSeparator { JsRunnerConsoleSeparatorNone
, JsRunnerConsoleSeparatorSpace
, JsRunnerConsoleSeparatorNewline
} |
| |
| enum | JsRunnerEventType { JsRunnerEventTypeScriptStarted
, JsRunnerEventTypeScriptFinished
} |
| |
|
| JsRunnerContextInitResult | js_runner_context_alloc (JsRunner *instance, const char *app_id, size_t heap_size, JsRunnerConsoleOutCallback console_write_cb, void *console_write_context) |
| | Allocate a Javascript execution context.
|
| |
| void | js_runner_context_free (JsRunnerContextHandle *handle) |
| | Free a Javascript execution context.
|
| |
| JsRunnerRunResult | js_runner_run (JsRunnerContextHandle *handle, const char *path, JsRunnerEventCallback event_callback, void *context) |
| | Run a JS application.
|
| |
| JsRunnerRunResult | js_runner_run_snippet (JsRunnerContextHandle *handle, const char *code, bool print_result, JsRunnerEventCallback event_callback, void *context) |
| | Run a JS code snippet.
|
| |
| JsRunnerError | js_runner_join (JsRunnerExecutionHandle *handle, uint32_t timeout) |
| | Wait until JS run job completes.
|
| |
| void | js_runner_abort (JsRunnerExecutionHandle *handle) |
| | Forcefully terminate a running JS application.
|
| |
| void | js_runner_abort_all (JsRunner *instance) |
| | Forcefully terminate all running JS applications.
|
| |
| const char * | js_runner_get_error_message (JsRunnerError error) |
| | Get human-readable error message corresponding to an error code.
|
| |
| FuriPubSub * | js_runner_get_fatal_pubsub (JsRunner *instance) |
| | Get a pubsub which is triggered on jerryscript fatal errors.
|
| |
◆ js_runner_abort()
Forcefully terminate a running JS application.
The handle must be joined afterwards.
- Parameters
-
| handle | execution handle of the running script. |
◆ js_runner_abort_all()
| void js_runner_abort_all |
( |
JsRunner * | instance | ) |
|
Forcefully terminate all running JS applications.
- Parameters
-
| instance | JsRunner instance. Can be obtained with furi_record_open(). |
◆ js_runner_context_alloc()
| JsRunnerContextInitResult js_runner_context_alloc |
( |
JsRunner * | instance, |
|
|
const char * | app_id, |
|
|
size_t | heap_size, |
|
|
JsRunnerConsoleOutCallback | console_write_cb, |
|
|
void * | console_write_context ) |
Allocate a Javascript execution context.
- Parameters
-
| instance | JsRunner instance. Can be obtained with furi_record_open(). |
| app_id | JS application ID (see js_app_launcher). |
| heap_size | JS heap size for the app in bytes. |
| console_write_cb | callback function for JS console methods (console.log, console.error, console.info). Supply NULL to disable console. |
| console_write_context | user pointer passed to console_write_cb. |
- Returns
- operation result. If error is JsRunnerErrorNone, handle is valid.
◆ js_runner_context_free()
Free a Javascript execution context.
Any execution handles obtained with this context handle must be joined before calling this function.
- Parameters
-
| handle | context handle to be freed. |
◆ js_runner_get_error_message()
| const char * js_runner_get_error_message |
( |
JsRunnerError | error | ) |
|
Get human-readable error message corresponding to an error code.
- Parameters
-
- Returns
- error message
◆ js_runner_get_fatal_pubsub()
| FuriPubSub * js_runner_get_fatal_pubsub |
( |
JsRunner * | instance | ) |
|
Get a pubsub which is triggered on jerryscript fatal errors.
- Parameters
-
| instance | JsRunner instance. Can be obtained with furi_record_open(). |
- Returns
- the pubsub. Pubsub messages can be casted into a pointer to JsRunnerFatal.
◆ js_runner_join()
Wait until JS run job completes.
This function blocks until the script terminates. To forcefully terminate the script use js_runner_abort().
- Parameters
-
| handle | execution handle previously created by js_runner_run or js_runner_run_snippet. |
| timeout | operation timeout in ticks. |
- Returns
- operation result (JsRunnerErrorTimeout or JsRunnerErrorNone).
◆ js_runner_run()
Run a JS application.
- Parameters
-
| handle | context handle previously created by js_runner_context_alloc. |
| path | entry point script path. |
| event_callback | function to be called when an event occurs. |
| context | user pointer passed to the event_callback function. |
- Returns
- operation result. If error is JsRunnerErrorNone, handle is valid.
◆ js_runner_run_snippet()
Run a JS code snippet.
- Parameters
-
| handle | context handle previously created by js_runner_context_alloc. |
| code | JS code (encoding: UTF-8). |
| print_result | if true, evaluation result of the code snippet is printed using the console callback (severity: log). |
| event_callback | function to be called when an event occurs. |
| context | user pointer passed to the on_terminate function. |
- Returns
- operation result. If error is JsRunnerErrorNone, handle is valid.