Class

JSContext

A JSContext object represents a JavaScript execution environment. You create and use JavaScript contexts to evaluate JavaScript scripts from Objective-C or Swift code, to access values defined in or calculated in JavaScript, and to make native objects, methods, or functions accessible to JavaScript.

Declaration

@interface JSContext : NSObject

Topics

Creating JavaScript Contexts

- init

Initializes a new JavaScript context.

- initWithVirtualMachine:

Creates a new JavaScript context associated with a specific virtual machine.

Evaluating Scripts

- evaluateScript:

Executes the specified JavaScript code.

- evaluateScript:withSourceURL:

Executes the specified JavaScript code, treating the specified URL as its source location.

Inspecting Callback State in a Running Context

+ currentContext

Returns the context currently executing JavaScript code.

+ currentCallee

Returns the currently executing JavaScript function.

+ currentThis

Returns the value of the this keyword in currently executing JavaScript code.

+ currentArguments

Returns the arguments to the current native callback from JavaScript code.

Working with JavaScript Global State

globalObject

The JavaScript global object associated with the context.

exception

A JavaScript exception to be thrown in evaluation of the script.

exceptionHandler

A block to be invoked should evaluating a script result in a JavaScript exception being thrown.

virtualMachine

The JavaScript virtual machine to which the context belongs.

name

A descriptive name for the context.

Accessing JavaScript Global State with Subscripts

- objectForKeyedSubscript:

Returns the value of the specified JavaScript property in the context’s global object, allowing subscript getter syntax.

- setObject:forKeyedSubscript:

Sets the specified JavaScript property of the context’s global object, allowing subscript setter syntax.

Working with the C JavaScriptCore API

JSGlobalContextRef

Returns the C representation of the JavaScript context.

+ contextWithJSGlobalContextRef:

Creates a JavaScript context object from the equivalent C representation.

Relationships

Inherits From