Platforms to show: All Mac Windows Linux Cross-Platform
Back to JavaScriptEngineMBS class.
JavaScriptEngineMBS.AddFunction(Name as String, JavaScript as String, FileName as String = "")
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Optional provide a file name to show in stack traces.
Function source code may contain a function name, but we use only the name parameter to register the function as global one.
Some examples using this method:
JavaScriptEngineMBS.CallFunction(Name as String, ParamArray Params as Variant) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Parameters are passed to the function.
If the function needs more parameter, undefined values are used to fill up.
If the function needs less parameters, additional ones are dropped.
Returns the result of the function converted to a variant.
See also:
JavaScriptEngineMBS.CallFunction(Name as String, Params() as Variant) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Parameters are passed to the function.
If the function needs more parameter, undefined values are used to fill up.
If the function needs less parameters, additional ones are dropped.
Returns the result of the function converted to a variant.
See also:
JavaScriptEngineMBS.CallFunctionMT(Name as String, ParamArray Params as Variant) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Threaded version of CallFunction. If events or delegates are called on main thread, the preemptive thread waits for answer.
Parameters are passed to the function.
If the function needs more parameter, undefined values are used to fill up.
If the function needs less parameters, additional ones are dropped.
Returns the result of the function converted to a variant.
The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.
See also:
Some examples using this method:
JavaScriptEngineMBS.CallFunctionMT(Name as String, Params() as Variant) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Threaded version of CallFunction. If events or delegates are called on main thread, the preemptive thread waits for answer.
Parameters are passed to the function.
If the function needs more parameter, undefined values are used to fill up.
If the function needs less parameters, additional ones are dropped.
Returns the result of the function converted to a variant.
The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.
See also:
JavaScriptEngineMBS.DateComponentsToTime(date as JavaScriptDateComponentsMBS) as Double
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Convert components (year, month, day, etc), interpreted in UTC, into a time value. The weekday argument is ignored in the conversion. If the component values are invalid, an error is thrown.
There are some differences to the ECMAScript Date.UTC() built-in:
- There's no special handling of two-digit years. For example, Date.UTC(99, 0, 1) gets interpreted as 1999-01-01. If time is 99, it's interpreted as the year 99.
- The milliseconds component is allowed fractions (sub-millisecond resolution) so that the resulting time value may have fractions.
Like the ECMAScript primitives, the components can exceed their natural range and are normalized. For example, specifying minute as 120 is interpreted as adding 2 hours to the time value. The components are expressed as Integers to allow large and negative values to be used.
JavaScriptEngineMBS.Destructor
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
JavaScriptEngineMBS.Evaluate(JavaScript as String) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
This may include definition of functions and objects and using them.
Result is converted to variant and returned.
JavaScriptEngineMBS.EvaluateMT(JavaScript as String) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Threaded version of Evaluate. If events or delegates are called on main thread, the preemptive thread waits for answer.
This may include definition of functions and objects and using them.
Result is converted to variant and returned.
The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.
JavaScriptEngineMBS.EvaluateToString(JavaScript as String) as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
This may include definition of functions and objects and using them.
Result is converted to string in JavaScript and returned as Xojo string.
Some examples using this method:
JavaScriptEngineMBS.GlobalMemoryBlock(PropertyName as String) as MemoryBlock
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
A normal memoryblock passed as parameter to a function or property would be copied.
This method allows you to define a buffer in JavaScript to reference the bytes in a memoryblock, so all changes are visible in Xojo directly.
You can assign nil as value to clear a memoryblock.
(Read and Write computed property)
Some examples using this property:
JavaScriptEngineMBS.GlobalProperty(PropertyName as String) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Values are converted to/from variant.
(Read and Write computed property)
JavaScriptEngineMBS.GlobalPropertyJSON(PropertyName as String) as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Same as GlobalProperty, but needs JSON text.
(Read and Write computed property)
JavaScriptEngineMBS.InitModules
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 21.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Only calls JS.InitModules once on a new instance of the JavaScript engine.
Define your own Duktape.modSearch() to provide environment specific module lookups.
After these steps, require() will be registered to the global object and the module system is ready to use.
JavaScriptEngineMBS.LoadFunction(Name as String, Data as Memoryblock) as Boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Load a buffer containing bytecode, recreating the original ECMAScript function (with some limitations). You must ensure that the bytecode has been dumped with a compatible Duktape version and that the bytecode has not been modified since. Loading bytecode from an untrusted source is memory unsafe and may lead to exploitable vulnerabilities.
Returns true in case of success or false on failure.
JavaScriptEngineMBS.Now as Double
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
This is seconds since 1st January 1970 multiplied by 1000 and may contain fraction with microseconds.
Get current time in POSIX milliseconds, as seen by the ECMAScript environment. The return value matches Date.now() with the reservation that sub-millisecond resolution may be available.
JavaScriptEngineMBS.RegisterFunction(Name as String, theDelegate as JavaScriptEngineDelegateMBS, ArgCount as Integer = -1, tag as Variant = nil)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
ArgCount can be in range from -1 to 15.
If -1 is passed, we allow variable number of arguments.
Tag is passed to delegate and allows you to pass a context object to the delegate.
Some examples using this method:
JavaScriptEngineMBS.SaveFunction(Name as String) as MemoryBlock
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Dump an ECMAScript function at stack top into bytecode, replacing the function with a buffer containing the bytecode data. The bytecode can be loaded back using LoadFunction().
JavaScriptEngineMBS.TimeToDateComponents(time as Double) as JavaScriptDateComponentsMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS Tools Plugin | 20.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Convert a time value to components (year, month, day, etc) interpreted in UTC. If the time value is invalid, e.g. beyond the valid ECMAScript time range, an error is thrown.
There are some differences to the ECMAScript Date UTC accessors like Date.prototype.getUTCMinutes():
The time value is allowed to have fractions (sub-millisecond resolution) so that the millisecond component may also have fractions.
The items on this page are in the following plugins: MBS Tools Plugin.
