JS_CheckAccess 编辑

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);
NameTypeDescription
cxJSContext *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.
objJSObject *The object that has the property being accessed.
idjsidThe name or index of the property being accessed.
modeJSAccessModeThe type of access requested (read, write, etc.)
vpjsval *Out parameter. On success, *vp receives the property's stored value.
attrspunsigned 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:

ValueDescription
JSACC_PROTOCheck for permission to read to obj's prototype. (This is redundant with passing the string id "__proto__" as id.)
JSACC_PARENTCheck for permission to read obj's parent. (This is redundant with passing the string id "__parent__" as id.)
JSACC_IMPORTCheck for permission to import the property.
JSACC_WATCHCheck for permission to place a watchpoint on the property.
JSACC_READCheck for permission to get the property's value.
JSACC_WRITEWhen 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:125 次

字数:5838

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文