Mac Developer Library

Developer

WebKit Framework Reference WebScriptObject Class Reference

Options
Deployment Target:

On This Page
Language:

WebScriptObject

A WebScriptObject object is an Objective-C wrapper for a scripting object passed to your application from the scripting environment.

You can not create a WebScriptObject object directly. You get a window WebScriptObject object by sending windowScriptObject to your WebView object.

You can use key-value coding methods—for example, setValue:forKey: and valueForKey:—to get and set properties of a WebScriptObject object. You can also access properties by index using the setWebScriptValueAtIndex:value: and webScriptValueAtIndex: methods. Use the removeWebScriptKey: method to remove a scripting object property.

Not all properties and methods of a class are exported. Use the setValue:forUndefinedKey: and valueForUndefinedKey: methods to intercept access to properties that are not exported. Similarly, use the invokeUndefinedMethodFromWebScript:withArguments: method to intercept method invocations that are not exported.

If you want access to properties and methods defined in your own classes, use the methods in the WebScripting informal protocol to specify the properties and methods the class should export to WebKit’s JavaScript environment.

Use the callWebScriptMethod:withArguments: and evaluateWebScript: methods to execute scripts in the scripting environment.

  • Raises an exception in the current script execution context.

    Declaration

    Swift

    class func throwException(_ exceptionMessage: String!) -> Bool

    Objective-C

    + (BOOL)throwException:(NSString *)exceptionMessage

    Parameters

    exceptionMessage

    The exception message.

    Return Value

    YEStrue if successful, NOfalse otherwise.

    Availability

    Available in OS X v10.3 and later.

  • Raises a scripting environment exception in the context of the current object.

    Declaration

    Swift

    func setException(_ description: String!)

    Objective-C

    - (void)setException:(NSString *)description

    Parameters

    description

    Description of the exception.

    Availability

    Available in OS X v10.3 and later.

  • Returns a string representation of the receiver.

    Declaration

    Swift

    func stringRepresentation() -> String!

    Objective-C

    - (NSString *)stringRepresentation

    Return Value

    The string representation of the receiver.

    Discussion

    The coercion of nonstring objects is dependent on the scripting environment.

    Availability

    Available in OS X v10.3 and later.