Platforms to show: All Mac Windows Linux Cross-Platform
Back to JSContextMBS class.
JSContextMBS.CheckScriptSyntax(script as string, sourceURL as String, startingLineNumber as Integer = 1, byref JSException as JSValueMBS) as Boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Script: A string containing the script to check for syntax errors.
sourceURL: A string containing a URL for the script's source file. This is only used when reporting exceptions. Pass "" if you do not care to include source file information in exceptions.
startingLineNumber: An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
exception: A JSValue in which to store a syntax error exception, if any.
Returns true if the script is syntactically correct, otherwise false.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Creates a global JavaScript execution context.
JSContextMBS.EvaluateScript(script as string, sourceURL as String, thisObject as JSValueMBS, startingLineNumber as Integer = 1, byref JSException as JSValueMBS) as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
script: A string containing the script to evaluate.
thisObject: The object to use as "this," or nil to use the global object as "this."
sourceURL: A string containing a URL for the script's source file. This is used by debuggers and when reporting exceptions. Pass "" if you do not care to include source file information.
startingLineNumber: An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
exception: A JSValueMBS in which to store an exception, if any.
Returns the JSValue that results from evaluating script, or nil if an exception is thrown.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
JavaScript values that are on the machine stack, in a register, protected by JSValueProtect, set as the global object of an execution context, or reachable from any such value will not be collected.
During JavaScript execution, you are not required to call this function; the JavaScript engine will garbage collect as needed. JavaScript values created within a context group are automatically destroyed when the last reference to the context group is released.
JSContextMBS.NewArray(arguments() as JSValueMBS, byref JSException as JSValueMBS) as JSObjectMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
arguments: A JSValue array of data to populate the Array with.
JSException: A JSValueMBS in which to store an exception, if any.
Returns a JSObject that is an Array.
The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument is supplied, this function returns an array with one element.
Requires Mac OS X 10.6 or newer.
JSContextMBS.NewDate(arguments() as JSValueMBS, byref JSException as JSValueMBS) as JSObjectMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
arguments: A JSValue array of arguments to pass to the Date Constructor.
JSException: A JSValueMBS in which to store an exception, if any.
Returns a JSObject that is a Date.
Requires Mac OS X 10.6 or newer.
JSContextMBS.NewError(arguments() as JSValueMBS, byref JSException as JSValueMBS) as JSObjectMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
arguments: A JSValue array of arguments to pass to the Error Constructor.
JSException: A JSValueMBS in which to store an exception, if any.
Returns a JSObject that is a Error.
Requires Mac OS X 10.6 or newer.
JSContextMBS.NewFunction(name as string) as JSObjectMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
name: A string containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
Returns a JSObject that is a function. The object's prototype will be the default function prototype.
See also:
Some examples using this method:
JSContextMBS.NewFunction(name as string, parameterNames() as string, Body as String, SourceURL as string = "", startingLineNumber as Integer = 0, byref JSException as JSValueMBS) as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
name: A string containing the function's name. This will be used when converting the function to string. Pass "" to create an anonymous function.
parameterNames: A string array containing the names of the function's parameters.
body: A string containing the script to use as the function's body.
sourceURL: A string containing a URL for the script's source file. This is only used when reporting exceptions. Pass "" if you do not care to include source file information in exceptions.
startingLineNumber: An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
exception: A JSValueMBS in which to store a syntax error exception, if any. Pass nil if you do not care to store a syntax error exception.
A JSObject that is a function, or nil if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
See also:
JSContextMBS.NewObject as JSObjectMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
JSContextMBS.NewRegExp(arguments() as JSValueMBS, byref JSException as JSValueMBS) as JSObjectMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
arguments: A JSValue array of arguments to pass to the RegExp Constructor.
JSException: A JSValueMBS in which to store an exception, if any.
Returns a JSObject that is a RegExp.
Requires Mac OS X 10.6 or newer.
JSContextMBS.valueWithBool(value as boolean) as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
JSContextMBS.valueWithDouble(value as Double) as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
JSContextMBS.valueWithJSON(JSON as string) as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Returns a JSValue containing the parsed value, or nil if the input is invalid.
Available on Mac OS X 10.7 and newer
JSContextMBS.valueWithNull as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
JSContextMBS.valueWithString(value as string) as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Some examples using this method:
JSContextMBS.valueWithUndefined as JSValueMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript | MBS MacFrameworks Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
The items on this page are in the following plugins: MBS MacFrameworks Plugin.