Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Next Page > Hide TOC

WebScriptObject Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/WebKit.framework
Availability
Available in Mac OS X v10.3.9 and later.
Companion guide
Declared in
WebScriptObject.h

Overview

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

You can not create a WebScriptObject directly. You get a window WebScriptObject 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. 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 Web Kit’s JavaScript environment.

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

Tasks

Getting and Setting Properties

Executing Scripts

Raising Exceptions

Getting a String Representation

Class Methods

throwException:

Raises an exception in the current script execution context.

+ (BOOL)throwException:(NSString *)exceptionMessage

Discussion

Returns YES if successful, NO otherwise.

Availability
See Also
Declared In
WebScriptObject.h

Instance Methods

callWebScriptMethod:withArguments:

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

- (id)callWebScriptMethod:(NSString *)methodName withArguments:(NSArray *)args

Discussion

This method returns the result of invoking a method, specified by methodName, with the arguments, specified by args, in the scripting environment. Returns WebUndefined if an exception is thrown in the JavaScript environment or the method has no return value.

Availability
See Also
Declared In
WebScriptObject.h

evaluateWebScript:

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

- (id)evaluateWebScript:(NSString *)script

Discussion

The format of the script is dependent on the target scripting environment. Returns WebUndefined if an exception is thrown in the JavaScript environment or there is no return value.

Availability
See Also
Declared In
WebScriptObject.h

InstanceMethod

Returns the JavaScript object corresponding to the receiver.

- (JSObjectRef)JSObject

Return Value

The JavaScript object corresponding to the receiver in the JavaScriptCore C API.

Availability

removeWebScriptKey:

Removes a property from a scripting environment.

- (void)removeWebScriptKey:(NSString *)key

Discussion

This method removes a property, specified by key, from the receiver in the scripting environment.

Availability
See Also
Declared In
WebScriptObject.h

setException:

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

- (void)setException:(NSString *)exceptionMessage

Availability
See Also
Declared In
WebScriptObject.h

setWebScriptValueAtIndex:value:

Sets the value of a property (by index).

- (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value

Discussion

This method sets the property value at the index specified by index to value.

Availability
See Also
Declared In
WebScriptObject.h

stringRepresentation

Returns a string representation of the receiver.

- (NSString *)stringRepresentation

Discussion

The coercion of non-string objects is dependent on the scripting environment.

Availability
Declared In
WebScriptObject.h

webScriptValueAtIndex:

Returns the index value of a property (specified by index).

- (id)webScriptValueAtIndex:(unsigned)index

Discussion

This method returns the value of the property at the index specified by index. Accessing property values by index is dependent on the scripting environment. Returns WebUndefined if an exception is thrown in the JavaScript environment.

Availability
See Also
Declared In
WebScriptObject.h

Next Page > Hide TOC


Last updated: 2008-06-19




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice