Class

WebScriptObject

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

Declaration

@interface WebScriptObject : NSObject

Overview

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.

Topics

Getting and setting properties

- JSObject

Returns the JavaScript object corresponding to the receiver.

- removeWebScriptKey:

Removes a property from a scripting environment.

- webScriptValueAtIndex:

Returns the value of a property at the specified index.

- setWebScriptValueAtIndex:value:

Sets the value of a property at the specified index.

Executing scripts

- callWebScriptMethod:withArguments:

Returns the result of executing a method in the scripting environment.

- evaluateWebScript:

Returns the result of evaluating a script in the scripting environment.

Raising exceptions

+ throwException:

Raises an exception in the current script execution context.

- setException:

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

Getting a string representation

- stringRepresentation

Returns a string representation of the receiver.

Instance Methods

Relationships

Inherits From

See Also

Incorporating Scripts (Legacy)

WebScripting

WebScripting is an informal protocol that defines methods that classes can implement to export their interfaces to a WebScript environment such as JavaScript.

WebUndefined

WebUndefined objects are simply used to represent the JavaScript “undefined” value in methods when bridging between JavaScript and Objective-C. For example, if you invoke a JavaScript function that returns the JavaScript “undefined” value, then a WebUndefined object is returned to the Objective-C calling context.

Deprecated