Class JSContext

  • All Implemented Interfaces:
    NSObject

    public class JSContext
    extends NSObject
    [@interface] A JSContext is a JavaScript execution environment. All JavaScript execution takes place within a context, and all JavaScript values are tied to a context.
    • Constructor Detail

      • JSContext

        protected JSContext​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • contextWithJSGlobalContextRef

        public static JSContext contextWithJSGlobalContextRef​(JSGlobalContextRef jsGlobalContextRef)
        Create a JSContext, wrapping its C API counterpart.
        Returns:
        The JSContext equivalent of the provided JSGlobalContextRef.
      • currentArguments

        public static NSArray<?> currentArguments()
        Get the arguments to the current callback. This 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.
        Returns:
        An NSArray of the arguments nil if there is no current callback.
      • currentCallee

        public static JSValue currentCallee()
        Get the JavaScript function that is currently executing. This 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.
        Returns:
        The currently executing JavaScript function or nil if there isn't one.
      • currentContext

        public static JSContext currentContext()
        [@methodgroup] Callback Accessors Get the JSContext that is currently executing. This 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.
        Returns:
        The currently executing JSContext or nil if there isn't one.
      • currentThis

        public static JSValue currentThis()
        Get the this value of the currently executing method. This 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.
        Returns:
        The current this value or nil if there isn't one.
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • JSGlobalContextRef

        public JSGlobalContextRef JSGlobalContextRef()
        [@property] Get the C API counterpart wrapped by a JSContext.
        Returns:
        The C API equivalent of this JSContext.
      • evaluateScript

        public JSValue evaluateScript​(java.lang.String script)
        [@methodgroup] Evaluating Scripts Evaluate a string of JavaScript code.
        Parameters:
        script - A string containing the JavaScript code to evaluate.
        Returns:
        The last value generated by the script.
      • evaluateScriptWithSourceURL

        public JSValue evaluateScriptWithSourceURL​(java.lang.String script,
                                                   NSURL sourceURL)
        Evaluate a string of JavaScript code, with a URL for the script's source file.
        Parameters:
        script - A string containing the JavaScript code to evaluate.
        sourceURL - A URL for the script's source file. Used by debuggers and when reporting exceptions. This parameter is informative only: it does not change the behavior of the script.
        Returns:
        The last value generated by the script.
      • exception

        public JSValue exception()
        [@property] The exception property may be used to throw an exception to JavaScript. 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 exceptionHandler is to assign an uncaught exception to this property).
      • exceptionHandler

        public JSContext.Block_exceptionHandler_ret exceptionHandler()
        [@property] If a call to an API function results in an uncaught JavaScript exception, the exceptionHandler block will be invoked. The default implementation for the exception handler will store the exception to the exception property on context. As a consequence the default behaviour is for uncaught exceptions occurring within a callback from JavaScript to be rethrown upon return. Setting this value to nil will cause all exceptions occurring within a callback from JavaScript to be silently caught.
      • globalObject

        public JSValue globalObject()
        [@property] Get the global object of the context. This method retrieves the global object of the JavaScript execution context. Instances of JSContext originating from WebKit will return a reference to the WindowProxy object.
        Returns:
        The global object.
      • init

        public JSContext init()
        [@methodgroup] Creating New JSContexts Create a JSContext.
        Overrides:
        init in class NSObject
        Returns:
        The new context.
      • initWithVirtualMachine

        public JSContext initWithVirtualMachine​(JSVirtualMachine virtualMachine)
        Create a JSContext in the specified virtual machine.
        Parameters:
        virtualMachine - The JSVirtualMachine in which the context will be created.
        Returns:
        The new context.
      • name

        public java.lang.String name()
        [@property] Name of the JSContext. Exposed when remote debugging the context.
      • objectForKeyedSubscript

        public JSValue objectForKeyedSubscript​(java.lang.Object key)
        Get a particular property on the global object.
        Returns:
        The JSValue for the global object's property.
      • setException

        public void setException​(JSValue value)
        [@property] The exception property may be used to throw an exception to JavaScript. 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 exceptionHandler is to assign an uncaught exception to this property).
      • setExceptionHandler

        public void setExceptionHandler​(JSContext.Block_setExceptionHandler value)
        [@property] If a call to an API function results in an uncaught JavaScript exception, the exceptionHandler block will be invoked. The default implementation for the exception handler will store the exception to the exception property on context. As a consequence the default behaviour is for uncaught exceptions occurring within a callback from JavaScript to be rethrown upon return. Setting this value to nil will cause all exceptions occurring within a callback from JavaScript to be silently caught.
      • setName

        public void setName​(java.lang.String value)
        [@property] Name of the JSContext. Exposed when remote debugging the context.
      • setObjectForKeyedSubscript

        public void setObjectForKeyedSubscript​(java.lang.Object object,
                                               NSObject key)
        Set a particular property on the global object.
      • virtualMachine

        public JSVirtualMachine virtualMachine()
        [@property] All instances of JSContext are associated with a JSVirtualMachine.