mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 1329846
(part 1) - Remove XPCNativeScriptableInfo. r=mccr8.
XPCNativeScriptableInfo is now a very thin wrapper around nsIXPCScriptable, and it uses manual memory management. Removing it simplifies things quite a bit. In particular, when setting XPCWrappedNative::mScriptable in XPCWrappedNative::WrapNewGlobal() and XPCWrappedNative::Init() we no longer have to worry about sharing the XPCNativeScriptableInfo object with the proto. And XPCWrappedNative::{Init,Destroy}() have similar simplifications. --HG-- extra : rebase_source : e58eb28f1574224a8e8badf25fcfa25e5a5b8ad8
This commit is contained in:
parent
3651b67998
commit
e3685c4266
@ -793,6 +793,13 @@ nsDOMClassInfo::GetClass()
|
||||
return &mData->mClass;
|
||||
}
|
||||
|
||||
// virtual
|
||||
const JSClass*
|
||||
nsDOMClassInfo::GetJSClass()
|
||||
{
|
||||
return Jsvalify(&mData->mClass);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMClassInfo::PreCreate(nsISupports *nativeObj, JSContext *cx,
|
||||
JSObject *globalObj, JSObject **parentObj)
|
||||
|
@ -29,6 +29,7 @@ interface nsIXPConnectWrappedNative;
|
||||
[ref] native JSCallArgsRef(const JS::CallArgs);
|
||||
[ref] native JSAutoIdVector(JS::AutoIdVector);
|
||||
[ptr] native jsClassPtr(const js::Class);
|
||||
[ptr] native JSClassPtr(const JSClass);
|
||||
|
||||
/**
|
||||
* Note: This is not really an XPCOM interface. For example, callers must
|
||||
@ -65,6 +66,7 @@ interface nsIXPCScriptable : nsISupports
|
||||
readonly attribute string className;
|
||||
[notxpcom,nostdcall] uint32_t getScriptableFlags();
|
||||
[notxpcom,nostdcall] jsClassPtr getClass();
|
||||
[notxpcom,nostdcall] JSClassPtr getJSClass();
|
||||
|
||||
void preCreate(in nsISupports nativeObj, in JSContextPtr cx,
|
||||
in JSObjectPtr globalObj, out JSObjectPtr parentObj);
|
||||
|
@ -85,6 +85,13 @@ XPC_MAP_CLASSNAME::GetClass()
|
||||
return &klass;
|
||||
}
|
||||
|
||||
// virtual
|
||||
const JSClass*
|
||||
XPC_MAP_CLASSNAME::GetJSClass()
|
||||
{
|
||||
return Jsvalify(GetClass());
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
#ifndef XPC_MAP_WANT_PRECREATE
|
||||
|
@ -70,11 +70,8 @@ XPCCallContext::XPCCallContext(JSContext* cx,
|
||||
&js::GetReservedSlot(unwrapped,
|
||||
XPC_WN_TEAROFF_FLAT_OBJECT_SLOT).toObject());
|
||||
}
|
||||
if (mWrapper) {
|
||||
if (mTearOff)
|
||||
mScriptableInfo = nullptr;
|
||||
else
|
||||
mScriptableInfo = mWrapper->GetScriptableInfo();
|
||||
if (mWrapper && !mTearOff) {
|
||||
mScriptable = mWrapper->GetScriptable();
|
||||
}
|
||||
|
||||
if (!JSID_IS_VOID(name))
|
||||
|
@ -28,7 +28,6 @@ class XPCNativeSet;
|
||||
class XPCWrappedNative;
|
||||
class XPCWrappedNativeProto;
|
||||
class XPCWrappedNativeTearOff;
|
||||
class XPCNativeScriptableInfo;
|
||||
class XPCNativeScriptableCreateInfo;
|
||||
|
||||
class XPCTraceableVariant;
|
||||
|
@ -99,11 +99,11 @@ XPCCallContext::GetTearOff() const
|
||||
return mTearOff;
|
||||
}
|
||||
|
||||
inline XPCNativeScriptableInfo*
|
||||
XPCCallContext::GetScriptableInfo() const
|
||||
inline nsIXPCScriptable*
|
||||
XPCCallContext::GetScriptable() const
|
||||
{
|
||||
CHECK_STATE(HAVE_OBJECT);
|
||||
return mScriptableInfo;
|
||||
return mScriptable;
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
@ -3531,7 +3531,6 @@ bool
|
||||
XPCJSContext::DescribeCustomObjects(JSObject* obj, const js::Class* clasp,
|
||||
char (&name)[72]) const
|
||||
{
|
||||
XPCNativeScriptableInfo* si = nullptr;
|
||||
|
||||
if (!IS_PROTO_CLASS(clasp)) {
|
||||
return false;
|
||||
@ -3539,13 +3538,13 @@ XPCJSContext::DescribeCustomObjects(JSObject* obj, const js::Class* clasp,
|
||||
|
||||
XPCWrappedNativeProto* p =
|
||||
static_cast<XPCWrappedNativeProto*>(xpc_GetJSPrivate(obj));
|
||||
si = p->GetScriptableInfo();
|
||||
|
||||
if (!si) {
|
||||
nsCOMPtr<nsIXPCScriptable> scr = p->GetScriptable();
|
||||
if (!scr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SprintfLiteral(name, "JS Object (%s - %s)", clasp->name, si->GetJSClass()->name);
|
||||
SprintfLiteral(name, "JS Object (%s - %s)",
|
||||
clasp->name, scr->GetJSClass()->name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(XPCWrappedNative)
|
||||
|
||||
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
||||
char name[72];
|
||||
XPCNativeScriptableInfo* si = tmp->GetScriptableInfo();
|
||||
if (si)
|
||||
SprintfLiteral(name, "XPCWrappedNative (%s)", si->GetJSClass()->name);
|
||||
nsCOMPtr<nsIXPCScriptable> scr = tmp->GetScriptable();
|
||||
if (scr)
|
||||
SprintfLiteral(name, "XPCWrappedNative (%s)",
|
||||
scr->GetJSClass()->name);
|
||||
else
|
||||
SprintfLiteral(name, "XPCWrappedNative");
|
||||
|
||||
@ -170,13 +171,13 @@ XPCWrappedNative::WrapNewGlobal(xpcObjectHelper& nativeHelper,
|
||||
GatherScriptableCreateInfo(identity, nativeHelper.GetClassInfo(),
|
||||
sciProto, sciMaybe);
|
||||
|
||||
// ...and then ScriptableInfo. We need all this stuff now because it's going
|
||||
// to tell us the JSClass of the object we're going to create.
|
||||
XPCNativeScriptableInfo* si = XPCNativeScriptableInfo::Construct(&sciWrapper);
|
||||
MOZ_ASSERT(si);
|
||||
// ...and then get the nsIXPCScriptable. This will tell us the JSClass of
|
||||
// the object we're going to create.
|
||||
nsCOMPtr<nsIXPCScriptable> scr = sciWrapper.GetCallback();
|
||||
MOZ_ASSERT(scr);
|
||||
|
||||
// Finally, we get to the JSClass.
|
||||
const JSClass* clasp = si->GetJSClass();
|
||||
const JSClass* clasp = scr->GetJSClass();
|
||||
MOZ_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
|
||||
|
||||
// Create the global.
|
||||
@ -221,23 +222,7 @@ XPCWrappedNative::WrapNewGlobal(xpcObjectHelper& nativeHelper,
|
||||
// are different for globals. We do our setup inline here, instead.
|
||||
//
|
||||
|
||||
// Share mScriptableInfo with the proto.
|
||||
//
|
||||
// This is probably more trouble than it's worth, since we've already
|
||||
// created an XPCNativeScriptableInfo for ourselves. Nevertheless, this is
|
||||
// what ::Init() does, and we want to be as consistent as possible with
|
||||
// that code.
|
||||
XPCNativeScriptableInfo* siProto = proto->GetScriptableInfo();
|
||||
if (siProto && siProto->GetCallback() == sciWrapper.GetCallback()) {
|
||||
wrapper->mScriptableInfo = siProto;
|
||||
// XPCNativeScriptableInfo uses manual memory management. If we're
|
||||
// switching over to that of the proto, we need to destroy the one
|
||||
// we've allocated.
|
||||
delete si;
|
||||
si = nullptr;
|
||||
} else {
|
||||
wrapper->mScriptableInfo = si;
|
||||
}
|
||||
wrapper->mScriptable = scr;
|
||||
|
||||
// Set the JS object to the global we already created.
|
||||
wrapper->mFlatJSObject = global;
|
||||
@ -550,8 +535,7 @@ XPCWrappedNative::GetUsedOnly(nsISupports* Object,
|
||||
XPCWrappedNative::XPCWrappedNative(already_AddRefed<nsISupports>&& aIdentity,
|
||||
XPCWrappedNativeProto* aProto)
|
||||
: mMaybeProto(aProto),
|
||||
mSet(aProto->GetSet()),
|
||||
mScriptableInfo(nullptr)
|
||||
mSet(aProto->GetSet())
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -568,8 +552,7 @@ XPCWrappedNative::XPCWrappedNative(already_AddRefed<nsISupports>&& aIdentity,
|
||||
already_AddRefed<XPCNativeSet>&& aSet)
|
||||
|
||||
: mMaybeScope(TagScope(aScope)),
|
||||
mSet(aSet),
|
||||
mScriptableInfo(nullptr)
|
||||
mSet(aSet)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -588,14 +571,7 @@ XPCWrappedNative::~XPCWrappedNative()
|
||||
void
|
||||
XPCWrappedNative::Destroy()
|
||||
{
|
||||
XPCWrappedNativeProto* proto = GetProto();
|
||||
|
||||
if (mScriptableInfo &&
|
||||
(!HasProto() ||
|
||||
(proto && proto->GetScriptableInfo() != mScriptableInfo))) {
|
||||
delete mScriptableInfo;
|
||||
mScriptableInfo = nullptr;
|
||||
}
|
||||
mScriptable = nullptr;
|
||||
|
||||
XPCWrappedNativeScope* scope = GetScope();
|
||||
if (scope) {
|
||||
@ -729,30 +705,20 @@ bool
|
||||
XPCWrappedNative::Init(const XPCNativeScriptableCreateInfo* sci)
|
||||
{
|
||||
AutoJSContext cx;
|
||||
// setup our scriptable info...
|
||||
|
||||
if (sci->GetCallback()) {
|
||||
if (HasProto()) {
|
||||
XPCNativeScriptableInfo* siProto = GetProto()->GetScriptableInfo();
|
||||
if (siProto && siProto->GetCallback() == sci->GetCallback())
|
||||
mScriptableInfo = siProto;
|
||||
}
|
||||
if (!mScriptableInfo) {
|
||||
mScriptableInfo = XPCNativeScriptableInfo::Construct(sci);
|
||||
|
||||
if (!mScriptableInfo)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
XPCNativeScriptableInfo* si = mScriptableInfo;
|
||||
// Setup our scriptable...
|
||||
MOZ_ASSERT(!mScriptable);
|
||||
mScriptable = sci->GetCallback();
|
||||
|
||||
// create our flatJSObject
|
||||
|
||||
const JSClass* jsclazz = si ? si->GetJSClass() : Jsvalify(&XPC_WN_NoHelper_JSClass);
|
||||
const JSClass* jsclazz = mScriptable
|
||||
? mScriptable->GetJSClass()
|
||||
: Jsvalify(&XPC_WN_NoHelper_JSClass);
|
||||
|
||||
// We should have the global jsclass flag if and only if we're a global.
|
||||
MOZ_ASSERT_IF(si, !!si->GetCallback()->IsGlobalObject() ==
|
||||
!!(jsclazz->flags & JSCLASS_IS_GLOBAL));
|
||||
MOZ_ASSERT_IF(mScriptable, !!mScriptable->IsGlobalObject() ==
|
||||
!!(jsclazz->flags & JSCLASS_IS_GLOBAL));
|
||||
|
||||
MOZ_ASSERT(jsclazz &&
|
||||
jsclazz->name &&
|
||||
@ -959,7 +925,7 @@ XPCWrappedNative::SystemIsBeingShutDown()
|
||||
if (HasProto())
|
||||
proto->SystemIsBeingShutDown();
|
||||
|
||||
// We don't destroy mScriptableInfo here. The destructor will do it.
|
||||
// We don't clear mScriptable here. The destructor will do it.
|
||||
|
||||
// Cleanup the tearoffs.
|
||||
for (XPCWrappedNativeTearOff* to = &mFirstTearOff; to; to = to->GetNextTearOff()) {
|
||||
@ -1095,8 +1061,8 @@ XPCWrappedNative::InitTearOff(XPCWrappedNativeTearOff* aTearOff,
|
||||
|
||||
// If the scriptable helper forbids us from reflecting additional
|
||||
// interfaces, then don't even try the QI, just fail.
|
||||
if (mScriptableInfo &&
|
||||
mScriptableInfo->GetCallback()->ClassInfoInterfacesOnly() &&
|
||||
if (mScriptable &&
|
||||
mScriptable->ClassInfoInterfacesOnly() &&
|
||||
!mSet->HasInterface(aInterface) &&
|
||||
!mSet->HasInterfaceWithAncestor(aInterface)) {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
@ -2152,14 +2118,12 @@ NS_IMETHODIMP XPCWrappedNative::DebugDump(int16_t depth)
|
||||
|
||||
XPC_LOG_ALWAYS(("mFlatJSObject of %x", mFlatJSObject.unbarrieredGetPtr()));
|
||||
XPC_LOG_ALWAYS(("mIdentity of %x", mIdentity.get()));
|
||||
XPC_LOG_ALWAYS(("mScriptableInfo @ %x", mScriptableInfo));
|
||||
XPC_LOG_ALWAYS(("mScriptable @ %x", mScriptable.get()));
|
||||
|
||||
if (depth && mScriptableInfo) {
|
||||
nsCOMPtr<nsIXPCScriptable> scr = mScriptableInfo->GetCallback();
|
||||
if (depth && mScriptable) {
|
||||
XPC_LOG_INDENT();
|
||||
XPC_LOG_ALWAYS(("mScriptable @ %x", scr.get()));
|
||||
XPC_LOG_ALWAYS(("mFlags of %x", scr->GetScriptableFlags()));
|
||||
XPC_LOG_ALWAYS(("mJSClass @ %x", mScriptableInfo->GetJSClass()));
|
||||
XPC_LOG_ALWAYS(("mFlags of %x", mScriptable->GetScriptableFlags()));
|
||||
XPC_LOG_ALWAYS(("mJSClass @ %x", mScriptable->GetJSClass()));
|
||||
XPC_LOG_OUTDENT();
|
||||
}
|
||||
XPC_LOG_OUTDENT();
|
||||
@ -2185,9 +2149,9 @@ XPCWrappedNative::ToString(XPCWrappedNativeTearOff* to /* = nullptr */ ) const
|
||||
char* sz = nullptr;
|
||||
char* name = nullptr;
|
||||
|
||||
XPCNativeScriptableInfo* si = GetScriptableInfo();
|
||||
if (si)
|
||||
name = JS_smprintf("%s", si->GetJSClass()->name);
|
||||
nsCOMPtr<nsIXPCScriptable> scr = GetScriptable();
|
||||
if (scr)
|
||||
name = JS_smprintf("%s", scr->GetJSClass()->name);
|
||||
if (to) {
|
||||
const char* fmt = name ? " (%s)" : "%s";
|
||||
name = JS_sprintf_append(name, fmt,
|
||||
@ -2218,7 +2182,7 @@ XPCWrappedNative::ToString(XPCWrappedNativeTearOff* to /* = nullptr */ ) const
|
||||
}
|
||||
const char* fmt = "[xpconnect wrapped %s" FMT_ADDR FMT_STR(" (native")
|
||||
FMT_ADDR FMT_STR(")") "]";
|
||||
if (si) {
|
||||
if (scr) {
|
||||
fmt = "[object %s" FMT_ADDR FMT_STR(" (native") FMT_ADDR FMT_STR(")") "]";
|
||||
}
|
||||
sz = JS_smprintf(fmt, name PARAM_ADDR(this) PARAM_ADDR(mIdentity.get()));
|
||||
@ -2267,12 +2231,10 @@ static void DEBUG_CheckClassInfoClaims(XPCWrappedNative* wrapper)
|
||||
|
||||
info->GetNameShared(&interfaceName);
|
||||
clsInfo->GetContractID(&contractID);
|
||||
if (wrapper->GetScriptableInfo()) {
|
||||
wrapper->GetScriptableInfo()->GetCallback()->
|
||||
GetClassName(&className);
|
||||
if (wrapper->GetScriptable()) {
|
||||
wrapper->GetScriptable()->GetClassName(&className);
|
||||
}
|
||||
|
||||
|
||||
printf("\n!!! Object's nsIClassInfo lies about its interfaces!!!\n"
|
||||
" classname: %s \n"
|
||||
" contractid: %s \n"
|
||||
|
@ -229,7 +229,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
bool reflectToStringAndToSource,
|
||||
XPCWrappedNative* wrapperToReflectInterfaceNames,
|
||||
XPCWrappedNative* wrapperToReflectDoubleWrap,
|
||||
XPCNativeScriptableInfo* scriptableInfo,
|
||||
nsIXPCScriptable* scr,
|
||||
unsigned propFlags,
|
||||
bool* resolved)
|
||||
{
|
||||
@ -254,9 +254,8 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
JSNative call;
|
||||
uint32_t flags = 0;
|
||||
|
||||
if (scriptableInfo) {
|
||||
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(
|
||||
scriptableInfo->GetCallback());
|
||||
if (scr) {
|
||||
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(scr);
|
||||
|
||||
if (classInfo) {
|
||||
nsresult rv = classInfo->GetFlags(&flags);
|
||||
@ -415,8 +414,8 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
|
||||
if (id == xpccx->GetStringID(XPCJSContext::IDX_TO_STRING) ||
|
||||
id == xpccx->GetStringID(XPCJSContext::IDX_TO_SOURCE) ||
|
||||
(scriptableInfo &&
|
||||
scriptableInfo->GetCallback()->DontEnumQueryInterface() &&
|
||||
(scr &&
|
||||
scr->DontEnumQueryInterface() &&
|
||||
id == xpccx->GetStringID(XPCJSContext::IDX_QUERY_INTERFACE)))
|
||||
propFlags &= ~JSPROP_ENUMERATE;
|
||||
|
||||
@ -549,7 +548,7 @@ WrappedNativeFinalize(js::FreeOp* fop, JSObject* obj, WNHelperType helperType)
|
||||
|
||||
XPCWrappedNative* wrapper = static_cast<XPCWrappedNative*>(p);
|
||||
if (helperType == WN_HELPER)
|
||||
wrapper->GetScriptableCallback()->Finalize(wrapper, js::CastToJSFreeOp(fop), obj);
|
||||
wrapper->GetScriptable()->Finalize(wrapper, js::CastToJSFreeOp(fop), obj);
|
||||
wrapper->FlatJSObjectFinalized();
|
||||
}
|
||||
|
||||
@ -704,7 +703,7 @@ XPC_WN_MaybeResolvingDeletePropertyStub(JSContext* cx, HandleObject obj, HandleI
|
||||
XPCWrappedNative* wrapper = XPCWrappedNative::Get(unwrapped); \
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); \
|
||||
bool retval = true; \
|
||||
nsresult rv = wrapper->GetScriptableCallback()->
|
||||
nsresult rv = wrapper->GetScriptable()->
|
||||
|
||||
#define POST_HELPER_STUB \
|
||||
if (NS_FAILED(rv)) \
|
||||
@ -797,15 +796,15 @@ XPC_WN_Helper_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolv
|
||||
|
||||
RootedId old(cx, ccx.SetResolveName(id));
|
||||
|
||||
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
|
||||
if (si && si->GetCallback()->WantResolve()) {
|
||||
nsCOMPtr<nsIXPCScriptable> scr = wrapper->GetScriptable();
|
||||
if (scr && scr->WantResolve()) {
|
||||
XPCWrappedNative* oldResolvingWrapper;
|
||||
bool allowPropMods = si->GetCallback()->AllowPropModsDuringResolve();
|
||||
bool allowPropMods = scr->AllowPropModsDuringResolve();
|
||||
|
||||
if (allowPropMods)
|
||||
oldResolvingWrapper = ccx.SetResolvingWrapper(wrapper);
|
||||
|
||||
rv = si->GetCallback()->Resolve(wrapper, cx, obj, id, &resolved, &retval);
|
||||
rv = scr->Resolve(wrapper, cx, obj, id, &resolved, &retval);
|
||||
|
||||
if (allowPropMods)
|
||||
(void)ccx.SetResolvingWrapper(oldResolvingWrapper);
|
||||
@ -835,9 +834,7 @@ XPC_WN_Helper_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolv
|
||||
IsLocal) {
|
||||
|
||||
XPCWrappedNative* wrapperForInterfaceNames =
|
||||
(si && si->GetCallback()->DontReflectInterfaceNames())
|
||||
? nullptr
|
||||
: wrapper;
|
||||
(scr && scr->DontReflectInterfaceNames()) ? nullptr : wrapper;
|
||||
|
||||
XPCWrappedNative* oldResolvingWrapper =
|
||||
ccx.SetResolvingWrapper(wrapper);
|
||||
@ -846,7 +843,7 @@ XPC_WN_Helper_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolv
|
||||
wrapper->GetScope(),
|
||||
false,
|
||||
wrapperForInterfaceNames,
|
||||
nullptr, si,
|
||||
nullptr, scr,
|
||||
JSPROP_ENUMERATE, resolvedp);
|
||||
(void)ccx.SetResolvingWrapper(oldResolvingWrapper);
|
||||
}
|
||||
@ -862,15 +859,15 @@ XPC_WN_Helper_Enumerate(JSContext* cx, HandleObject obj)
|
||||
XPCWrappedNative* wrapper = ccx.GetWrapper();
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
|
||||
if (!si || !si->GetCallback()->WantEnumerate())
|
||||
nsCOMPtr<nsIXPCScriptable> scr = wrapper->GetScriptable();
|
||||
if (!scr || !scr->WantEnumerate())
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
|
||||
if (!XPC_WN_Shared_Enumerate(cx, obj))
|
||||
return false;
|
||||
|
||||
bool retval = true;
|
||||
nsresult rv = si->GetCallback()->Enumerate(wrapper, cx, obj, &retval);
|
||||
nsresult rv = scr->Enumerate(wrapper, cx, obj, &retval);
|
||||
if (NS_FAILED(rv))
|
||||
return Throw(rv, cx);
|
||||
return retval;
|
||||
@ -886,15 +883,15 @@ XPC_WN_JSOp_Enumerate(JSContext* cx, HandleObject obj, AutoIdVector& properties,
|
||||
XPCWrappedNative* wrapper = ccx.GetWrapper();
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
|
||||
if (!si || !si->GetCallback()->WantNewEnumerate())
|
||||
nsCOMPtr<nsIXPCScriptable> scr = wrapper->GetScriptable();
|
||||
if (!scr || !scr->WantNewEnumerate())
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
|
||||
if (!XPC_WN_Shared_Enumerate(cx, obj))
|
||||
return false;
|
||||
|
||||
bool retval = true;
|
||||
nsresult rv = si->GetCallback()->NewEnumerate(wrapper, cx, obj, properties, &retval);
|
||||
nsresult rv = scr->NewEnumerate(wrapper, cx, obj, properties, &retval);
|
||||
if (NS_FAILED(rv))
|
||||
return Throw(rv, cx);
|
||||
return retval;
|
||||
@ -902,16 +899,6 @@ XPC_WN_JSOp_Enumerate(JSContext* cx, HandleObject obj, AutoIdVector& properties,
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// static
|
||||
XPCNativeScriptableInfo*
|
||||
XPCNativeScriptableInfo::Construct(const XPCNativeScriptableCreateInfo* sci)
|
||||
{
|
||||
MOZ_ASSERT(sci, "bad param");
|
||||
nsCOMPtr<nsIXPCScriptable> callback = sci->GetCallback();
|
||||
MOZ_ASSERT(callback);
|
||||
return new XPCNativeScriptableInfo(callback);
|
||||
}
|
||||
|
||||
const js::ObjectOps XPC_WN_ObjectOpsWithEnumerate = {
|
||||
nullptr, // lookupProperty
|
||||
nullptr, // defineProperty
|
||||
@ -1113,11 +1100,11 @@ XPC_WN_ModsAllowed_Proto_Resolve(JSContext* cx, HandleObject obj, HandleId id, b
|
||||
if (!ccx.IsValid())
|
||||
return false;
|
||||
|
||||
XPCNativeScriptableInfo* si = self->GetScriptableInfo();
|
||||
nsCOMPtr<nsIXPCScriptable> scr = self->GetScriptable();
|
||||
return DefinePropertyIfFound(ccx, obj, id,
|
||||
self->GetSet(), nullptr, nullptr,
|
||||
self->GetScope(),
|
||||
true, nullptr, nullptr, si,
|
||||
true, nullptr, nullptr, scr,
|
||||
JSPROP_ENUMERATE, resolvep);
|
||||
}
|
||||
|
||||
@ -1190,12 +1177,12 @@ XPC_WN_NoMods_Proto_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool*
|
||||
if (!ccx.IsValid())
|
||||
return false;
|
||||
|
||||
XPCNativeScriptableInfo* si = self->GetScriptableInfo();
|
||||
nsCOMPtr<nsIXPCScriptable> scr = self->GetScriptable();
|
||||
|
||||
return DefinePropertyIfFound(ccx, obj, id,
|
||||
self->GetSet(), nullptr, nullptr,
|
||||
self->GetScope(),
|
||||
true, nullptr, nullptr, si,
|
||||
true, nullptr, nullptr, scr,
|
||||
JSPROP_READONLY |
|
||||
JSPROP_PERMANENT |
|
||||
JSPROP_ENUMERATE, resolvedp);
|
||||
|
@ -21,8 +21,7 @@ XPCWrappedNativeProto::XPCWrappedNativeProto(XPCWrappedNativeScope* Scope,
|
||||
: mScope(Scope),
|
||||
mJSProtoObject(nullptr),
|
||||
mClassInfo(ClassInfo),
|
||||
mSet(Set),
|
||||
mScriptableInfo(nullptr)
|
||||
mSet(Set)
|
||||
{
|
||||
// This native object lives as long as its associated JSObject - killed
|
||||
// by finalization of the JSObject (or explicitly if Init fails).
|
||||
@ -48,8 +47,6 @@ XPCWrappedNativeProto::~XPCWrappedNativeProto()
|
||||
// Note that our weak ref to mScope is not to be trusted at this point.
|
||||
|
||||
XPCNativeSet::ClearCacheEntryForClassInfo(mClassInfo);
|
||||
|
||||
delete mScriptableInfo;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -57,19 +54,14 @@ XPCWrappedNativeProto::Init(const XPCNativeScriptableCreateInfo* scriptableCreat
|
||||
bool callPostCreatePrototype)
|
||||
{
|
||||
AutoJSContext cx;
|
||||
nsIXPCScriptable* callback = scriptableCreateInfo ?
|
||||
scriptableCreateInfo->GetCallback() :
|
||||
nullptr;
|
||||
if (callback) {
|
||||
mScriptableInfo =
|
||||
XPCNativeScriptableInfo::Construct(scriptableCreateInfo);
|
||||
if (!mScriptableInfo)
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIXPCScriptable> callback = scriptableCreateInfo
|
||||
? scriptableCreateInfo->GetCallback() :
|
||||
: nullptr;
|
||||
if (callback)
|
||||
mScriptable = callback;
|
||||
|
||||
const js::Class* jsclazz =
|
||||
(mScriptableInfo &&
|
||||
mScriptableInfo->GetCallback()->AllowPropModsToPrototype())
|
||||
(mScriptable && mScriptable->AllowPropModsToPrototype())
|
||||
? &XPC_WN_ModsAllowed_Proto_JSClass
|
||||
: &XPC_WN_NoMods_Proto_JSClass;
|
||||
|
||||
@ -94,14 +86,12 @@ XPCWrappedNativeProto::CallPostCreatePrototype()
|
||||
AutoJSContext cx;
|
||||
|
||||
// Nothing to do if we don't have a scriptable callback.
|
||||
nsIXPCScriptable* callback = mScriptableInfo ? mScriptableInfo->GetCallback()
|
||||
: nullptr;
|
||||
if (!callback)
|
||||
if (!mScriptable)
|
||||
return true;
|
||||
|
||||
// Call the helper. This can handle being called if it's not implemented,
|
||||
// so we don't have to check any sort of "want" here. See xpc_map_end.h.
|
||||
nsresult rv = callback->PostCreatePrototype(cx, mJSProtoObject);
|
||||
nsresult rv = mScriptable->PostCreatePrototype(cx, mJSProtoObject);
|
||||
if (NS_FAILED(rv)) {
|
||||
JS_SetPrivate(mJSProtoObject, nullptr);
|
||||
mJSProtoObject = nullptr;
|
||||
@ -193,13 +183,11 @@ XPCWrappedNativeProto::DebugDump(int16_t depth)
|
||||
XPC_LOG_ALWAYS(("mScope @ %x", mScope));
|
||||
XPC_LOG_ALWAYS(("mJSProtoObject @ %x", mJSProtoObject.get()));
|
||||
XPC_LOG_ALWAYS(("mSet @ %x", mSet.get()));
|
||||
XPC_LOG_ALWAYS(("mScriptableInfo @ %x", mScriptableInfo));
|
||||
if (depth && mScriptableInfo) {
|
||||
nsCOMPtr<nsIXPCScriptable> scr = mScriptableInfo->GetCallback();
|
||||
XPC_LOG_ALWAYS(("mScriptable @ %x", mScriptable.get()));
|
||||
if (depth && mScriptable) {
|
||||
XPC_LOG_INDENT();
|
||||
XPC_LOG_ALWAYS(("mScriptable @ %x", scr.get()));
|
||||
XPC_LOG_ALWAYS(("mFlags of %x", scr->GetScriptableFlags()));
|
||||
XPC_LOG_ALWAYS(("mJSClass @ %x", mScriptableInfo->GetJSClass()));
|
||||
XPC_LOG_ALWAYS(("mFlags of %x", mScriptable->GetScriptableFlags()));
|
||||
XPC_LOG_ALWAYS(("mJSClass @ %x", mScriptable->GetJSClass()));
|
||||
XPC_LOG_OUTDENT();
|
||||
}
|
||||
XPC_LOG_OUTDENT();
|
||||
|
@ -16,8 +16,8 @@ namespace XPCNativeWrapper {
|
||||
// set.
|
||||
// XXX Convert to using GetFlags() and not a macro.
|
||||
#define NATIVE_HAS_FLAG(_wn, _flag) \
|
||||
((_wn)->GetScriptableInfo() && \
|
||||
(_wn)->GetScriptableInfo()->GetCallback()->_flag())
|
||||
((_wn)->GetScriptable() && \
|
||||
(_wn)->GetScriptable()->_flag())
|
||||
|
||||
bool
|
||||
AttachNewConstructorObject(JSContext* aCx, JS::HandleObject aGlobalObject);
|
||||
|
@ -58,8 +58,7 @@
|
||||
* nsIXPCScriptable). This allows it to implement a more DOM-like interface,
|
||||
* besides just exposing XPCOM methods and constants. An nsIXPCScriptable
|
||||
* instance has hooks that correspond to all the normal JSClass hooks. Each
|
||||
* nsIXPCScriptable instance is mirrored by an XPCNativeScriptableInfo in
|
||||
* XPConnect. These can have pointers from XPCWrappedNativeProto and
|
||||
* nsIXPCScriptable instance can have pointers from XPCWrappedNativeProto and
|
||||
* XPCWrappedNative (since C++ objects can have scriptable info without having
|
||||
* class info).
|
||||
*/
|
||||
@ -703,7 +702,7 @@ public:
|
||||
inline bool CanGetTearOff() const ;
|
||||
inline XPCWrappedNativeTearOff* GetTearOff() const ;
|
||||
|
||||
inline XPCNativeScriptableInfo* GetScriptableInfo() const ;
|
||||
inline nsIXPCScriptable* GetScriptable() const ;
|
||||
inline bool CanGetSet() const ;
|
||||
inline XPCNativeSet* GetSet() const ;
|
||||
inline bool CanGetInterface() const ;
|
||||
@ -779,7 +778,7 @@ private:
|
||||
XPCWrappedNative* mWrapper;
|
||||
XPCWrappedNativeTearOff* mTearOff;
|
||||
|
||||
XPCNativeScriptableInfo* mScriptableInfo;
|
||||
nsCOMPtr<nsIXPCScriptable> mScriptable;
|
||||
|
||||
RefPtr<XPCNativeSet> mSet;
|
||||
RefPtr<XPCNativeInterface> mInterface;
|
||||
@ -1383,47 +1382,9 @@ class XPCNativeSet final
|
||||
XPCNativeInterface* mInterfaces[1];
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// XPCNativeScriptableInfo is a trivial wrapper for nsIXPCScriptable which
|
||||
// should be removed eventually.
|
||||
|
||||
class XPCNativeScriptableInfo final
|
||||
{
|
||||
public:
|
||||
static XPCNativeScriptableInfo*
|
||||
Construct(const XPCNativeScriptableCreateInfo* sci);
|
||||
|
||||
nsIXPCScriptable*
|
||||
GetCallback() const { return mCallback; }
|
||||
|
||||
const JSClass*
|
||||
GetJSClass() { return Jsvalify(mCallback->GetClass()); }
|
||||
|
||||
protected:
|
||||
explicit XPCNativeScriptableInfo(nsIXPCScriptable* aCallback)
|
||||
: mCallback(aCallback)
|
||||
{
|
||||
MOZ_COUNT_CTOR(XPCNativeScriptableInfo);
|
||||
}
|
||||
public:
|
||||
~XPCNativeScriptableInfo()
|
||||
{
|
||||
MOZ_COUNT_DTOR(XPCNativeScriptableInfo);
|
||||
}
|
||||
private:
|
||||
|
||||
// disable copy ctor and assignment
|
||||
XPCNativeScriptableInfo(const XPCNativeScriptableInfo& r) = delete;
|
||||
XPCNativeScriptableInfo& operator= (const XPCNativeScriptableInfo& r) = delete;
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIXPCScriptable> mCallback;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// XPCNativeScriptableCreateInfo is used in creating new wrapper and protos.
|
||||
// it abstracts out the scriptable interface pointer and the flags. After
|
||||
// creation these are factored differently using XPCNativeScriptableInfo.
|
||||
// It abstracts out the scriptable interface pointer and the flags.
|
||||
|
||||
class MOZ_STACK_CLASS XPCNativeScriptableCreateInfo final
|
||||
{
|
||||
@ -1469,8 +1430,8 @@ public:
|
||||
XPCNativeSet*
|
||||
GetSet() const {return mSet;}
|
||||
|
||||
XPCNativeScriptableInfo*
|
||||
GetScriptableInfo() {return mScriptableInfo;}
|
||||
nsIXPCScriptable*
|
||||
GetScriptable() const { return mScriptable; }
|
||||
|
||||
bool CallPostCreatePrototype();
|
||||
void JSProtoObjectFinalized(js::FreeOp* fop, JSObject* obj);
|
||||
@ -1529,7 +1490,7 @@ private:
|
||||
JS::ObjectPtr mJSProtoObject;
|
||||
nsCOMPtr<nsIClassInfo> mClassInfo;
|
||||
RefPtr<XPCNativeSet> mSet;
|
||||
XPCNativeScriptableInfo* mScriptableInfo;
|
||||
nsCOMPtr<nsIXPCScriptable> mScriptable;
|
||||
};
|
||||
|
||||
/***********************************************/
|
||||
@ -1692,11 +1653,8 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
XPCNativeScriptableInfo*
|
||||
GetScriptableInfo() const {return mScriptableInfo;}
|
||||
|
||||
nsIXPCScriptable* // call this wrong and you deserve to crash
|
||||
GetScriptableCallback() const {return mScriptableInfo->GetCallback();}
|
||||
nsIXPCScriptable*
|
||||
GetScriptable() const { return mScriptable; }
|
||||
|
||||
nsIClassInfo*
|
||||
GetClassInfo() const {return IsValid() && HasProto() ?
|
||||
@ -1844,7 +1802,7 @@ private:
|
||||
};
|
||||
RefPtr<XPCNativeSet> mSet;
|
||||
JS::TenuredHeap<JSObject*> mFlatJSObject;
|
||||
XPCNativeScriptableInfo* mScriptableInfo;
|
||||
nsCOMPtr<nsIXPCScriptable> mScriptable;
|
||||
XPCWrappedNativeTearOff mFirstTearOff;
|
||||
};
|
||||
|
||||
|
@ -211,7 +211,7 @@ WrapperFactory::PrepareForWrapping(JSContext* cx, HandleObject scope,
|
||||
// being accessed across compartments. We would really prefer to
|
||||
// replace the above code with a test that says "do you only have one
|
||||
// wrapper?"
|
||||
nsresult rv = wn->GetScriptableInfo()->GetCallback()->
|
||||
nsresult rv = wn->GetScriptable()->
|
||||
PreCreate(wn->Native(), cx, scope, wrapScope.address());
|
||||
if (NS_FAILED(rv)) {
|
||||
retObj.set(waive ? WaiveXray(cx, obj) : obj);
|
||||
@ -250,7 +250,7 @@ WrapperFactory::PrepareForWrapping(JSContext* cx, HandleObject scope,
|
||||
// (the old scope). If (2) is the case, PreCreate will return the
|
||||
// scope of the document (the new scope).
|
||||
RootedObject probe(cx);
|
||||
rv = wn->GetScriptableInfo()->GetCallback()->
|
||||
rv = wn->GetScriptable()->
|
||||
PreCreate(wn->Native(), cx, currentScope, probe.address());
|
||||
|
||||
// Check for case (2).
|
||||
|
@ -1579,8 +1579,7 @@ XPCWrappedNativeXrayTraits::call(JSContext* cx, HandleObject wrapper,
|
||||
if (!ccx.IsValid())
|
||||
return false;
|
||||
bool ok = true;
|
||||
nsresult rv = wn->GetScriptableInfo()->GetCallback()->Call(
|
||||
wn, cx, wrapper, args, &ok);
|
||||
nsresult rv = wn->GetScriptable()->Call(wn, cx, wrapper, args, &ok);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (ok)
|
||||
XPCThrower::Throw(rv, cx);
|
||||
@ -1605,8 +1604,8 @@ XPCWrappedNativeXrayTraits::construct(JSContext* cx, HandleObject wrapper,
|
||||
if (!ccx.IsValid())
|
||||
return false;
|
||||
bool ok = true;
|
||||
nsresult rv = wn->GetScriptableInfo()->GetCallback()->Construct(
|
||||
wn, cx, wrapper, args, &ok);
|
||||
nsresult rv =
|
||||
wn->GetScriptable()->Construct(wn, cx, wrapper, args, &ok);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (ok)
|
||||
XPCThrower::Throw(rv, cx);
|
||||
|
Loading…
Reference in New Issue
Block a user