Backed out changeset 76f7d7963692 (bug 861912) for debug mochitest b-c orange.

This commit is contained in:
Ryan VanderMeulen 2013-04-16 11:51:49 -04:00
parent fdd94e62db
commit 8b4107f38d
6 changed files with 62 additions and 17 deletions

View File

@ -29,7 +29,6 @@
using namespace xpc;
using namespace mozilla;
using namespace mozilla::dom;
using namespace JS;
//#define STRICT_CHECK_OF_UNICODE
#ifdef STRICT_CHECK_OF_UNICODE
@ -170,7 +169,7 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
nsID* iid2 = *((nsID**)s);
if (!iid2)
break;
RootedObject scope(cx, lccx.GetScopeForNewJSObjects());
JS::RootedObject scope(cx, lccx.GetScopeForNewJSObjects());
JSObject* obj;
if (!(obj = xpc_NewIDObject(cx, scope, *iid2)))
return false;
@ -831,7 +830,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
nsWrapperCache *cache = aHelper.GetWrapperCache();
bool tryConstructSlimWrapper = false;
RootedObject flat(cx);
JS::RootedObject flat(cx);
if (cache) {
flat = cache->GetWrapper();
if (cache->IsDOMBinding()) {
@ -1154,7 +1153,7 @@ public:
private:
JSContext * const mContext;
AutoValueRooter tvr;
JS::AutoValueRooter tvr;
};
// static
@ -1412,26 +1411,29 @@ XPCConvert::NativeArray2JS(XPCLazyCallContext& lccx,
// XXX add support to indicate *which* array element was not convertable
RootedObject array(cx, JS_NewArrayObject(cx, count, nullptr));
JSObject *array = JS_NewArrayObject(cx, count, nullptr);
if (!array)
return false;
// root this early
*d = OBJECT_TO_JSVAL(array);
AUTO_MARK_JSVAL(ccx, d);
if (pErr)
*pErr = NS_ERROR_XPC_BAD_CONVERT_NATIVE;
uint32_t i;
RootedValue current(cx, JSVAL_NULL);
jsval current = JSVAL_NULL;
AUTO_MARK_JSVAL(ccx, &current);
#define POPULATE(_t) \
PR_BEGIN_MACRO \
for (i = 0; i < count; i++) { \
if (!NativeData2JS(ccx, current.address(), ((_t*)*s)+i, type, iid, pErr) || \
!JS_SetElement(cx, array, i, current.address())) \
goto failure; \
} \
#define POPULATE(_t) \
PR_BEGIN_MACRO \
for (i = 0; i < count; i++) { \
if (!NativeData2JS(ccx, &current, ((_t*)*s)+i, type, iid, pErr) ||\
!JS_SetElement(cx, array, i, &current)) \
goto failure; \
} \
PR_END_MACRO
// XXX check IsPtr - esp. to handle array of nsID (as opposed to nsID*)

View File

@ -232,6 +232,9 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx,
if (!JS_GetPropertyById(cx, jsobj, funid, fun.address()) || JSVAL_IS_PRIMITIVE(fun))
return nullptr;
// protect fun so that we're sure it's alive when we call it
AUTO_MARK_JSVAL(cx, fun);
// Ensure that we are asking for a scriptable interface.
// NB: It's important for security that this check is here rather
// than later, since it prevents untrusted objects from implementing
@ -268,6 +271,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx,
"JS failed without setting an exception!");
RootedValue jsexception(cx, NullValue());
AUTO_MARK_JSVAL(cx, jsexception.address());
if (JS_GetPendingException(cx, jsexception.address())) {
nsresult rv;
@ -712,9 +716,12 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
}
// check if the JSObject claims to implement this interface
RootedObject jsobj(ccx, CallQueryInterfaceOnJSObject(ccx, self->GetJSObject(),
aIID));
JSObject* jsobj = CallQueryInterfaceOnJSObject(ccx, self->GetJSObject(),
aIID);
if (jsobj) {
// protect jsobj until it is actually attached
AUTO_MARK_JSVAL(ccx, OBJECT_TO_JSVAL(jsobj));
// We can't use XPConvert::JSObject2NativeInterface() here
// since that can find a XPCWrappedNative directly on the
// proto chain, and we don't want that here. We need to find
@ -1284,7 +1291,8 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
nsXPTType datum_type;
uint32_t array_count;
bool isArray = type.IsArray();
RootedValue val(cx, NullValue());
RootedValue val(cx, JSVAL_NULL);
AUTO_MARK_JSVAL(ccx, val.address());
bool isSizedString = isArray ?
false :
type.TagPart() == nsXPTType::T_PSTRING_SIZE_IS ||

View File

@ -503,7 +503,9 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
RootedObject parent(ccx, Scope->GetGlobalJSObject());
RootedValue newParentVal(ccx, JSVAL_NULL);
jsval newParentVal = JSVAL_NULL;
XPCMarkableJSVal newParentVal_markable(&newParentVal);
AutoMarkingJSVal newParentVal_automarker(ccx, &newParentVal_markable);
JSBool needsSOW = false;
JSBool needsCOW = false;
@ -2439,6 +2441,7 @@ CallMethodHelper::GatherAndConvertResults()
const nsXPTType& type = paramInfo.GetType();
nsXPTCVariant* dp = GetDispatchParam(i);
RootedValue v(mCallContext, NullValue());
AUTO_MARK_JSVAL(mCallContext, v.address());
uint32_t array_count = 0;
nsXPTType datum_type;
bool isArray = type.IsArray();

View File

@ -424,6 +424,9 @@ DefinePropertyIfFound(XPCCallContext& ccx,
if (!member->NewFunctionObject(ccx, iface, obj, funval.address()))
return false;
// protect funobj until it is actually attached
AUTO_MARK_JSVAL(ccx, funval);
#ifdef off_DEBUG_jband
{
static int cloneCount = 0;

View File

@ -1593,6 +1593,7 @@ nsXPConnect::CreateSandbox(JSContext *cx, nsIPrincipal *principal,
*_retval = nullptr;
RootedValue rval(cx, JSVAL_VOID);
AUTO_MARK_JSVAL(ccx, rval.address());
SandboxOptions options(cx);
nsresult rv = xpc_CreateSandboxObject(cx, rval.address(), principal, options);

View File

@ -3856,6 +3856,25 @@ private:
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/***************************************************************************/
class XPCMarkableJSVal
{
public:
XPCMarkableJSVal(jsval val) : mVal(val), mValPtr(&mVal) {}
XPCMarkableJSVal(jsval *pval) : mVal(JSVAL_VOID), mValPtr(pval) {}
~XPCMarkableJSVal() {}
void Mark() {}
void TraceJS(JSTracer* trc)
{
JS_CallValueTracer(trc, *mValPtr, "XPCMarkableJSVal");
}
void AutoTrace(JSTracer* trc) {}
private:
XPCMarkableJSVal(); // not implemented
jsval mVal;
jsval* mValPtr;
};
/***************************************************************************/
// AutoMarkingPtr is the base class for the various AutoMarking pointer types
// below. This system allows us to temporarily protect instances of our garbage
@ -3935,6 +3954,7 @@ typedef TypedAutoMarkingPtr<XPCNativeSet> AutoMarkingNativeSetPtr;
typedef TypedAutoMarkingPtr<XPCWrappedNative> AutoMarkingWrappedNativePtr;
typedef TypedAutoMarkingPtr<XPCWrappedNativeTearOff> AutoMarkingWrappedNativeTearOffPtr;
typedef TypedAutoMarkingPtr<XPCWrappedNativeProto> AutoMarkingWrappedNativeProtoPtr;
typedef TypedAutoMarkingPtr<XPCMarkableJSVal> AutoMarkingJSVal;
typedef TypedAutoMarkingPtr<XPCNativeScriptableInfo> AutoMarkingNativeScriptableInfoPtr;
template<class T>
@ -3987,6 +4007,14 @@ class ArrayAutoMarkingPtr : public AutoMarkingPtr
typedef ArrayAutoMarkingPtr<XPCNativeInterface> AutoMarkingNativeInterfacePtrArrayPtr;
#define AUTO_MARK_JSVAL_HELPER2(tok, line) tok##line
#define AUTO_MARK_JSVAL_HELPER(tok, line) AUTO_MARK_JSVAL_HELPER2(tok, line)
#define AUTO_MARK_JSVAL(cx, val) \
XPCMarkableJSVal AUTO_MARK_JSVAL_HELPER(_val_,__LINE__)(val); \
AutoMarkingJSVal AUTO_MARK_JSVAL_HELPER(_automarker_,__LINE__) \
(cx, &AUTO_MARK_JSVAL_HELPER(_val_,__LINE__))
/***************************************************************************/
// Allocates a string that grants all access ("AllAccess")