JSNewResolveOp 编辑

Obsolete since JSAPI 36
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.

JSNewResolveOp is the type of the JSClass.resolve callback when the JSCLASS_NEW_RESOLVE bit is set in the JSClass.flags field.

Syntax

typedef bool
(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
                   JS::MutableHandleObject objp);
NameTypeDescription
cxJSContext *Pointer to the JS context in which the property access is taking place.
objJS::HandleObjectPointer to the object whose properties are being accessed.
idJS::HandleIdName or index of the property being accessed.
flagsuint32_tObsolete since JSAPI 31 Flags giving contextual information about the ongoing property access.
objpJS::MutableHandleObjectOut parameter. On success, the resolve hook must set *objp to the object in which the property has been defined, or NULL if it was not defined.

Description

Like JSResolveOp, but flags provide contextual information about the property access.

On success, the callback must set the *objp out parameter to null if id was not resolved; or non-null, referring to obj or one of its prototypes, if id was resolved; and return JS_TRUE. On failure, it must return JS_FALSE.

This hook instead of JSResolveOp is called via the JSClass.resolve member if JSCLASS_NEW_RESOLVE is set in JSClass.flags.

Setting JSCLASS_NEW_RESOLVE and JSCLASS_NEW_RESOLVE_GETS_START further extends this hook by passing in the starting object on the prototype chain via *objp. Thus a resolve hook implementation may define the property id being resolved in the object in which the id was first sought, rather than in a prototype object whose class led to the resolve hook being called.

When using JSCLASS_NEW_RESOLVE_GETS_START, the resolve hook must therefore null *objp to signify "not resolved". With only JSCLASS_NEW_RESOLVE and no JSCLASS_NEW_RESOLVE_GETS_START, the hook can assume *objp is null on entry. This is not good practice, but enough existing hook implementations count on it that we can't break compatibility by passing the starting object in *objp without a new JSClass flag.

Flags

The flags argument is the logical OR of zero or more of the following flags. The flags describe what kind of property access triggered the resolve callback. (The same flags are used in JS_LookupPropertyWithFlags.)

JSRESOLVE_QUALIFIEDObsolete since JSAPI 20
The property access uses the . or [] operator: obj.id or obj[id], not id.
JSRESOLVE_ASSIGNING Obsolete since JSAPI 31
The property appears on the left-hand side of an assignment.
JSRESOLVE_DETECTINGObsolete since JSAPI 20
The property is being used in code like "if (o.p)...", or a similar idiom where the apparent purpose of the property access is to detect whether the property exists.  (This flag has been replaced with the JSCLASS_EMULATES_UNDEFINED mechanism.)
JSRESOLVE_DECLARING Obsolete since JSAPI 15
The property is being declared in a var, const, or function declaration.
JSRESOLVE_CLASSNAME Obsolete since JavaScript 1.8.8
class name used when constructing.
JSRESOLVE_WITH Obsolete since JavaScript 1.8.8
The lookup is occurring for a name evaluated inside a with statement.

See Also

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

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

发布评论

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

词条统计

浏览:67 次

字数:7994

最后编辑:7年前

编辑次数:0 次

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