mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 860311 - GC: More rooting in XPConnect r=bholley
--HG-- extra : rebase_source : 3afba11173f0df957fe34e66b9dd443b5ed01b9a
This commit is contained in:
parent
9dbbe9752e
commit
b935ddbe82
@ -829,7 +829,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
||||
nsWrapperCache *cache = aHelper.GetWrapperCache();
|
||||
|
||||
bool tryConstructSlimWrapper = false;
|
||||
JSObject *flat;
|
||||
JS::RootedObject flat(cx);
|
||||
if (cache) {
|
||||
flat = cache->GetWrapper();
|
||||
if (cache->IsDOMBinding()) {
|
||||
@ -845,7 +845,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
||||
}
|
||||
|
||||
if (flat) {
|
||||
if (allowNativeWrapper && !JS_WrapObject(ccx, &flat))
|
||||
if (allowNativeWrapper && !JS_WrapObject(ccx, flat.address()))
|
||||
return false;
|
||||
|
||||
return CreateHolderIfNeeded(ccx, flat, d, dest);
|
||||
@ -975,7 +975,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
||||
// The call to wrap here handles both cross-compartment and same-compartment
|
||||
// security wrappers.
|
||||
JSObject *original = flat;
|
||||
if (!JS_WrapObject(ccx, &flat))
|
||||
if (!JS_WrapObject(ccx, flat.address()))
|
||||
return false;
|
||||
|
||||
*d = OBJECT_TO_JSVAL(flat);
|
||||
|
@ -494,7 +494,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
||||
|
||||
if (!JSVAL_IS_PRIMITIVE(val)) {
|
||||
// we have a JSObject
|
||||
JSObject* obj = JSVAL_TO_OBJECT(val);
|
||||
JS::RootedObject obj(cx, JSVAL_TO_OBJECT(val));
|
||||
|
||||
NS_ASSERTION(obj, "when is an object not an object?");
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
using namespace xpc;
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace JS;
|
||||
|
||||
bool
|
||||
xpc_OkToHandOutWrapper(nsWrapperCache *cache)
|
||||
@ -284,7 +285,7 @@ FinishCreate(XPCCallContext& ccx,
|
||||
nsresult
|
||||
XPCWrappedNative::WrapNewGlobal(XPCCallContext &ccx, xpcObjectHelper &nativeHelper,
|
||||
nsIPrincipal *principal, bool initStandardClasses,
|
||||
JS::ZoneSpecifier zoneSpec,
|
||||
ZoneSpecifier zoneSpec,
|
||||
XPCWrappedNative **wrappedGlobal)
|
||||
{
|
||||
nsISupports *identity = nativeHelper.GetCanonical();
|
||||
@ -314,7 +315,7 @@ XPCWrappedNative::WrapNewGlobal(XPCCallContext &ccx, xpcObjectHelper &nativeHelp
|
||||
MOZ_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
|
||||
|
||||
// Create the global.
|
||||
JSObject *global = xpc::CreateGlobalObject(ccx, clasp, principal, zoneSpec);
|
||||
RootedObject global(ccx, xpc::CreateGlobalObject(ccx, clasp, principal, zoneSpec));
|
||||
if (!global)
|
||||
return NS_ERROR_FAILURE;
|
||||
XPCWrappedNativeScope *scope = GetCompartmentPrivate(global)->scope;
|
||||
@ -500,7 +501,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
isClassInfo ? sci :
|
||||
GatherScriptableCreateInfo(identity, info, sciProto, sci);
|
||||
|
||||
JSObject* parent = Scope->GetGlobalJSObject();
|
||||
RootedObject parent(ccx, Scope->GetGlobalJSObject());
|
||||
|
||||
jsval newParentVal = JSVAL_NULL;
|
||||
XPCMarkableJSVal newParentVal_markable(&newParentVal);
|
||||
@ -514,9 +515,9 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
// PreCreate may touch dead compartments.
|
||||
js::AutoMaybeTouchDeadZones agc(parent);
|
||||
|
||||
JSObject* plannedParent = parent;
|
||||
RootedObject plannedParent(ccx, parent);
|
||||
nsresult rv = sciWrapper.GetCallback()->PreCreate(identity, ccx,
|
||||
parent, &parent);
|
||||
parent, parent.address());
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
@ -542,7 +543,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
// interesting path (the DOM code tends to make this happen sometimes).
|
||||
|
||||
if (cache) {
|
||||
JSObject *cached = cache->GetWrapper();
|
||||
RootedObject cached(ccx, cache->GetWrapper());
|
||||
if (cached) {
|
||||
if (IS_SLIM_WRAPPER_OBJECT(cached)) {
|
||||
if (NS_FAILED(XPCWrappedNative::Morph(ccx, cached,
|
||||
@ -572,8 +573,8 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
nsISupports *Object = helper.Object();
|
||||
if (nsXPCWrappedJSClass::IsWrappedJS(Object)) {
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedjs(do_QueryInterface(Object));
|
||||
JSObject *obj;
|
||||
wrappedjs->GetJSObject(&obj);
|
||||
RootedObject obj(ccx);
|
||||
wrappedjs->GetJSObject(obj.address());
|
||||
if (xpc::AccessCheck::isChrome(js::GetObjectCompartment(obj)) &&
|
||||
!xpc::AccessCheck::isChrome(js::GetObjectCompartment(Scope->GetGlobalJSObject()))) {
|
||||
needsCOW = true;
|
||||
@ -736,7 +737,7 @@ FinishCreate(XPCCallContext& ccx,
|
||||
// static
|
||||
nsresult
|
||||
XPCWrappedNative::Morph(XPCCallContext& ccx,
|
||||
JSObject* existingJSObject,
|
||||
HandleObject existingJSObject,
|
||||
XPCNativeInterface* Interface,
|
||||
nsWrapperCache *cache,
|
||||
XPCWrappedNative** resultWrapper)
|
||||
@ -808,7 +809,7 @@ XPCWrappedNative::GetUsedOnly(XPCCallContext& ccx,
|
||||
nsWrapperCache* cache = nullptr;
|
||||
CallQueryInterface(Object, &cache);
|
||||
if (cache) {
|
||||
JSObject *flat = cache->GetWrapper();
|
||||
RootedObject flat(ccx, cache->GetWrapper());
|
||||
if (flat && IS_SLIM_WRAPPER_OBJECT(flat) && !MorphSlimWrapper(ccx, flat))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -944,8 +945,8 @@ XPCWrappedNative::Destroy()
|
||||
* the first time because mWrapperWord isn't used afterwards.
|
||||
*/
|
||||
if (XPCJSRuntime *rt = GetRuntime()) {
|
||||
if (JS::IsIncrementalBarrierNeeded(rt->GetJSRuntime()))
|
||||
JS::IncrementalObjectBarrier(GetWrapperPreserveColor());
|
||||
if (IsIncrementalBarrierNeeded(rt->GetJSRuntime()))
|
||||
IncrementalObjectBarrier(GetWrapperPreserveColor());
|
||||
mWrapperWord = WRAPPER_WORD_POISON;
|
||||
} else {
|
||||
MOZ_ASSERT(mWrapperWord == WRAPPER_WORD_POISON);
|
||||
@ -961,7 +962,7 @@ XPCWrappedNative::UpdateScriptableInfo(XPCNativeScriptableInfo *si)
|
||||
|
||||
// Write barrier for incremental GC.
|
||||
JSRuntime* rt = GetRuntime()->GetJSRuntime();
|
||||
if (JS::IsIncrementalBarrierNeeded(rt))
|
||||
if (IsIncrementalBarrierNeeded(rt))
|
||||
mScriptableInfo->Mark();
|
||||
|
||||
mScriptableInfo = si;
|
||||
@ -1094,7 +1095,7 @@ static uint32_t sMorphedSlimWrappers;
|
||||
#endif
|
||||
|
||||
JSBool
|
||||
XPCWrappedNative::Init(XPCCallContext& ccx, JSObject* parent,
|
||||
XPCWrappedNative::Init(XPCCallContext& ccx, HandleObject parent,
|
||||
const XPCNativeScriptableCreateInfo* sci)
|
||||
{
|
||||
// setup our scriptable info...
|
||||
@ -1400,8 +1401,8 @@ XPCWrappedNative::SystemIsBeingShutDown()
|
||||
// Dynamically ensure that two objects don't end up with the same private.
|
||||
class MOZ_STACK_CLASS AutoClonePrivateGuard {
|
||||
public:
|
||||
AutoClonePrivateGuard(JSObject *aOld, JSObject *aNew)
|
||||
: mOldReflector(aOld), mNewReflector(aNew)
|
||||
AutoClonePrivateGuard(JSContext *cx, JSObject *aOld, JSObject *aNew)
|
||||
: mOldReflector(cx, aOld), mNewReflector(cx, aNew)
|
||||
{
|
||||
MOZ_ASSERT(JS_GetPrivate(aOld) == JS_GetPrivate(aNew));
|
||||
}
|
||||
@ -1414,8 +1415,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
JSObject* mOldReflector;
|
||||
JSObject* mNewReflector;
|
||||
RootedObject mOldReflector;
|
||||
RootedObject mNewReflector;
|
||||
};
|
||||
|
||||
// static
|
||||
@ -1423,7 +1424,7 @@ nsresult
|
||||
XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
XPCWrappedNativeScope* aOldScope,
|
||||
XPCWrappedNativeScope* aNewScope,
|
||||
JSObject* aNewParent,
|
||||
HandleObject aNewParent,
|
||||
nsISupports* aCOMObj)
|
||||
{
|
||||
XPCNativeInterface* iface =
|
||||
@ -1435,7 +1436,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
nsresult rv;
|
||||
|
||||
nsRefPtr<XPCWrappedNative> wrapper;
|
||||
JSObject *flat = nullptr;
|
||||
RootedObject flat(ccx);
|
||||
nsWrapperCache* cache = nullptr;
|
||||
CallQueryInterface(aCOMObj, &cache);
|
||||
if (cache) {
|
||||
@ -1505,9 +1506,9 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
// ending up with two reflectors pointing to the same WN. Other than
|
||||
// that, the objects we create will just go away if we return early.
|
||||
|
||||
JSObject *newobj = JS_CloneObject(ccx, flat,
|
||||
newProto->GetJSProtoObject(),
|
||||
aNewParent);
|
||||
RootedObject newobj(ccx, JS_CloneObject(ccx, flat,
|
||||
newProto->GetJSProtoObject(),
|
||||
aNewParent));
|
||||
if (!newobj)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -1518,9 +1519,9 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
// |newobj| will be set to NULL. |flat| will go away soon, because
|
||||
// we swap it with another object during the transplant and let that
|
||||
// object die.
|
||||
JSObject *propertyHolder;
|
||||
RootedObject propertyHolder(ccx);
|
||||
{
|
||||
AutoClonePrivateGuard cloneGuard(flat, newobj);
|
||||
AutoClonePrivateGuard cloneGuard(ccx, flat, newobj);
|
||||
|
||||
propertyHolder = JS_NewObjectWithGivenProto(ccx, NULL, NULL, aNewParent);
|
||||
if (!propertyHolder)
|
||||
@ -1668,7 +1669,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
// See bug 751995 for more information.
|
||||
|
||||
static nsresult
|
||||
RescueOrphans(XPCCallContext& ccx, JSObject* obj)
|
||||
RescueOrphans(XPCCallContext& ccx, HandleObject obj)
|
||||
{
|
||||
//
|
||||
// Even if we're not an orphan at the moment, one of our ancestors might
|
||||
@ -1682,7 +1683,7 @@ RescueOrphans(XPCCallContext& ccx, JSObject* obj)
|
||||
// NB: We pass stopAtOuter=false during the unwrap because Location objects
|
||||
// are parented to outer window proxies.
|
||||
nsresult rv;
|
||||
JSObject *parentObj = js::GetObjectParent(obj);
|
||||
RootedObject parentObj(ccx, js::GetObjectParent(obj));
|
||||
if (!parentObj)
|
||||
return NS_OK; // Global object. We're done.
|
||||
parentObj = js::UncheckedUnwrap(parentObj, /* stopAtOuter = */ false);
|
||||
@ -1703,8 +1704,8 @@ RescueOrphans(XPCCallContext& ccx, JSObject* obj)
|
||||
XPCWrappedNative *wn =
|
||||
static_cast<XPCWrappedNative*>(js::GetObjectPrivate(obj));
|
||||
rv = wn->GetScriptableInfo()->GetCallback()->PreCreate(wn->GetIdentityObject(), ccx,
|
||||
wn->GetScope()->GetGlobalJSObject(),
|
||||
&parentObj);
|
||||
wn->GetScope()->GetGlobalJSObject(),
|
||||
parentObj.address());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
MOZ_ASSERT(IsDOMObject(obj));
|
||||
@ -1730,7 +1731,7 @@ RescueOrphans(XPCCallContext& ccx, JSObject* obj)
|
||||
|
||||
// We've been orphaned. Find where our parent went, and follow it.
|
||||
if (isWN) {
|
||||
JSObject *realParent = js::UncheckedUnwrap(parentObj);
|
||||
RootedObject realParent(ccx, js::UncheckedUnwrap(parentObj));
|
||||
XPCWrappedNative *wn =
|
||||
static_cast<XPCWrappedNative*>(js::GetObjectPrivate(obj));
|
||||
return wn->ReparentWrapperIfFound(ccx, GetObjectScope(parentObj),
|
||||
@ -1748,7 +1749,8 @@ RescueOrphans(XPCCallContext& ccx, JSObject* obj)
|
||||
nsresult
|
||||
XPCWrappedNative::RescueOrphans(XPCCallContext& ccx)
|
||||
{
|
||||
return ::RescueOrphans(ccx, mFlatJSObject);
|
||||
RootedObject flatJSObject(ccx, mFlatJSObject);
|
||||
return ::RescueOrphans(ccx, flatJSObject);
|
||||
}
|
||||
|
||||
JSBool
|
||||
@ -1933,8 +1935,8 @@ XPCWrappedNative::InitTearOff(XPCCallContext& ccx,
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS(do_QueryInterface(obj));
|
||||
if (wrappedJS) {
|
||||
JSObject* jso = nullptr;
|
||||
if (NS_SUCCEEDED(wrappedJS->GetJSObject(&jso)) &&
|
||||
RootedObject jso(ccx);
|
||||
if (NS_SUCCEEDED(wrappedJS->GetJSObject(jso.address())) &&
|
||||
jso == mFlatJSObject) {
|
||||
// The implementing JSObject is the same as ours! Just say OK
|
||||
// without actually extending the set.
|
||||
@ -2000,8 +2002,8 @@ XPCWrappedNative::InitTearOff(XPCCallContext& ccx,
|
||||
if (iid->Equals(NS_GET_IID(nsIPropertyBag)) && jso &&
|
||||
NS_SUCCEEDED(nsXPCWrappedJSClass::GetNewOrUsed(ccx,*iid,&clazz))&&
|
||||
clazz) {
|
||||
JSObject* answer =
|
||||
clazz->CallQueryInterfaceOnJSObject(ccx, jso, *iid);
|
||||
RootedObject answer(ccx,
|
||||
clazz->CallQueryInterfaceOnJSObject(ccx, jso, *iid));
|
||||
NS_RELEASE(clazz);
|
||||
if (!answer) {
|
||||
NS_RELEASE(obj);
|
||||
@ -2064,7 +2066,7 @@ JSObject*
|
||||
XPCWrappedNative::GetSameCompartmentSecurityWrapper(JSContext *cx)
|
||||
{
|
||||
// Grab the current state of affairs.
|
||||
JSObject *flat = GetFlatJSObject();
|
||||
RootedObject flat(cx, GetFlatJSObject());
|
||||
JSObject *wrapper = GetWrapper();
|
||||
|
||||
// If we already have a wrapper, it must be what we want.
|
||||
@ -2438,8 +2440,8 @@ CallMethodHelper::GatherAndConvertResults()
|
||||
|
||||
const nsXPTType& type = paramInfo.GetType();
|
||||
nsXPTCVariant* dp = GetDispatchParam(i);
|
||||
jsval v = JSVAL_NULL;
|
||||
AUTO_MARK_JSVAL(mCallContext, &v);
|
||||
RootedValue v(mCallContext, NullValue());
|
||||
AUTO_MARK_JSVAL(mCallContext, v.address());
|
||||
uint32_t array_count = 0;
|
||||
nsXPTType datum_type;
|
||||
bool isArray = type.IsArray();
|
||||
@ -2470,7 +2472,7 @@ CallMethodHelper::GatherAndConvertResults()
|
||||
nsresult err;
|
||||
if (isArray) {
|
||||
XPCLazyCallContext lccx(mCallContext);
|
||||
if (!XPCConvert::NativeArray2JS(lccx, &v, (const void**)&dp->val,
|
||||
if (!XPCConvert::NativeArray2JS(lccx, v.address(), (const void**)&dp->val,
|
||||
datum_type, ¶m_iid,
|
||||
array_count, &err)) {
|
||||
// XXX need exception scheme for arrays to indicate bad element
|
||||
@ -2478,7 +2480,7 @@ CallMethodHelper::GatherAndConvertResults()
|
||||
return false;
|
||||
}
|
||||
} else if (isSizedString) {
|
||||
if (!XPCConvert::NativeStringWithSize2JS(mCallContext, &v,
|
||||
if (!XPCConvert::NativeStringWithSize2JS(mCallContext, v.address(),
|
||||
(const void*)&dp->val,
|
||||
datum_type,
|
||||
array_count, &err)) {
|
||||
@ -2486,7 +2488,7 @@ CallMethodHelper::GatherAndConvertResults()
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!XPCConvert::NativeData2JS(mCallContext, &v, &dp->val, datum_type,
|
||||
if (!XPCConvert::NativeData2JS(mCallContext, v.address(), &dp->val, datum_type,
|
||||
¶m_iid, &err)) {
|
||||
ThrowBadParam(err, i, mCallContext);
|
||||
return false;
|
||||
@ -2500,7 +2502,7 @@ CallMethodHelper::GatherAndConvertResults()
|
||||
NS_ASSERTION(mArgv[i].isObject(), "out var is not object");
|
||||
if (!JS_SetPropertyById(mCallContext,
|
||||
&mArgv[i].toObject(),
|
||||
mIdxValueId, &v)) {
|
||||
mIdxValueId, v.address())) {
|
||||
ThrowBadParam(NS_ERROR_XPC_CANT_SET_OUT_VAL, i, mCallContext);
|
||||
return false;
|
||||
}
|
||||
@ -2523,7 +2525,7 @@ CallMethodHelper::QueryInterfaceFastPath() const
|
||||
Throw(NS_ERROR_XPC_NOT_ENOUGH_ARGS, mCallContext);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!mArgv[0].isObject()) {
|
||||
ThrowBadParam(NS_ERROR_XPC_BAD_CONVERT_JS, 0, mCallContext);
|
||||
return false;
|
||||
@ -2546,10 +2548,10 @@ CallMethodHelper::QueryInterfaceFastPath() const
|
||||
return false;
|
||||
}
|
||||
|
||||
jsval v = JSVAL_NULL;
|
||||
RootedValue v(mCallContext, NullValue());
|
||||
nsresult err;
|
||||
JSBool success =
|
||||
XPCConvert::NativeData2JS(mCallContext, &v, &qiresult,
|
||||
XPCConvert::NativeData2JS(mCallContext, v.address(), &qiresult,
|
||||
nsXPTType::T_INTERFACE_IS,
|
||||
iid, &err);
|
||||
NS_IF_RELEASE(qiresult);
|
||||
@ -2680,8 +2682,8 @@ CallMethodHelper::ConvertIndependentParam(uint8_t i)
|
||||
// we want to know before the call, rather than after.
|
||||
//
|
||||
// This is a no-op for 'in' params.
|
||||
jsval src;
|
||||
if (!GetOutParamSource(i, &src))
|
||||
RootedValue src(mCallContext);
|
||||
if (!GetOutParamSource(i, src.address()))
|
||||
return false;
|
||||
|
||||
// All that's left to do is value conversion. Bail early if we don't need
|
||||
@ -2786,8 +2788,8 @@ CallMethodHelper::ConvertDependentParam(uint8_t i)
|
||||
// we want to know before the call, rather than after.
|
||||
//
|
||||
// This is a no-op for 'in' params.
|
||||
jsval src;
|
||||
if (!GetOutParamSource(i, &src))
|
||||
RootedValue src(mCallContext);
|
||||
if (!GetOutParamSource(i, src.address()))
|
||||
return false;
|
||||
|
||||
// All that's left to do is value conversion. Bail early if we don't need
|
||||
@ -3598,7 +3600,7 @@ XPCJSObjectHolder::newHolder(XPCCallContext& ccx, JSObject* obj)
|
||||
}
|
||||
|
||||
JSBool
|
||||
MorphSlimWrapper(JSContext *cx, JSObject *obj)
|
||||
MorphSlimWrapper(JSContext *cx, HandleObject obj)
|
||||
{
|
||||
SLIM_LOG(("***** morphing from MorphSlimToWrapper (%p, %p)\n",
|
||||
obj, static_cast<nsISupports*>(xpc_GetJSPrivate(obj))));
|
||||
@ -3636,7 +3638,7 @@ ConstructSlimWrapper(XPCCallContext &ccx,
|
||||
NS_ASSERTION(flags.DontAskInstanceForScriptable(),
|
||||
"Not supported for cached wrappers!");
|
||||
|
||||
JSObject* parent = xpcScope->GetGlobalJSObject();
|
||||
RootedObject parent(ccx, xpcScope->GetGlobalJSObject());
|
||||
if (!flags.WantPreCreate()) {
|
||||
SLIM_LOG_NOT_CREATED(ccx, identityObj,
|
||||
"scriptable helper has no PreCreate hook");
|
||||
@ -3647,8 +3649,8 @@ ConstructSlimWrapper(XPCCallContext &ccx,
|
||||
// PreCreate may touch dead compartments.
|
||||
js::AutoMaybeTouchDeadZones agc(parent);
|
||||
|
||||
JSObject* plannedParent = parent;
|
||||
nsresult rv = classInfoHelper->PreCreate(identityObj, ccx, parent, &parent);
|
||||
RootedObject plannedParent(ccx, parent);
|
||||
nsresult rv = classInfoHelper->PreCreate(identityObj, ccx, parent, parent.address());
|
||||
if (rv != NS_SUCCESS_ALLOW_SLIM_WRAPPERS) {
|
||||
SLIM_LOG_NOT_CREATED(ccx, identityObj, "PreCreate hook refused");
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
using namespace JS;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// XPCNativeMember
|
||||
@ -30,7 +32,7 @@ XPCNativeMember::GetCallInfo(JSObject* funobj,
|
||||
|
||||
JSBool
|
||||
XPCNativeMember::NewFunctionObject(XPCCallContext& ccx,
|
||||
XPCNativeInterface* iface, JSObject *parent,
|
||||
XPCNativeInterface* iface, HandleObject parent,
|
||||
jsval* pval)
|
||||
{
|
||||
NS_ASSERTION(!IsConstant(),
|
||||
@ -41,7 +43,7 @@ XPCNativeMember::NewFunctionObject(XPCCallContext& ccx,
|
||||
|
||||
JSBool
|
||||
XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
|
||||
JSObject *parent, jsval *vp)
|
||||
HandleObject parent, jsval *vp)
|
||||
{
|
||||
if (IsConstant()) {
|
||||
const nsXPTConstant* constant;
|
||||
@ -56,9 +58,9 @@ XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
|
||||
v.type = constant->GetType();
|
||||
memcpy(&v.val, &mv.val, sizeof(mv.val));
|
||||
|
||||
jsval resultVal;
|
||||
RootedValue resultVal(ccx);
|
||||
|
||||
if (!XPCConvert::NativeData2JS(ccx, &resultVal, &v.val, v.type,
|
||||
if (!XPCConvert::NativeData2JS(ccx, resultVal.address(), &v.val, v.type,
|
||||
nullptr, nullptr))
|
||||
return false;
|
||||
|
||||
@ -230,9 +232,8 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
|
||||
uint16_t totalCount;
|
||||
uint16_t realTotalCount = 0;
|
||||
XPCNativeMember* cur;
|
||||
JSString* str = NULL;
|
||||
jsid name;
|
||||
jsid interfaceName;
|
||||
RootedString str(ccx);
|
||||
RootedId interfaceName(ccx);
|
||||
|
||||
// XXX Investigate lazy init? This is a problem given the
|
||||
// 'placement new' scheme - we need to at least know how big to make
|
||||
@ -290,7 +291,7 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
name = INTERNED_STRING_TO_JSID(ccx, str);
|
||||
jsid name = INTERNED_STRING_TO_JSID(ccx, str);
|
||||
|
||||
if (info->IsSetter()) {
|
||||
NS_ASSERTION(realTotalCount,"bad setter");
|
||||
@ -327,7 +328,7 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
name = INTERNED_STRING_TO_JSID(ccx, str);
|
||||
jsid name = INTERNED_STRING_TO_JSID(ccx, str);
|
||||
|
||||
// XXX need better way to find dups
|
||||
//NS_ASSERTION(!LookupMemberByID(name),"duplicate method/constant name");
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace JS;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// All of the exceptions thrown into JS from this file go through here.
|
||||
@ -140,19 +142,19 @@ XPC_WN_Shared_ToSource(JSContext *cx, unsigned argc, jsval *vp)
|
||||
static JSObject*
|
||||
GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper)
|
||||
{
|
||||
JSObject* obj = nullptr;
|
||||
RootedObject obj(ccx);
|
||||
nsCOMPtr<nsIXPConnectWrappedJS>
|
||||
underware = do_QueryInterface(wrapper->GetIdentityObject());
|
||||
if (underware) {
|
||||
JSObject* mainObj = nullptr;
|
||||
if (NS_SUCCEEDED(underware->GetJSObject(&mainObj)) && mainObj) {
|
||||
jsid id = ccx.GetRuntime()->
|
||||
GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT);
|
||||
RootedObject mainObj(ccx);
|
||||
if (NS_SUCCEEDED(underware->GetJSObject(mainObj.address())) && mainObj) {
|
||||
RootedId id(ccx, ccx.GetRuntime()->
|
||||
GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT));
|
||||
|
||||
JSAutoCompartment ac(ccx, mainObj);
|
||||
|
||||
jsval val;
|
||||
if (JS_GetPropertyById(ccx, mainObj, id, &val) &&
|
||||
RootedValue val(ccx);
|
||||
if (JS_GetPropertyById(ccx, mainObj, id, val.address()) &&
|
||||
!JSVAL_IS_PRIMITIVE(val)) {
|
||||
obj = JSVAL_TO_OBJECT(val);
|
||||
}
|
||||
@ -167,7 +169,7 @@ GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper)
|
||||
static JSBool
|
||||
XPC_WN_DoubleWrappedGetter(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
@ -178,7 +180,7 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
NS_ASSERTION(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
|
||||
|
||||
JSObject* realObject = GetDoubleWrappedJSObject(ccx, wrapper);
|
||||
RootedObject realObject(cx, GetDoubleWrappedJSObject(ccx, wrapper));
|
||||
if (!realObject) {
|
||||
// This is pretty unexpected at this point. The object originally
|
||||
// responded to this get property call and now gives no object.
|
||||
@ -232,7 +234,8 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
static JSBool
|
||||
DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
JSObject *obj, jsid id,
|
||||
HandleObject obj,
|
||||
HandleId idArg,
|
||||
XPCNativeSet* set,
|
||||
XPCNativeInterface* iface,
|
||||
XPCNativeMember* member,
|
||||
@ -244,6 +247,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
unsigned propFlags,
|
||||
JSBool* resolved)
|
||||
{
|
||||
RootedId id(ccx, idArg);
|
||||
XPCJSRuntime* rt = ccx.GetRuntime();
|
||||
JSBool found;
|
||||
const char* name;
|
||||
@ -291,7 +295,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
call = nullptr;
|
||||
|
||||
if (call) {
|
||||
JSFunction* fun = JS_NewFunction(ccx, call, 0, 0, obj, name);
|
||||
RootedFunction fun(ccx, JS_NewFunction(ccx, call, 0, 0, obj, name));
|
||||
if (!fun) {
|
||||
JS_ReportOutOfMemory(ccx);
|
||||
return false;
|
||||
@ -315,7 +319,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
JSAutoByteString name;
|
||||
AutoMarkingNativeInterfacePtr iface2(ccx);
|
||||
XPCWrappedNativeTearOff* to;
|
||||
JSObject* jso;
|
||||
RootedObject jso(ccx);
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (JSID_IS_STRING(id) &&
|
||||
@ -355,7 +359,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
if (!fun)
|
||||
return false;
|
||||
|
||||
JSObject* funobj = JS_GetFunctionObject(fun);
|
||||
RootedObject funobj(ccx, JS_GetFunctionObject(fun));
|
||||
if (!funobj)
|
||||
return false;
|
||||
|
||||
@ -367,7 +371,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
*resolved = true;
|
||||
return JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
|
||||
JS_DATA_TO_FUNC_PTR(JSPropertyOp,
|
||||
funobj),
|
||||
funobj.get()),
|
||||
nullptr, propFlags);
|
||||
}
|
||||
|
||||
@ -383,7 +387,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
|
||||
if (!to)
|
||||
return false;
|
||||
JSObject* jso = to->GetJSObject();
|
||||
RootedObject jso(ccx, to->GetJSObject());
|
||||
if (!jso)
|
||||
return false;
|
||||
|
||||
@ -400,11 +404,11 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
}
|
||||
|
||||
if (member->IsConstant()) {
|
||||
jsval val;
|
||||
RootedValue val(ccx);
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
*resolved = true;
|
||||
return member->GetConstantValue(ccx, iface, &val) &&
|
||||
return member->GetConstantValue(ccx, iface, val.address()) &&
|
||||
JS_DefinePropertyById(ccx, obj, id, val, nullptr, nullptr,
|
||||
propFlags);
|
||||
}
|
||||
@ -416,8 +420,8 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
id == rt->GetStringID(XPCJSRuntime::IDX_QUERY_INTERFACE)))
|
||||
propFlags &= ~JSPROP_ENUMERATE;
|
||||
|
||||
jsval funval;
|
||||
if (!member->NewFunctionObject(ccx, iface, obj, &funval))
|
||||
RootedValue funval(ccx);
|
||||
if (!member->NewFunctionObject(ccx, iface, obj, funval.address()))
|
||||
return false;
|
||||
|
||||
// protect funobj until it is actually attached
|
||||
@ -731,9 +735,9 @@ XPC_WN_OuterObject(JSContext *cx, JSHandleObject obj_)
|
||||
|
||||
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
|
||||
if (si && si->GetFlags().WantOuterObject()) {
|
||||
JSObject *newThis;
|
||||
RootedObject newThis(cx);
|
||||
nsresult rv =
|
||||
si->GetCallback()->OuterObject(wrapper, cx, obj, &newThis);
|
||||
si->GetCallback()->OuterObject(wrapper, cx, obj, newThis.address());
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
Throw(rv, cx);
|
||||
@ -934,7 +938,7 @@ static JSBool
|
||||
XPC_WN_Helper_Call(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
// N.B. we want obj to be the callee, not JS_THIS(cx, vp)
|
||||
JSObject *obj = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
|
||||
RootedObject obj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
|
||||
XPCCallContext ccx(JS_CALLER, cx, obj, nullptr, JSID_VOID,
|
||||
argc, JS_ARGV(cx, vp), vp);
|
||||
@ -952,7 +956,7 @@ XPC_WN_Helper_Call(JSContext *cx, unsigned argc, jsval *vp)
|
||||
static JSBool
|
||||
XPC_WN_Helper_Construct(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
|
||||
RootedObject obj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
@ -992,7 +996,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsig
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
bool retval = true;
|
||||
JSObject* obj2FromScriptable = nullptr;
|
||||
RootedObject obj2FromScriptable(cx);
|
||||
if (IS_SLIM_WRAPPER(obj)) {
|
||||
XPCNativeScriptableInfo *si =
|
||||
GetSlimWrapperProto(obj)->GetScriptableInfo();
|
||||
@ -1004,7 +1008,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsig
|
||||
"We don't support these flags for slim wrappers!");
|
||||
|
||||
rv = si->GetCallback()->NewResolve(nullptr, cx, obj, id, flags,
|
||||
&obj2FromScriptable, &retval);
|
||||
obj2FromScriptable.address(), &retval);
|
||||
if (NS_FAILED(rv))
|
||||
return Throw(rv, cx);
|
||||
|
||||
@ -1018,7 +1022,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsig
|
||||
XPCWrappedNative* wrapper = ccx.GetWrapper();
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
jsid old = ccx.SetResolveName(id);
|
||||
RootedId old(cx, ccx.SetResolveName(id));
|
||||
|
||||
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
|
||||
if (si && si->GetFlags().WantNewResolve()) {
|
||||
@ -1029,7 +1033,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsig
|
||||
oldResolvingWrapper = ccx.SetResolvingWrapper(wrapper);
|
||||
|
||||
rv = si->GetCallback()->NewResolve(wrapper, cx, obj, id, flags,
|
||||
&obj2FromScriptable, &retval);
|
||||
obj2FromScriptable.address(), &retval);
|
||||
|
||||
if (allowPropMods)
|
||||
(void)ccx.SetResolvingWrapper(oldResolvingWrapper);
|
||||
@ -1427,9 +1431,9 @@ JSBool
|
||||
XPC_WN_CallMethod(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
NS_ASSERTION(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
|
||||
JSObject* funobj = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
|
||||
RootedObject funobj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
|
||||
JSObject* obj = JS_THIS_OBJECT(cx, vp);
|
||||
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
@ -1463,9 +1467,9 @@ JSBool
|
||||
XPC_WN_GetterSetter(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
NS_ASSERTION(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
|
||||
JSObject* funobj = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
|
||||
RootedObject funobj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
|
||||
JSObject* obj = JS_THIS_OBJECT(cx, vp);
|
||||
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
|
@ -1137,7 +1137,7 @@ xpc_MorphSlimWrapper(JSContext *cx, nsISupports *tomorph)
|
||||
if (!cache)
|
||||
return NS_OK;
|
||||
|
||||
JSObject *obj = cache->GetWrapper();
|
||||
JS::RootedObject obj(cx, cache->GetWrapper());
|
||||
if (!obj || !IS_SLIM_WRAPPER(obj))
|
||||
return NS_OK;
|
||||
NS_ENSURE_STATE(MorphSlimWrapper(cx, obj));
|
||||
@ -1408,8 +1408,9 @@ nsXPConnect::ReparentWrappedNativeIfFound(JSContext * aJSContext,
|
||||
if (!scope || !scope2)
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
JS::RootedObject newParent(ccx, aNewParent);
|
||||
return XPCWrappedNative::
|
||||
ReparentWrapperIfFound(ccx, scope, scope2, aNewParent,
|
||||
ReparentWrapperIfFound(ccx, scope, scope2, newParent,
|
||||
aCOMObj);
|
||||
}
|
||||
|
||||
|
@ -1786,10 +1786,10 @@ public:
|
||||
jsval* pval)
|
||||
{NS_ASSERTION(IsConstant(),
|
||||
"Only call this if you're sure this is a constant!");
|
||||
return Resolve(ccx, iface, nullptr, pval);}
|
||||
return Resolve(ccx, iface, JS::NullPtr(), pval);}
|
||||
|
||||
JSBool NewFunctionObject(XPCCallContext& ccx, XPCNativeInterface* iface,
|
||||
JSObject *parent, jsval* pval);
|
||||
JS::HandleObject parent, jsval* pval);
|
||||
|
||||
JSBool IsMethod() const
|
||||
{return 0 != (mFlags & METHOD);}
|
||||
@ -1827,7 +1827,7 @@ public:
|
||||
|
||||
private:
|
||||
JSBool Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
|
||||
JSObject *parent, jsval *vp);
|
||||
JS::HandleObject parent, jsval *vp);
|
||||
|
||||
enum {
|
||||
METHOD = 0x01,
|
||||
@ -2521,7 +2521,7 @@ extern JSBool ConstructSlimWrapper(XPCCallContext &ccx,
|
||||
xpcObjectHelper &aHelper,
|
||||
XPCWrappedNativeScope* xpcScope,
|
||||
jsval *rval);
|
||||
extern JSBool MorphSlimWrapper(JSContext *cx, JSObject *obj);
|
||||
extern JSBool MorphSlimWrapper(JSContext *cx, JS::HandleObject obj);
|
||||
|
||||
/***********************************************/
|
||||
// XPCWrappedNativeTearOff represents the info needed to make calls to one
|
||||
@ -2759,7 +2759,7 @@ public:
|
||||
|
||||
static nsresult
|
||||
Morph(XPCCallContext& ccx,
|
||||
JSObject* existingJSObject,
|
||||
JS::HandleObject existingJSObject,
|
||||
XPCNativeInterface* Interface,
|
||||
nsWrapperCache *cache,
|
||||
XPCWrappedNative** resultWrapper);
|
||||
@ -2773,8 +2773,9 @@ public:
|
||||
XPCWrappedNative** wrapper);
|
||||
|
||||
static XPCWrappedNative*
|
||||
GetAndMorphWrappedNativeOfJSObject(JSContext* cx, JSObject* obj)
|
||||
GetAndMorphWrappedNativeOfJSObject(JSContext* cx, JSObject* obj_)
|
||||
{
|
||||
JS::RootedObject obj(cx, obj_);
|
||||
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
@ -2791,7 +2792,7 @@ public:
|
||||
ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
XPCWrappedNativeScope* aOldScope,
|
||||
XPCWrappedNativeScope* aNewScope,
|
||||
JSObject* aNewParent,
|
||||
JS::HandleObject aNewParent,
|
||||
nsISupports* aCOMObj);
|
||||
|
||||
nsresult RescueOrphans(XPCCallContext& ccx);
|
||||
@ -2963,7 +2964,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
JSBool Init(XPCCallContext& ccx, JSObject* parent, const XPCNativeScriptableCreateInfo* sci);
|
||||
JSBool Init(XPCCallContext& ccx, JS::HandleObject parent, const XPCNativeScriptableCreateInfo* sci);
|
||||
JSBool Init(XPCCallContext &ccx, JSObject *existingJSObject);
|
||||
JSBool FinishInit(XPCCallContext &ccx);
|
||||
|
||||
@ -3837,9 +3838,9 @@ class MOZ_STACK_CLASS AutoResolveName
|
||||
public:
|
||||
AutoResolveName(XPCCallContext& ccx, jsid name
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
||||
mOld(XPCJSRuntime::Get()->SetResolveName(name))
|
||||
mOld(ccx, XPCJSRuntime::Get()->SetResolveName(name))
|
||||
#ifdef DEBUG
|
||||
,mCheck(name)
|
||||
,mCheck(ccx, name)
|
||||
#endif
|
||||
{
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
@ -3854,9 +3855,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
jsid mOld;
|
||||
JS::RootedId mOld;
|
||||
#ifdef DEBUG
|
||||
jsid mCheck;
|
||||
JS::RootedId mCheck;
|
||||
#endif
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
@ -124,8 +124,9 @@ WrapperFactory::DoubleWrap(JSContext *cx, JSObject *obj, unsigned flags)
|
||||
}
|
||||
|
||||
JSObject *
|
||||
WrapperFactory::PrepareForWrapping(JSContext *cx, JSObject *scope, JSObject *obj, unsigned flags)
|
||||
WrapperFactory::PrepareForWrapping(JSContext *cx, JSObject *scope, JSObject *obj_, unsigned flags)
|
||||
{
|
||||
JS::RootedObject obj(cx, obj_);
|
||||
// Outerize any raw inner objects at the entry point here, so that we don't
|
||||
// have to worry about them for the rest of the wrapping code.
|
||||
if (js::IsInnerObject(obj)) {
|
||||
|
Loading…
Reference in New Issue
Block a user