Visit Mozilla.org

JS GetProperty

From MDC

Finds a specified property and retrieves its value.

[edit] Syntax

JSBool JS_GetProperty(JSContext *cx, JSObject *obj,
    const char *name, jsval *vp);

JSBool JS_GetUCProperty(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen, jsval *vp);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information.

Requires request. (In a JS_THREADSAFE build, the caller must be in a request on this JSContext.)

obj JSObject * Object to search on for the property.
name const char * or const jschar * Name of the property to look up.
namelen size_t (in JS_GetUCProperty only) The length of name, in characters; or -1 to indicate that name is null-terminated.
vp jsval * Out parameter. On success, *vp receives the current value of the property.

[edit] Description

JS_GetProperty examines a specified JS object obj and its prototype chain for a property with the specified name. JS_GetUCProperty is the Unicode version of the function.

If the property is found, JS_GetProperty sets *vp to the current value of the property and returns JS_TRUE.

If the object obj has no such property, *vp is set to JSVAL_VOID and JS_GetProperty returns JS_TRUE (to indicate that no error occurred).

If the search fails with an error or exception, JS_GetProperty returns JS_FALSE, and the value left in *vp is undefined.

[edit] See Also

LXR ID Search for JS_GetProperty
LXR ID Search for JS_GetUCProperty

Example in the JSAPI Phrasebook

JS_DefineProperty, JS_DefinePropertyWithTinyId, JS_DeleteProperty, JS_DeleteProperty2, JS_LookupProperty, JS_PropertyStub, JS_SetProperty