This article covers features introduced in SpiderMonkey 1.8

Determine whether a property is already physically present on a JSObject.


JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name,
                         bool *foundp);

JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name,
                           size_t namelen, bool *foundp);

JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
                             bool *foundp); // Added in SpiderMonkey 1.8.1

JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
                        bool *foundp);
Name Type Description
cx JSContext * Pointer to a JS context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object to be searched.
name or id const char * or const char16_t *or JS::HandleId (in JS_AlreadyHasOwnProperty, AlreadyHasOwnUCProperty, and JS_AlreadyHasOwnPropertyById) The name of the property to search for.
namelen size_t (in JS_AlreadyHasOwnUCProperty only) The length of name, in characters; or the special value (size_t) -1 to indicate that name is null-terminated.
index uint32_t (in JS_AlreadyHasOwnElement only) The index of the element to search for.
foundp bool * Out parameter. *foundp receives true if the property is found or false if it is not found. If an error occurs, the value left in *foundp is undefined.


These functions attempt to determine whether a property already exists on a specific JSObject without modifying the object. By design, this search may not find a property that other property lookup functions, such as JS_LookupProperty, would find.

For native objects—objects whose properties are stored in the default data structure provided by SpiderMonkey—these functions simply check that data structure to see if the specified field is present. They do not search anywhere else for the property. This means that:

For non-native objects, this falls back on a complete search. This calls the JSObjectOps.lookupProperty hook. *foundp is set to true only if lookupProperty reports that the property was found on obj itself and not on some other object (even the corresponding outer object, if any).

If the property is found on obj, this sets *foundp to true and returns true.

If the property is not found on obj, this sets *foundp to false and returns true (to indicate that no error occurred).

If the search fails with an error or exception, this returns false.

See Also