<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSContext",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSContext"
  },
  "title" : "JSContext"
}
-->

# JSContext

A JavaScript execution environment.

```
class JSContext
```

## Overview

You create and use JavaScript contexts to evaluate JavaScript scripts from Objective-C or Swift code; to access values that JavaScript defines or calculates; and to make native objects, methods, or functions accessible to JavaScript.

## Topics

### Creating JavaScript contexts

[`init()`](/documentation/JavaScriptCore/JSContext/init())

Initializes a new JavaScript context.

[`init(virtualMachine:)`](/documentation/JavaScriptCore/JSContext/init(virtualMachine:))

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

### Making JavaScript context inspectable

[`isInspectable`](/documentation/JavaScriptCore/JSContext/isInspectable)

A Boolean value that indicates whether you can inspect the JavaScript context with Safari Web Inspector.

### Evaluating scripts

[`evaluateScript(_:)`](/documentation/JavaScriptCore/JSContext/evaluateScript(_:))

Executes the specified JavaScript code.

[`evaluateScript(_:withSourceURL:)`](/documentation/JavaScriptCore/JSContext/evaluateScript(_:withSourceURL:))

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

### Inspecting callback state in a running context

[`current()`](/documentation/JavaScriptCore/JSContext/current())

Returns the context currently executing JavaScript code.

[`currentCallee()`](/documentation/JavaScriptCore/JSContext/currentCallee())

Returns the currently executing JavaScript function.

[`currentThis()`](/documentation/JavaScriptCore/JSContext/currentThis())

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

[`currentArguments()`](/documentation/JavaScriptCore/JSContext/currentArguments())

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

### Working with JavaScript global state

[`globalObject`](/documentation/JavaScriptCore/JSContext/globalObject)

The JavaScript global object associated with the context.

[`exception`](/documentation/JavaScriptCore/JSContext/exception)

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

[`exceptionHandler`](/documentation/JavaScriptCore/JSContext/exceptionHandler)

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

[`virtualMachine`](/documentation/JavaScriptCore/JSContext/virtualMachine)

The JavaScript virtual machine to which the context belongs.

[`name`](/documentation/JavaScriptCore/JSContext/name)

A descriptive name for the context.

### Accessing JavaScript global state with subscripts

[`objectForKeyedSubscript(_:)`](/documentation/JavaScriptCore/JSContext/objectForKeyedSubscript(_:))

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

[`setObject(_:forKeyedSubscript:)`](/documentation/JavaScriptCore/JSContext/setObject(_:forKeyedSubscript:))

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

### Working with the C JavaScriptCore API

[`jsGlobalContextRef`](/documentation/JavaScriptCore/JSContext/jsGlobalContextRef)

Returns the C representation of the JavaScript context.

[`init(JSGlobalContextRef:)`](/documentation/JavaScriptCore/JSContext/init(JSGlobalContextRef:)-9m51)

Creates a JavaScript context object from the equivalent C representation.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)