Mac Developer Library

Developer

JSBase.h Reference

Options
Deployment Target:

On This Page
Language:

JSBase.h Reference

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import JavaScriptCore

Objective-C

@import JavaScriptCore;

Included Headers

  • <stdbool.h>

  • <Foundation/Foundation.h>

Functions

  • Checks for syntax errors in a string of JavaScript.

    Declaration

    Swift

    func JSCheckScriptSyntax(_ ctx: JSContextRef, _ script: JSStringRef, _ sourceURL: JSStringRef, _ startingLineNumber: Int32, _ exception: UnsafeMutablePointer<JSValueRef>) -> Bool

    Objective-C

    bool JSCheckScriptSyntax ( JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef *exception );

    Parameters

    ctx

    The execution context to use.

    script

    A JSString containing the script to check for syntax errors.

    sourceURL

    A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL 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.

    exception

    A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.

    Return Value

    true if the script is syntactically correct, otherwise false.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Evaluates a string of JavaScript.

    Declaration

    Swift

    func JSEvaluateScript(_ ctx: JSContextRef, _ script: JSStringRef, _ thisObject: JSObjectRef, _ sourceURL: JSStringRef, _ startingLineNumber: Int32, _ exception: UnsafeMutablePointer<JSValueRef>) -> JSValueRef

    Objective-C

    JSValueRef JSEvaluateScript ( JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef *exception );

    Parameters

    ctx

    The execution context to use.

    script

    A JSString containing the script to evaluate.

    thisObject

    The object to use as "this," or NULL to use the global object as "this."

    sourceURL

    A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL 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.

    exception

    A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.

    Return Value

    The JSValue that results from evaluating script, or NULL if an exception is thrown.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Performs a JavaScript garbage collection.

    Declaration

    Swift

    func JSGarbageCollect(_ ctx: JSContextRef)

    Objective-C

    void JSGarbageCollect ( JSContextRef ctx );

    Parameters

    ctx

    The execution context to use.

    Discussion

    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.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

Data Types

See the Overview section above for header-level documentation.

  • Declaration

    Swift

    typealias JSClassRef = COpaquePointer

    Objective-C

    typedef struct OpaqueJSClass* JSClassRef;

    Discussion

    A JavaScript class. Used with JSObjectMake to construct objects with custom behavior.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSContextGroupRef = COpaquePointer

    Objective-C

    typedef const struct OpaqueJSContextGroup* JSContextGroupRef;

    Discussion

    A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.6 and later.

  • Declaration

    Swift

    typealias JSContextRef = COpaquePointer

    Objective-C

    typedef const struct OpaqueJSContext* JSContextRef;

    Discussion

    A JavaScript execution context. Holds the global object and other execution state.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSGlobalContextRef = COpaquePointer

    Objective-C

    typedef struct OpaqueJSContext* JSGlobalContextRef;

    Discussion

    A global JavaScript execution context. A JSGlobalContext is a JSContext.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSObjectRef = COpaquePointer

    Objective-C

    typedef struct OpaqueJSValue* JSObjectRef;

    Discussion

    A JavaScript object. A JSObject is a JSValue.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSPropertyNameAccumulatorRef = COpaquePointer

    Objective-C

    typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;

    Discussion

    An ordered set used to collect the names of a JavaScript object's properties.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSPropertyNameArrayRef = COpaquePointer

    Objective-C

    typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef;

    Discussion

    An array of JavaScript property names.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSStringRef = COpaquePointer

    Objective-C

    typedef struct OpaqueJSString* JSStringRef;

    Discussion

    A UTF16 character buffer. The fundamental string representation in JavaScript.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Swift

    typealias JSValueRef = COpaquePointer

    Objective-C

    typedef const struct OpaqueJSValue* JSValueRef;

    Discussion

    A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them.

    Import Statement

    Objective-C

    @import JavaScriptCore;

    Swift

    import JavaScriptCore

    Availability

    Available in OS X v10.5 and later.