зеркало из https://github.com/mozilla/pjs.git
Report proper typeof for XPCNativeWrapper(obj) and XPCNativeWrapper(fun) (553407, r=mrbkap).
This commit is contained in:
Родитель
76154bd4b4
Коммит
2a3ead7d2b
|
@ -1474,7 +1474,7 @@ jsval nsDOMClassInfo::sJava_id = JSVAL_VOID;
|
|||
jsval nsDOMClassInfo::sPackages_id = JSVAL_VOID;
|
||||
|
||||
static const JSClass *sObjectClass = nsnull;
|
||||
const JSClass *nsDOMClassInfo::sXPCNativeWrapperClass = nsnull;
|
||||
JSPropertyOp nsDOMClassInfo::sXPCNativeWrapperGetPropertyOp = nsnull;
|
||||
|
||||
/**
|
||||
* Set our JSClass pointer for the Object class
|
||||
|
|
|
@ -174,17 +174,17 @@ public:
|
|||
/**
|
||||
* Get our JSClass pointer for the XPCNativeWrapper class
|
||||
*/
|
||||
static const JSClass* GetXPCNativeWrapperClass() {
|
||||
return sXPCNativeWrapperClass;
|
||||
static JSPropertyOp GetXPCNativeWrapperGetPropertyOp() {
|
||||
return sXPCNativeWrapperGetPropertyOp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set our JSClass pointer for the XPCNativeWrapper class
|
||||
*/
|
||||
static void SetXPCNativeWrapperClass(JSClass* aClass) {
|
||||
NS_ASSERTION(!sXPCNativeWrapperClass,
|
||||
"Double set of sXPCNativeWrapperClass");
|
||||
sXPCNativeWrapperClass = aClass;
|
||||
static void SetXPCNativeWrapperGetPropertyOp(JSPropertyOp getPropertyOp) {
|
||||
NS_ASSERTION(!sXPCNativeWrapperGetPropertyOp,
|
||||
"Double set of sXPCNativeWrapperGetPropertyOp");
|
||||
sXPCNativeWrapperGetPropertyOp = getPropertyOp;
|
||||
}
|
||||
|
||||
static PRBool ObjectIsNativeWrapper(JSContext* cx, JSObject* obj)
|
||||
|
@ -194,13 +194,13 @@ public:
|
|||
nsIScriptContext *scx = GetScriptContextFromJSContext(cx);
|
||||
|
||||
NS_PRECONDITION(!scx || !scx->IsContextInitialized() ||
|
||||
sXPCNativeWrapperClass,
|
||||
"Must know what the XPCNativeWrapper class is!");
|
||||
sXPCNativeWrapperGetPropertyOp,
|
||||
"Must know what the XPCNativeWrapper class GetProperty op is!");
|
||||
}
|
||||
#endif
|
||||
|
||||
return sXPCNativeWrapperClass &&
|
||||
::JS_GET_CLASS(cx, obj) == sXPCNativeWrapperClass;
|
||||
return sXPCNativeWrapperGetPropertyOp &&
|
||||
::JS_GET_CLASS(cx, obj)->getProperty == sXPCNativeWrapperGetPropertyOp;
|
||||
}
|
||||
|
||||
static void PreserveNodeWrapper(nsIXPConnectWrappedNative *aWrapper);
|
||||
|
@ -365,7 +365,7 @@ protected:
|
|||
static jsval sJava_id;
|
||||
static jsval sPackages_id;
|
||||
|
||||
static const JSClass *sXPCNativeWrapperClass;
|
||||
static JSPropertyOp sXPCNativeWrapperGetPropertyOp;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2586,8 +2586,10 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
|
|||
|
||||
// Now check whether we need to grab a pointer to the
|
||||
// XPCNativeWrapper class
|
||||
if (!nsDOMClassInfo::GetXPCNativeWrapperClass()) {
|
||||
nsDOMClassInfo::SetXPCNativeWrapperClass(xpc->GetNativeWrapperClass());
|
||||
if (!nsDOMClassInfo::GetXPCNativeWrapperGetPropertyOp()) {
|
||||
JSPropertyOp getProperty;
|
||||
xpc->GetNativeWrapperGetPropertyOp(&getProperty);
|
||||
nsDOMClassInfo::SetXPCNativeWrapperGetPropertyOp(getProperty);
|
||||
}
|
||||
} else {
|
||||
// There's already a global object. We are preparing this outer window
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
[ptr] native JSClassPtr(JSClass);
|
||||
[ptr] native JSObjectPtr(JSObject);
|
||||
[ptr] native JSValPtr(jsval);
|
||||
native JSPropertyOp(JSPropertyOp);
|
||||
native JSEqualityOp(JSEqualityOp);
|
||||
native JSID(jsid);
|
||||
[ptr] native voidPtrPtr(void*);
|
||||
|
@ -396,7 +397,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
|
|||
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
%}
|
||||
|
||||
[uuid(96540596-c21e-4183-bb47-f6a5c1ad2dba)]
|
||||
[uuid(0332b12a-8103-4601-aed3-b9933a0d9441)]
|
||||
interface nsIXPConnect : nsISupports
|
||||
{
|
||||
%{ C++
|
||||
|
@ -868,5 +869,5 @@ interface nsIXPConnect : nsISupports
|
|||
#endif
|
||||
%}
|
||||
|
||||
[notxpcom] JSClassPtr getNativeWrapperClass();
|
||||
[notxpcom] void getNativeWrapperGetPropertyOp(out JSPropertyOp getProperty);
|
||||
};
|
||||
|
|
|
@ -112,7 +112,33 @@ namespace XPCNativeWrapper { namespace internal {
|
|||
// JS class for XPCNativeWrapper (and this doubles as the constructor
|
||||
// for XPCNativeWrapper for the moment too...)
|
||||
|
||||
JSExtendedClass NWClass = {
|
||||
JSExtendedClass NW_NoCall_Class = {
|
||||
// JSClass (JSExtendedClass.base) initialization
|
||||
{ "XPCNativeWrapper",
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS |
|
||||
// Our one reserved slot holds a jsint of flag bits
|
||||
JSCLASS_NEW_RESOLVE | JSCLASS_HAS_RESERVED_SLOTS(1) |
|
||||
JSCLASS_MARK_IS_TRACE | JSCLASS_IS_EXTENDED | JSCLASS_CONSTRUCT_PROTOTYPE,
|
||||
XPC_NW_AddProperty, XPC_NW_DelProperty,
|
||||
XPC_NW_GetProperty, XPC_NW_SetProperty,
|
||||
XPC_NW_Enumerate, (JSResolveOp)XPC_NW_NewResolve,
|
||||
XPC_NW_Convert, XPC_NW_Finalize,
|
||||
nsnull, XPC_NW_CheckAccess,
|
||||
nsnull, XPC_NW_Construct,
|
||||
nsnull, XPC_NW_HasInstance,
|
||||
JS_CLASS_TRACE(XPC_NW_Trace), nsnull
|
||||
},
|
||||
|
||||
// JSExtendedClass initialization
|
||||
XPC_NW_Equality,
|
||||
nsnull, // outerObject
|
||||
nsnull, // innerObject
|
||||
XPC_NW_Iterator,
|
||||
nsnull, // wrappedObject
|
||||
JSCLASS_NO_RESERVED_MEMBERS
|
||||
};
|
||||
|
||||
JSExtendedClass NW_Call_Class = {
|
||||
// JSClass (JSExtendedClass.base) initialization
|
||||
{ "XPCNativeWrapper",
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS |
|
||||
|
@ -1112,7 +1138,7 @@ XPC_NW_Iterator(JSContext *cx, JSObject *obj, JSBool keysonly)
|
|||
}
|
||||
|
||||
JSObject *wrapperIter =
|
||||
JS_NewObjectWithGivenProto(cx, XPCNativeWrapper::GetJSClass(), nsnull,
|
||||
JS_NewObjectWithGivenProto(cx, XPCNativeWrapper::GetJSClass(false), nsnull,
|
||||
obj->getParent());
|
||||
if (!wrapperIter) {
|
||||
return nsnull;
|
||||
|
@ -1208,7 +1234,7 @@ XPCNativeWrapper::AttachNewConstructorObject(XPCCallContext &ccx,
|
|||
JSObject *aGlobalObject)
|
||||
{
|
||||
JSObject *class_obj =
|
||||
::JS_InitClass(ccx, aGlobalObject, nsnull, &internal::NWClass.base,
|
||||
::JS_InitClass(ccx, aGlobalObject, nsnull, &internal::NW_Call_Class.base,
|
||||
XPCNativeWrapperCtor, 0, nsnull, nsnull,
|
||||
nsnull, static_functions);
|
||||
if (!class_obj) {
|
||||
|
@ -1226,7 +1252,7 @@ XPCNativeWrapper::AttachNewConstructorObject(XPCCallContext &ccx,
|
|||
|
||||
JSBool found;
|
||||
return ::JS_SetPropertyAttributes(ccx, aGlobalObject,
|
||||
internal::NWClass.base.name,
|
||||
internal::NW_Call_Class.base.name,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT,
|
||||
&found);
|
||||
}
|
||||
|
@ -1295,7 +1321,9 @@ XPCNativeWrapper::GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper,
|
|||
::JS_LockGCThing(cx, nw_parent);
|
||||
}
|
||||
|
||||
obj = ::JS_NewObjectWithGivenProto(cx, GetJSClass(), nsnull, nw_parent);
|
||||
bool call = NATIVE_HAS_FLAG(wrapper, WantCall) ||
|
||||
NATIVE_HAS_FLAG(wrapper, WantConstruct);
|
||||
obj = ::JS_NewObjectWithGivenProto(cx, GetJSClass(call), nsnull, nw_parent);
|
||||
|
||||
if (lock) {
|
||||
::JS_UnlockGCThing(cx, nw_parent);
|
||||
|
@ -1338,8 +1366,10 @@ XPCNativeWrapper::CreateExplicitWrapper(JSContext *cx,
|
|||
printf("Creating new JSObject\n");
|
||||
#endif
|
||||
|
||||
bool call = NATIVE_HAS_FLAG(wrappedNative, WantCall) ||
|
||||
NATIVE_HAS_FLAG(wrappedNative, WantConstruct);
|
||||
JSObject *wrapperObj =
|
||||
JS_NewObjectWithGivenProto(cx, XPCNativeWrapper::GetJSClass(), nsnull,
|
||||
JS_NewObjectWithGivenProto(cx, XPCNativeWrapper::GetJSClass(call), nsnull,
|
||||
wrappedNative->GetScope()->GetGlobalJSObject());
|
||||
|
||||
if (!wrapperObj) {
|
||||
|
|
|
@ -44,7 +44,10 @@ class nsIPrincipal;
|
|||
|
||||
namespace XPCNativeWrapper {
|
||||
|
||||
namespace internal { extern JSExtendedClass NWClass; }
|
||||
namespace internal {
|
||||
extern JSExtendedClass NW_NoCall_Class;
|
||||
extern JSExtendedClass NW_Call_Class;
|
||||
}
|
||||
|
||||
PRBool
|
||||
AttachNewConstructorObject(XPCCallContext &ccx, JSObject *aGlobalObject);
|
||||
|
@ -59,13 +62,14 @@ CreateExplicitWrapper(JSContext *cx, XPCWrappedNative *wrapper, JSBool deep,
|
|||
inline PRBool
|
||||
IsNativeWrapperClass(JSClass *clazz)
|
||||
{
|
||||
return clazz == &internal::NWClass.base;
|
||||
return clazz == &internal::NW_NoCall_Class.base ||
|
||||
clazz == &internal::NW_Call_Class.base;
|
||||
}
|
||||
|
||||
inline PRBool
|
||||
IsNativeWrapper(JSObject *obj)
|
||||
{
|
||||
return STOBJ_GET_CLASS(obj) == &internal::NWClass.base;
|
||||
return IsNativeWrapperClass(obj->getClass());
|
||||
}
|
||||
|
||||
JSBool
|
||||
|
@ -80,9 +84,11 @@ SafeGetWrappedNative(JSObject *obj)
|
|||
}
|
||||
|
||||
inline JSClass *
|
||||
GetJSClass()
|
||||
GetJSClass(bool call)
|
||||
{
|
||||
return &internal::NWClass.base;
|
||||
return call
|
||||
? &internal::NW_Call_Class.base
|
||||
: &internal::NW_NoCall_Class.base;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -2796,10 +2796,14 @@ nsXPConnect::GetPrincipal(JSObject* obj, PRBool allowShortCircuit) const
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(JSClass *)
|
||||
nsXPConnect::GetNativeWrapperClass()
|
||||
NS_IMETHODIMP_(void)
|
||||
nsXPConnect::GetNativeWrapperGetPropertyOp(JSPropertyOp *getPropertyPtr)
|
||||
{
|
||||
return XPCNativeWrapper::GetJSClass();
|
||||
NS_ASSERTION(XPCNativeWrapper::GetJSClass(true)->getProperty ==
|
||||
XPCNativeWrapper::GetJSClass(false)->getProperty,
|
||||
"Call and NoCall XPCNativeWrapper Class must use the same "
|
||||
"getProperty hook.");
|
||||
*getPropertyPtr = XPCNativeWrapper::GetJSClass(true)->getProperty;
|
||||
}
|
||||
|
||||
/* These are here to be callable from a debugger */
|
||||
|
|
|
@ -68,6 +68,7 @@ _TEST_FILES = bug500931_helper.html \
|
|||
test_bug504877.html \
|
||||
test_bug505915.html \
|
||||
test_bug517163.html \
|
||||
test_bug553407.html \
|
||||
test_cows.html \
|
||||
test_frameWrapping.html \
|
||||
$(NULL)
|
||||
|
|
Загрузка…
Ссылка в новой задаче