Bug 910937: Remove xpc_UnmarkGrayObject and use JSAPI directly. r=mccr8

This commit is contained in:
Kyle Huey 2013-09-08 20:28:48 -07:00
parent fde62e307a
commit a53f6f80b6
31 changed files with 129 additions and 76 deletions

View File

@ -89,7 +89,8 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(EventSource)
tmp->mListenerManager->MarkForCC();
}
if (!isBlack && tmp->PreservingWrapper()) {
xpc_UnmarkGrayObject(tmp->GetWrapperPreserveColor());
// This marks the wrapper black.
tmp->GetWrapper();
}
return true;
}

View File

@ -1221,7 +1221,9 @@ void
FragmentOrElement::MarkNodeChildren(nsINode* aNode)
{
JSObject* o = GetJSObjectChild(aNode);
xpc_UnmarkGrayObject(o);
if (o) {
JS::ExposeObjectToActiveJS(o);
}
nsEventListenerManager* elm = aNode->GetListenerManager(false);
if (elm) {

View File

@ -581,7 +581,8 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(WebSocket)
tmp->mListenerManager->MarkForCC();
}
if (!isBlack && tmp->PreservingWrapper()) {
xpc_UnmarkGrayObject(tmp->GetWrapperPreserveColor());
// This marks the wrapper black.
tmp->GetWrapper();
}
return true;
}

View File

@ -446,7 +446,8 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsXMLHttpRequest)
tmp->mListenerManager->MarkForCC();
}
if (!isBlack && tmp->PreservingWrapper()) {
xpc_UnmarkGrayObject(tmp->GetWrapperPreserveColor());
// This marks the wrapper black.
tmp->GetWrapper();
}
return true;
}

View File

@ -14,7 +14,7 @@
#include "nsCycleCollectionParticipant.h"
#include "nsTraceRefcnt.h"
#include "xpcpublic.h"
#include "js/GCAPI.h"
namespace mozilla {
namespace dom {
@ -54,7 +54,7 @@ public:
}
JSObject* GetDataObject() const
{
xpc_UnmarkGrayObject(mData);
JS::ExposeObjectToActiveJS(mData);
return mData;
}

View File

@ -1330,9 +1330,11 @@ nsEventListenerManager::MarkForCC()
nsIJSEventListener* jsl = ls.GetJSListener();
if (jsl) {
if (jsl->GetHandler().HasEventHandler()) {
xpc_UnmarkGrayObject(jsl->GetHandler().Ptr()->Callable());
JS::ExposeObjectToActiveJS(jsl->GetHandler().Ptr()->Callable());
}
if (JSObject* scope = jsl->GetEventScope()) {
JS::ExposeObjectToActiveJS(scope);
}
xpc_UnmarkGrayObject(jsl->GetEventScope());
} else if (ls.mListenerType == eWrappedJSListener) {
xpc_TryUnmarkWrappedGrayObject(ls.mListener.GetXPCOMCallback());
} else if (ls.mListenerType == eWebIDLListener) {

View File

@ -67,7 +67,8 @@ HTMLAllCollection::GetObject(JSContext* aCx, ErrorResult& aRv)
NS_ADDREF(mDocument);
}
return xpc_UnmarkGrayObject(mObject);
JS::ExposeObjectToActiveJS(mObject);
return mObject;
}
} // namespace dom

View File

@ -213,7 +213,9 @@ nsXBLDocGlobalObject::ClearGlobalObjectOwner()
void
nsXBLDocGlobalObject::UnmarkCompilationGlobal()
{
xpc_UnmarkGrayObject(mJSObject);
if (mJSObject) {
JS::ExposeObjectToActiveJS(mJSObject);
}
}
JSObject *
@ -357,7 +359,7 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
static void
UnmarkXBLJSObject(void* aP, const char* aName, void* aClosure)
{
xpc_UnmarkGrayObject(static_cast<JSObject*>(aP));
JS::ExposeObjectToActiveJS(static_cast<JSObject*>(aP));
}
static bool

View File

@ -356,7 +356,7 @@ nsXBLPrototypeHandler::EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
if (pWindow) {
JS::Rooted<JSObject*> cachedHandler(cx, pWindow->GetCachedXBLPrototypeHandler(this));
if (cachedHandler) {
xpc_UnmarkGrayObject(cachedHandler);
JS::ExposeObjectToActiveJS(cachedHandler);
aHandler.set(cachedHandler);
NS_ENSURE_TRUE(aHandler, NS_ERROR_FAILURE);
return NS_OK;

View File

@ -2638,7 +2638,9 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
options.setSourcePolicy(mOutOfLine ? JS::CompileOptions::LAZY_SOURCE
: JS::CompileOptions::SAVE_SOURCE);
JS::RootedObject scope(cx, JS::CurrentGlobalOrNull(cx));
xpc_UnmarkGrayObject(scope);
if (scope) {
JS::ExposeObjectToActiveJS(scope);
}
if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options)) {
if (!JS::CompileOffThread(cx, scope, options,

View File

@ -3668,7 +3668,10 @@ XULDocument::ExecuteScript(nsIScriptContext * aContext,
JSContext *cx = aContext->GetNativeContext();
AutoCxPusher pusher(cx);
JS::Rooted<JSObject*> global(cx, mScriptGlobalObject->GetGlobalJSObject());
xpc_UnmarkGrayObject(global);
// XXXkhuey can this ever be null?
if (global) {
JS::ExposeObjectToActiveJS(global);
}
xpc_UnmarkGrayScript(aScriptObject);
JSAutoCompartment ac(cx, global);
JS::Rooted<JS::Value> unused(cx);

View File

@ -52,7 +52,12 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsXULPDGlobalObject)
JSObject* GetCompilationGlobal();
void UnmarkCompilationGlobal() { xpc_UnmarkGrayObject(mJSObject); }
void UnmarkCompilationGlobal()
{
if (mJSObject) {
JS::ExposeObjectToActiveJS(mJSObject);
}
}
void Destroy();
nsIPrincipal* GetPrincipal();
void ClearGlobalObjectOwner();
@ -730,9 +735,14 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPDGlobalObject)
JSObject *
nsXULPDGlobalObject::GetCompilationGlobal()
{
if (mJSObject || mDestroyed) {
if (mJSObject) {
// We've been initialized before. This is what we get.
return xpc_UnmarkGrayObject(mJSObject);
JS::ExposeObjectToActiveJS(mJSObject);
return mJSObject;
}
if (mDestroyed) {
return nullptr;
}
AutoSafeJSContext cx;

View File

@ -1559,7 +1559,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsGlobalWindow)
static PLDHashOperator
MarkXBLHandlers(nsXBLPrototypeHandler* aKey, JS::Heap<JSObject*>& aData, void* aClosure)
{
xpc_UnmarkGrayObject(aData);
JS::ExposeObjectToActiveJS(aData);
return PL_DHASH_NEXT;
}
@ -2248,13 +2248,13 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
if (aDocument != oldDoc) {
JS::Rooted<JSObject*> obj(cx, currentInner->mJSObject);
xpc_UnmarkGrayObject(obj);
JS::ExposeObjectToActiveJS(obj);
}
// We're reusing the inner window, but this still counts as a navigation,
// so all expandos and such defined on the outer window should go away. Force
// all Xray wrappers to be recomputed.
xpc_UnmarkGrayObject(mJSObject);
JS::ExposeObjectToActiveJS(mJSObject);
if (!JS_RefreshCrossCompartmentWrappers(cx, mJSObject)) {
return NS_ERROR_FAILURE;
}
@ -2359,8 +2359,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
mJSObject = mContext->GetWindowProxy();
SetWrapper(mJSObject);
} else {
JS::Rooted<JSObject*> global(cx,
xpc_UnmarkGrayObject(newInnerWindow->mJSObject));
JS::ExposeObjectToActiveJS(newInnerWindow->mJSObject);
JS::Rooted<JSObject*> global(cx, newInnerWindow->mJSObject);
JS::Rooted<JSObject*> outerObject(cx,
NewOuterWindowProxy(cx, global, thisChrome));
if (!outerObject) {

View File

@ -201,7 +201,12 @@ public:
// Can return null if we already have a handler.
JSObject* GetEventScope() const
{
return xpc_UnmarkGrayObject(mScopeObject);
if (!mScopeObject) {
return nullptr;
}
JS::ExposeObjectToActiveJS(mScopeObject);
return mScopeObject;
}
const nsEventHandler& GetHandler() const

View File

@ -1044,12 +1044,15 @@ nsJSContext::JSObjectFromInterface(nsISupports* aTarget,
NS_ASSERTION(native == targetSupp, "Native should be the target!");
#endif
*aRet = xpc_UnmarkGrayObject(JSVAL_TO_OBJECT(v));
JSObject* obj = v.toObjectOrNull();
if (obj) {
JS::ExposeObjectToActiveJS(obj);
}
*aRet = obj;
return NS_OK;
}
nsresult
nsJSContext::BindCompiledEventHandler(nsISupports* aTarget,
JS::Handle<JSObject*> aScope,
@ -1060,8 +1063,10 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget,
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
NS_PRECONDITION(!aBoundHandler, "Shouldn't already have a bound handler!");
xpc_UnmarkGrayObject(aScope);
xpc_UnmarkGrayObject(aHandler);
if (aScope) {
JS::ExposeObjectToActiveJS(aScope);
}
JS::ExposeObjectToActiveJS(aHandler);
AutoPushJSContext cx(mContext);
// Get the jsobject associated with this target
@ -2602,7 +2607,12 @@ nsJSContext::SetWindowProxy(JS::Handle<JSObject*> aWindowProxy)
JSObject*
nsJSContext::GetWindowProxy()
{
return xpc_UnmarkGrayObject(GetWindowProxyPreserveColor());
JSObject* windowProxy = GetWindowProxyPreserveColor();
if (windowProxy) {
JS::ExposeObjectToActiveJS(windowProxy);
}
return windowProxy;
}
JSObject*

View File

@ -177,7 +177,9 @@ nsJSUtils::CompileFunction(JSContext* aCx,
aOptions.setPrincipals(p);
// Do the junk Gecko is supposed to do before calling into JSAPI.
xpc_UnmarkGrayObject(aTarget);
if (aTarget) {
JS::ExposeObjectToActiveJS(aTarget);
}
// Compile.
JSFunction* fun = JS::CompileFunction(aCx, aTarget, aOptions,
@ -238,7 +240,7 @@ nsJSUtils::EvaluateString(JSContext* aCx,
*aRetValue = JSVAL_VOID;
}
xpc_UnmarkGrayObject(aScopeObject);
JS::ExposeObjectToActiveJS(aScopeObject);
nsAutoMicroTask mt;
JSPrincipals* p = JS_GetCompartmentPrincipals(js::GetObjectCompartment(aScopeObject));

View File

@ -7,13 +7,16 @@
#define nsWrapperCacheInline_h___
#include "nsWrapperCache.h"
#include "xpcpublic.h"
#include "js/GCAPI.h"
#include "jsapi.h"
inline JSObject*
nsWrapperCache::GetWrapper() const
{
JSObject* obj = GetWrapperPreserveColor();
xpc_UnmarkGrayObject(obj);
if (obj) {
JS::ExposeObjectToActiveJS(obj);
}
return obj;
}
@ -21,14 +24,14 @@ inline bool
nsWrapperCache::IsBlack()
{
JSObject* o = GetWrapperPreserveColor();
return o && !xpc_IsGrayGCThing(o);
return o && !JS::GCThingIsMarkedGray(o);
}
static void
SearchGray(void* aGCThing, const char* aName, void* aClosure)
{
bool* hasGrayObjects = static_cast<bool*>(aClosure);
if (!*hasGrayObjects && aGCThing && xpc_IsGrayGCThing(aGCThing)) {
if (!*hasGrayObjects && aGCThing && JS::GCThingIsMarkedGray(aGCThing)) {
*hasGrayObjects = true;
}
}

View File

@ -652,7 +652,7 @@ WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T* value,
JSObject* obj = value->GetWrapperPreserveColor();
bool couldBeDOMBinding = CouldBeDOMBinding(value);
if (obj) {
xpc_UnmarkNonNullGrayObject(obj);
JS::ExposeObjectToActiveJS(obj);
} else {
// Inline this here while we have non-dom objects in wrapper caches.
if (!couldBeDOMBinding) {

View File

@ -106,7 +106,7 @@ CallbackObject::CallSetup::CallSetup(JS::Handle<JSObject*> aCallback,
//
// We can do this even though we're not in the right compartment yet, because
// Rooted<> does not care about compartments.
xpc_UnmarkGrayObject(aCallback);
JS::ExposeObjectToActiveJS(aCallback);
mRootedCallable.construct(cx, aCallback);
// Check that it's ok to run this callback at all.

View File

@ -58,7 +58,7 @@ public:
JS::Handle<JSObject*> Callback() const
{
xpc_UnmarkGrayObject(mCallback);
JS::ExposeObjectToActiveJS(mCallback);
return CallbackPreserveColor();
}

View File

@ -421,7 +421,8 @@ BluetoothAdapter::GetDevices(JSContext* aContext, ErrorResult& aRv)
return JS::NullValue();
}
return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsDeviceAddresses));
JS::ExposeObjectToActiveJS(mJsDeviceAddresses);
return JS::ObjectValue(*mJsDeviceAddresses);
}
JS::Value
@ -433,7 +434,8 @@ BluetoothAdapter::GetUuids(JSContext* aContext, ErrorResult& aRv)
return JS::NullValue();
}
return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsUuids));
JS::ExposeObjectToActiveJS(mJsUuids);
return JS::ObjectValue(*mJsUuids);
}
already_AddRefed<DOMRequest>

View File

@ -206,7 +206,8 @@ BluetoothDevice::GetUuids(JSContext* aCx, ErrorResult& aRv)
return JS::NullValue();
}
return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsUuids));
JS::ExposeObjectToActiveJS(mJsUuids);
return JS::ObjectValue(*mJsUuids);
}
JS::Value
@ -218,7 +219,8 @@ BluetoothDevice::GetServices(JSContext* aCx, ErrorResult& aRv)
return JS::Value(JSVAL_NULL);
}
return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsServices));
JS::ExposeObjectToActiveJS(mJsServices);
return JS::ObjectValue(*mJsServices);
}
JSObject*

View File

@ -290,6 +290,12 @@ ExposeValueToActiveJS(const Value &v)
ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind());
}
static JS_ALWAYS_INLINE void
ExposeObjectToActiveJS(JSObject *obj)
{
ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT);
}
} /* namespace JS */
#endif /* js_GCAPI_h */

View File

@ -488,7 +488,9 @@ inline
JSObject* XPCWrappedNativeTearOff::GetJSObject()
{
JSObject *obj = GetJSObjectPreserveColor();
xpc_UnmarkGrayObject(obj);
if (obj) {
JS::ExposeObjectToActiveJS(obj);
}
return obj;
}

View File

@ -246,7 +246,8 @@ nsXPCWrappedJS::GetWeakReference(nsIWeakReference** aInstancePtr)
JSObject*
nsXPCWrappedJS::GetJSObject()
{
return xpc_UnmarkGrayObject(mJSObj);
JS::ExposeObjectToActiveJS(mJSObj);
return mJSObj;
}
static bool

View File

@ -291,7 +291,7 @@ JSObject *GetXBLScope(JSContext *cx, JSObject *contentScopeArg)
JSObject *scope = EnsureCompartmentPrivate(contentScope)->scope->EnsureXBLScope(cx);
NS_ENSURE_TRUE(scope, nullptr); // See bug 858642.
scope = js::UncheckedUnwrap(scope);
xpc_UnmarkGrayObject(scope);
JS::ExposeObjectToActiveJS(scope);
return scope;
}

View File

@ -1300,8 +1300,10 @@ public:
GetComponentsJSObject();
JSObject*
GetGlobalJSObject() const
{return xpc_UnmarkGrayObject(mGlobalJSObject);}
GetGlobalJSObject() const {
JS::ExposeObjectToActiveJS(mGlobalJSObject);
return mGlobalJSObject;
}
JSObject*
GetGlobalJSObjectPreserveColor() const {return mGlobalJSObject;}
@ -2029,7 +2031,10 @@ public:
GetRuntime() const {return mScope->GetRuntime();}
JSObject*
GetJSProtoObject() const {return xpc_UnmarkGrayObject(mJSProtoObject);}
GetJSProtoObject() const {
JS::ExposeObjectToActiveJS(mJSProtoObject);
return mJSProtoObject;
}
nsIClassInfo*
GetClassInfo() const {return mClassInfo;}
@ -2295,8 +2300,10 @@ public:
*/
JSObject*
GetFlatJSObject() const
{xpc_UnmarkGrayObject(mFlatJSObject);
return mFlatJSObject;}
{
JS::ExposeObjectToActiveJS(mFlatJSObject);
return mFlatJSObject;
}
/**
* This getter does not change the color of the JSObject meaning that the
@ -2485,7 +2492,7 @@ public:
{
JSObject* wrapper = GetWrapperPreserveColor();
if (wrapper) {
xpc_UnmarkGrayObject(wrapper);
JS::ExposeObjectToActiveJS(wrapper);
// Call this to unmark mFlatJSObject.
GetFlatJSObject();
}
@ -3571,10 +3578,11 @@ public:
* represents a JSObject. That means that the object is guaranteed to be
* kept alive past the next CC.
*/
jsval GetJSVal() const
{if (!JSVAL_IS_PRIMITIVE(mJSVal))
xpc_UnmarkGrayObject(JSVAL_TO_OBJECT(mJSVal));
return mJSVal;}
jsval GetJSVal() const {
if (!JSVAL_IS_PRIMITIVE(mJSVal))
JS::ExposeObjectToActiveJS(&mJSVal.toObject());
return mJSVal;
}
/**
* This getter does not change the color of the jsval (if it represents a

View File

@ -137,23 +137,6 @@ xpc_IsGrayGCThing(void *thing)
extern bool
xpc_GCThingIsGrayCCThing(void *thing);
// Unmark gray for known-nonnull cases
MOZ_ALWAYS_INLINE void
xpc_UnmarkNonNullGrayObject(JSObject *obj)
{
JS::ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT);
}
// Remove the gray color from the given JSObject and any other objects that can
// be reached through it.
MOZ_ALWAYS_INLINE JSObject *
xpc_UnmarkGrayObject(JSObject *obj)
{
if (obj)
xpc_UnmarkNonNullGrayObject(obj);
return obj;
}
inline JSScript *
xpc_UnmarkGrayScript(JSScript *script)
{

View File

@ -59,7 +59,12 @@ WrapperFactory::GetXrayWaiver(JSObject *obj)
if (!scope->mWaiverWrapperMap)
return NULL;
return xpc_UnmarkGrayObject(scope->mWaiverWrapperMap->Find(obj));
JSObject* xrayWaiver = scope->mWaiverWrapperMap->Find(obj);
if (xrayWaiver)
JS::ExposeObjectToActiveJS(xrayWaiver);
return xrayWaiver;
}
JSObject *

View File

@ -43,10 +43,8 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSAttributeDeclaration, mElement)
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDOMCSSAttributeDeclaration)
if (tmp->mElement && Element::CanSkip(tmp->mElement, true)) {
if (tmp->PreservingWrapper()) {
// Not relying on GetWrapper to unmark us gray because the
// side-effect thing is pretty weird.
JSObject* o = tmp->GetWrapperPreserveColor();
xpc_UnmarkGrayObject(o);
// This marks the wrapper black.
tmp->GetWrapper();
}
return true;
}

View File

@ -51,6 +51,7 @@
#include "nsIDOMCryptoDialogs.h"
#include "nsIFormSigningDialog.h"
#include "nsIContentSecurityPolicy.h"
#include "nsIURI.h"
#include "jsapi.h"
#include "js/OldDebugAPI.h"
#include <ctype.h>