This document describes functions in the global scope available in the JavaScript environment for app serivices.
Global functions |
log hexdump queueMicrotask |
log(expression)
Evaluates the given expression and prints the result to the log file of the app instance using the flag LOG_APP. The function works similar to the console.log function in browsers.
Example:
log("hello world");
log("3 + 5 = " + (3 + 5));
log("message: " + JSON.stringify({ mt: "SomeMessage", value: 5 }));
Example log file:
07-29 17:05:08.982 generic@test.com JS: hello world 07-29 17:05:08.993 generic@test.com JS: 3 + 5 = 8 07-29 17:05:09.130 generic@test.com JS: message: {"mt":"SomeMessage","value":5}
hexdump(data)
Prints a hexdump of the given data to the log file of the app instance using the flag LOG_APP. Note that data can be a string or a Uint8Array.
Example:
hexdump("hello");
hexdump(new Uint8Array([0xff, 0xfe, 0xfd]));
Example log file:
07-29 17:05:08.993 generic@test.com JS: 020c816c: 68 65 6c 6c 6f hello 07-29 17:05:09.130 generic@test.com JS: 020755b8: ff fe fd ...
queueMicrotask(callback)
Queues a callback that shall be executed after the current code and all other microtasks have been completed but before yielding control to main event loop.
Remark: This is a better alternative to setting a timer for executing a callback after the current code.
Example:
log("a");
queueMicrotask(function() {
log("c");
});
log("b");
Example log file:
07-29 17:05:09.130 generic@test.com JS: a 07-29 17:05:09.130 generic@test.com JS: b 07-29 17:05:09.130 generic@test.com JS: c