![]() |
Qore v8 Module 1.0.0
|
The v8
module allows for the execution and management of JavaScript code in Qore.
To use the module in a Qore script, use the %requires
directive as follows:
Note that while JavaScript and v8 support threading, calls into a single JavaScriptProgram are subject to thread serialization; only one thread can be active
Also included with the v8
module:
Main classes:
Source JavaScript Type | Target Qore Type |
bool | bool |
int32 , uint32 , bigint | int or number if greater than 64-bits |
number | float |
array | list |
string | string |
object | V8::JavaScriptObject |
null , undefined | NOTHING |
Other JavaScript types cannot be converted to Qore; attempting to convert an unsupported type will result in a runtime exception.
Source Qore Type | Target JavaScript Type |
binary | string (base64-encoded value) |
bool | bool |
date | string (ISO-8601 format) |
float | number |
hash | object |
int | int32 , uint32 , bigint |
list | array |
string | string |
V8::JavaScriptObject | object |
code | callable object |
NOTHING , NULL | null |
Other Qore types cannot be converted to JavaScript; attempting to convert an unsupported type will result in a runtime exception.
Exceptions in JavaScript are propagated to Qore as Qore exceptions.
Qore's deterministic garbage collection approach and reliance on destructors means that references to Qore data stored in JavaScript must have their reference counts managed externally.
JavaScript objects storing references to Qore data hold only weak references to Qore data.
By default, Qore references are saved in thread-local data, so the lifecycle of the object is automatically limited to the existence of the thread.
The thread-local hash key name used to save the list of objects created is determined by the value of the "_v8_save"
thread-local key, if set. If no such key is set, then "_v8_save"
is used instead as the literal key for saving the list of objects.
References to Qore data can be managed explicitly by using the JavaScriptProgram::setSaveReferenceCallback() method to set a callback that is called every time a Qore references is stored in a JavaScript object.
This callback must take a single auto
argument as in the following example: