Find a specified property and retrieve its value.
bool JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); bool JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen, JS::MutableHandleValue vp); bool JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); // Added in SpiderMonkey 1.8.1
||A context. Requires request. In a
||Object to search on for the property.|
||Name of the property to look up.|
||Out parameter. On success,
JS_GetProperty examines a specified JS object
obj and its prototype chain for a property with the specified
JS_GetUCProperty is the Unicode version of the function.
JS_GetPropertyById is the same but takes a
JS::HandleId for the property name.
In the simplest case, JS_GetProperty stores the value of the property in *vp and returns
true. However, several different hooks can affect property gets. The full algorithm is described below.
First, a property lookup is performed. If the lookup proceeds without error, exactly one of the following cases applies:
- If the property is not found, then
*vpis set to
undefined. Then the
obj's class is called with the arguments
(cx, obj, id, vp). For many objects, including objects of standard classes such as
Array, this hook does nothing and returns
true, so the property get succeeds and
undefinedis left in
- If the property is found on a non-native object, get handler of
Proxy(only if the object is a Proxy) or its
JSObjectOps.getPropertymethod is called.
*vpis set to the property's stored value, or
undefinedif the property does not have a stored value, and then the property's getter is called with the arguments
(cx, obj, id, vp). For many properties, the getter does nothing and returns
true, so the property get succeeds and the property's stored value is left in
Internally, property retrieval, including all the behavior described above, is implemented by
On success, these functions set
*vp to the current value of the property, or
obj has no such property, and return
true. On an error or exception, these functions return
false, and the value left in
*vp is undefined.