Obsolete since JSAPI 29
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Check whether a running script may access a given object property.

Syntax

JSBool JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id,
    JSAccessMode mode, jsval *vp, unsigned int *attrsp);
Name Type Description
cx JSContext * The context in which to perform the access check. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object that has the property being accessed.
id jsid The name or index of the property being accessed.
mode JSAccessMode The type of access requested (read, write, etc.)
vp jsval * Out parameter. On success, *vp receives the property's stored value.
attrsp unsigned int * Out parameter. On success, *attrsp receives the property attributes.

Description

JS_CheckAccess determines whether the property of obj given by id can be accessed by the code currently running in the context cx.

The mode parameter specifies what kind of access to check for. It is one of the following values:

Value Description
JSACC_PROTO Check for permission to read to obj's prototype. (This is redundant with passing the string id "__proto__" as id.)
JSACC_PARENT Check for permission to read obj's parent. (This is redundant with passing the string id "__parent__" as id.)
JSACC_IMPORT Check for permission to import the property.
JSACC_WATCH Check for permission to place a watchpoint on the property.
JSACC_READ Check for permission to get the property's value.
JSACC_WRITE When bitwise-ORed with one of the above values, check for permission to write the property, not read it.

The access check proceeds as follows. If obj has custom JSObjectOps, the access check is delegated to the JSObjectOps.checkAccess callback. Otherwise, if obj's class has a non-null JSClass.checkAccess callback, then it is called to perform the check. Otherwise, if a runtime-wide check-object-access callback has been installed by calling JS_SetCheckObjectAccessCallback, then that is called to perform the check. Otherwise, access is granted.

On success, JS_CheckAccess returns JS_TRUE, *vp is set to the current value of the specified property, and *attrsp is set to the property's attributes. On error or exception, including if access is denied, JS_CheckAccess returns JS_FALSE, and the values left in *vp and *attrsp are undefined.

MXR ID Search for JS_CheckAccess