JSContext
IntroductionAn instance of JSContext represents a JavaScript execution environment. All JavaScript execution takes place within a context. JSContext is also used to manage the life-cycle of objects within the JavaScript virtual machine. Every instance of JSValue is associated with a JSContext via a strong reference. The JSValue will keep the JSContext it references alive so long as the JSValue remains alive. When all of the JSValues that reference a particular JSContext have been deallocated the JSContext will be deallocated unless it has been previously retained. GroupsCreating New JSContextsGroup members:
Callback AccessorsGroup members:
Evaluating ScriptsGroup members:
Global PropertiesMethods
currentArgumentsGet the arguments to the current callback. + (NSArray *)currentArguments; Return ValueAn NSArray of the arguments nil if there is no current callback. DiscussionThis method may be called from within an Objective-C block or method invoked as a callback from JavaScript to retrieve the callback's arguments, objects in the returned array are instances of JSValue. Outside of a callback from JavaScript this method will return nil. currentCalleeGet the JavaScript function that is currently executing. + (JSValue *)currentCallee ; Return ValueThe currently executing JavaScript function or nil if there isn't one. DiscussionThis method may be called from within an Objective-C block or method invoked as a callback from JavaScript to retrieve the callback's context. Outside of a callback from JavaScript this method will return nil.
currentContextGet the JSContext that is currently executing. + (JSContext *)currentContext; Return ValueThe currently executing JSContext or nil if there isn't one. DiscussionThis method may be called from within an Objective-C block or method invoked as a callback from JavaScript to retrieve the callback's context. Outside of a callback from JavaScript this method will return nil. currentThisGet the + (JSValue *)currentThis; Return ValueThe current DiscussionThis method may be called from within an Objective-C block or method invoked as a callback from JavaScript to retrieve the callback's this value. Outside of a callback from JavaScript this method will return nil. evaluateScript:Evaluate a string of JavaScript code. - (JSValue *)evaluateScript:(NSString *)script; ParametersReturn ValueThe last value generated by the script. evaluateScript:withSourceURL:Evaluate a string of JavaScript code, with a URL for the script's source file. - (JSValue *)evaluateScript:(NSString *)script withSourceURL:(NSURL *)sourceURL ; ParametersReturn ValueThe last value generated by the script.
initCreate a JSContext. - (instancetype)init; Return ValueThe new context. initWithVirtualMachine:Create a JSContext in the specified virtual machine. - (instancetype)initWithVirtualMachine:(JSVirtualMachine *)virtualMachine; ParametersReturn ValueThe new context. Properties
exception@property (strong) JSValue *exception; DiscussionThe Before a callback is made from JavaScript to an Objective-C block or method, the prior value of the exception property will be preserved and the property will be set to nil. After the callback has completed the new value of the exception property will be read, and prior value restored. If the new value of exception is not nil, the callback will result in that value being thrown. This property may also be used to check for uncaught exceptions arising from
API function calls (since the default behaviour of If a JSValue originating from a different JSVirtualMachine than this context is assigned to this property, an Objective-C exception will be raised. exceptionHandler@property (copy) void(^exceptionHandler)(JSContext *context, JSValue *exception); DiscussionIf a call to an API function results in an uncaught JavaScript exception, the
globalObjectGet the global object of the context. @property (readonly, strong) JSValue *globalObject; Return ValueThe global object. DiscussionThis method retrieves the global object of the JavaScript execution context. Instances of JSContext originating from WebKit will return a reference to the WindowProxy object. name@property (copy) NSString *name ; DiscussionName of the JSContext. Exposed when remote debugging the context.
virtualMachine@property (readonly, strong) JSVirtualMachine *virtualMachine; DiscussionAll instances of JSContext are associated with a single JSVirtualMachine. The virtual machine provides an "object space" or set of execution resources. |