nsIXPCScriptable 编辑

Note: This is not really an XPCOM interface. For example, callers must guarantee that they set the *_retval of the various methods that return a boolean to PR_TRUE before making the call. Implementations may skip writing to *_retval unless they want to return PR_FALSE. js/src/xpconnect/idl/nsIXPCScriptable.idlNot scriptable Please add a summary to this article.   Last changed in Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Inherits from: nsISupports

Method overview

void preCreate(in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj);
void create(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj);
void postCreate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj);
PRBool addProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp);
PRBool delProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp);
PRBool getProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp);
PRBool setProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp);
PRBool enumerate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj);
PRBool newEnumerate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp);
PRBool newResolve(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp);
PRBool convert(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp);
void finalize(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj);
PRBool checkAccess(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp);
PRBool call(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp);
PRBool construct(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp);
PRBool hasInstance(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp);
void trace(in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj);
PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val);
JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj);
JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj);
void postCreatePrototype(in JSContextPtr cx, in JSObjectPtr proto);

 

Attributes

AttributeTypeDescription
classNamestring 
scriptableFlagsPRUint32 The bitwise or'd set of flags (define below) that indicate the behavior of this object.

Constants

ConstantValueDescription
WANT_PRECREATE1 << 0 
WANT_CREATE1 << 1 
WANT_POSTCREATE1 << 2 
WANT_ADDPROPERTY1 << 3 
WANT_DELPROPERTY1 << 4 
WANT_GETPROPERTY1 << 5 
WANT_SETPROPERTY1 << 6 
WANT_ENUMERATE1 << 7 
WANT_NEWENUMERATE1 << 8 Indicates that the object wants to have its newEnumerate method called.
WANT_NEWRESOLVE1 << 9 Indicates that the object wants to have its newResolve method called.
WANT_CONVERT1 << 10 
WANT_FINALIZE1 << 11 
WANT_CHECKACCESS1 << 12 
WANT_CALL1 << 13 
WANT_CONSTRUCT1 << 14 
WANT_HASINSTANCE1 << 15 
WANT_TRACE1 << 16 
USE_JSSTUB_FOR_ADDPROPERTY1 << 17 
USE_JSSTUB_FOR_DELPROPERTY1 << 18 
USE_JSSTUB_FOR_SETPROPERTY1 << 19 
DONT_ENUM_STATIC_PROPS1 << 20 
DONT_ENUM_QUERY_INTERFACE1 << 21 
DONT_ASK_INSTANCE_FOR_SCRIPTABLE1 << 22 
CLASSINFO_INTERFACES_ONLY1 << 23 
ALLOW_PROP_MODS_DURING_RESOLVE1 << 24 
ALLOW_PROP_MODS_TO_PROTOTYPE1 << 25 
DONT_SHARE_PROTOTYPE1 << 26 
DONT_REFLECT_INTERFACE_NAMES1 << 27 
WANT_EQUALITY1 << 28 
WANT_OUTER_OBJECT1 << 29 
WANT_INNER_OBJECT1 << 30 
RESERVED1 << 31The high order bit is RESERVED for consumers of these flags. No implementor of this interface should ever return flags with this bit set.

 

Methods

preCreate()

 void preCreate(
   in nsISupports nativeObj,
   in JSContextPtr cx,
   in JSObjectPtr globalObj,
   out JSObjectPtr parentObj
 );
Parameters
nativeObj
cx
globalObj
parentObj

create()

 void create(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj
 );
Parameters
wrapper
cx
obj

postCreate()

 void postCreate(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj
 );
Parameters
wrapper
cx
obj

addProperty()

 PRBool addProperty(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal id,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
id
vp
Return value

 

delProperty()

 PRBool delProperty(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal id,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
id
vp
Return value

 

getProperty()

 PRBool getProperty(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal id,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
id
vp
Return value

NS_SUCCESS_I_DID_SOMETHING if this method does something.

 

setProperty()

 PRBool setProperty(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal id,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
id
vp
Return value

NS_SUCCESS_I_DID_SOMETHING if this method does something.

 

enumerate()

 PRBool enumerate(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj
 );
Parameters
wrapper
cx
obj
Return value

 

newEnumerate()

This method is called when the WANT_NEWENUMERATE flag is set.  It allows the object to implement the for..in enumeration in JavaScript.

This is very similar to JSClass.enumerate.
 PRBool newEnumerate(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in PRUint32 enum_op,
   in JSValPtr statep,
   out JSID idp
 );
Parameters
wrapper
cx
The pointer to the JSContext newEnumerate is being called from.
obj
The pointer to the JSObject being enumerated.
enum_op
Indicates what statep and idp represent, as well as indicates how the function should behave.  This will always be one of three values:

JSENUMERATE_INIT

A new, opaque iterator state should be allocated and stored in statep.  You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored.  If idp is non-null, and provided the number of enumerable properties is known, the number of properties that will be enumerated should be returned as an integer jsval in idp.If idp is non-null and the number of enumerable properties cannot be computed in advance, idp should be set toJSVAL_ZERO.

Your function might be passed a null pointer for idp.

JSENUMERATE_NEXT

A previously allocated opaque iterator state is passed in via statep. Return the next jsid in the iteration using idp. The opaque iterator state pointed at by statep is destroyed and *statep is set to JSVAL_NULL if there are no properties left to enumerate.

JSENUMERATE_DESTROY

This function should destroy the opaque iterator state previously allocated in statep by this function when enum_op was JSENUMERATE_INIT.

statep
An in/out pointer to a jsval whose meaning depends on the value of enum_op.
idp
An in/out pointer to a jsid whose meaning depends on the value of enum_op.

Return value

 This should (although does not need to) return PR_TRUE to indicate success or must return PR_FALSE to indicate failure.

newResolve()

This method is called when the WANT_NEWRESOLVE flag is set.  When this method is called, XPConnect is attempting to resolve a lazy property named by id on obj.  The JS engine will check if the property named by id is defined after this method has been called.

This is very similar to JSNewResolveOp. If an implementation of this method throws an error code, the prototype chain will not be checked for the property.
 PRBool newResolve(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal id,
   in PRUint32 flags,
   out JSObjectPtr objp
 );
Parameters
wrapper
cx
The pointer to the JSContext newResolve is being called from.
obj
The pointer to the JSObject that the property named by id that is being accessed.
id
The name or index of the property being accessed as a jsval.
flags
The flags that describe the access to the property named by id.  See JS_LookupProperty for the flags and their meaning.
objp
An out parameter that, on success, points to the JSObject that the property named by id has been defined on.  If the property named by id was not defined, this should be set to NULL.
Return value

 This should (although does not need to) return PR_TRUE to indicate success or must return PR_FALSE to indicate failure.

convert()

 PRBool convert(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in PRUint32 type,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
type
vp
Return value

 

finalize()

 void finalize(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj
 );
Parameters
wrapper
cx
obj

checkAccess()

 PRBool checkAccess(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal id,
   in PRUint32 mode,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
id
mode
vp
Return value

 

call()

 PRBool call(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in PRUint32 argc,
   in JSValPtr argv,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
argc
argv
vp
Return value

 

construct()

 PRBool construct(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in PRUint32 argc,
   in JSValPtr argv,
   in JSValPtr vp
 );
Parameters
wrapper
cx
obj
argc
argv
vp
Return value

 

hasInstance()

 PRBool hasInstance(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal val,
   out PRBool bp
 );
Parameters
wrapper
cx
obj
val
bp
Return value

 

trace()

 void trace(
   in nsIXPConnectWrappedNative wrapper,
   in JSTracerPtr trc,
   in JSObjectPtr obj
 );
Parameters
wrapper
trc
obj

equality()

 PRBool equality(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj,
   in JSVal val
 );
Parameters
wrapper
cx
obj
val
Return value

 

outerObject()

 JSObjectPtr outerObject(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj
 );
Parameters
wrapper
cx
obj
Return value

 

innerObject()

 JSObjectPtr innerObject(
   in nsIXPConnectWrappedNative wrapper,
   in JSContextPtr cx,
   in JSObjectPtr obj
 );
Parameters
wrapper
cx
obj
Return value

 

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

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

发布评论

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

词条统计

浏览:43 次

字数:31590

最后编辑:7年前

编辑次数:0 次

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