Commit d717a673 authored by Ms2ger's avatar Ms2ger
Browse files

Bug 698420 - Make nsScriptObjectHolder typesafe; r=bz

parent b2b42ad0
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -579,7 +579,7 @@ nsEventListenerManager::CompileEventHandlerInternal(nsListenerStruct *aListenerS
  nsIScriptContext *context = listener->GetEventContext();
  nsCOMPtr<nsIScriptEventHandlerOwner> handlerOwner =
    do_QueryInterface(mTarget);
  nsScriptObjectHolder handler(context);
  nsScriptObjectHolder<JSObject> handler(context);

  if (handlerOwner) {
    result = handlerOwner->GetCompiledEventHandler(aListenerStruct->mTypeAtom,
@@ -699,10 +699,10 @@ nsEventListenerManager::CompileEventHandlerInternal(nsListenerStruct *aListenerS

  if (handler) {
    // Bind it
    nsScriptObjectHolder boundHandler(context);
    nsScriptObjectHolder<JSObject> boundHandler(context);
    context->BindCompiledEventHandler(mTarget, listener->GetEventScope(),
                                      handler.getObject(), boundHandler);
    listener->SetHandler(boundHandler.getObject());
                                      handler.get(), boundHandler);
    listener->SetHandler(boundHandler.get());
  }

  return result;
+6 −6
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget,
  if (!boundContext)
    return NS_OK;

  nsScriptObjectHolder handler(boundContext);
  nsScriptObjectHolder<JSObject> handler(boundContext);
  nsISupports *scriptTarget;

  if (winRoot) {
@@ -321,16 +321,16 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget,

  // Bind it to the bound element
  JSObject* scope = boundGlobal->GetGlobalJSObject();
  nsScriptObjectHolder boundHandler(boundContext);
  nsScriptObjectHolder<JSObject> boundHandler(boundContext);
  rv = boundContext->BindCompiledEventHandler(scriptTarget, scope,
                                              handler.getObject(), boundHandler);
                                              handler.get(), boundHandler);
  NS_ENSURE_SUCCESS(rv, rv);

  // Execute it.
  nsCOMPtr<nsIJSEventListener> eventListener;
  rv = NS_NewJSEventListener(boundContext, scope,
                             scriptTarget, onEventAtom,
                             boundHandler.getObject(),
                             boundHandler.get(),
                             getter_AddRefs(eventListener));
  NS_ENSURE_SUCCESS(rv, rv);

@@ -344,14 +344,14 @@ nsresult
nsXBLPrototypeHandler::EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
                                          nsIScriptContext *aBoundContext,
                                          nsIAtom *aName,
                                          nsScriptObjectHolder &aHandler)
                                          nsScriptObjectHolder<JSObject>& aHandler)
{
  // Check to see if we've already compiled this
  nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(aGlobal);
  if (pWindow) {
    JSObject* cachedHandler = pWindow->GetCachedXBLPrototypeHandler(this);
    if (cachedHandler) {
      aHandler.setObject(cachedHandler);
      aHandler.set(cachedHandler);
      return aHandler ? NS_OK : NS_ERROR_FAILURE;
    }
  }
+1 −1
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ protected:
  nsresult DispatchXULKeyCommand(nsIDOMEvent* aEvent);
  nsresult EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
                              nsIScriptContext *aBoundContext, nsIAtom *aName,
                              nsScriptObjectHolder &aHandler);
                              nsScriptObjectHolder<JSObject>& aHandler);
  static PRInt32 KeyToMask(PRInt32 key);
  
  static PRInt32 kAccelKey;
+9 −9
Original line number Diff line number Diff line
@@ -163,9 +163,9 @@ public:
                                         const nsAString& aBody,
                                         const char* aURL,
                                         PRUint32 aLineNo,
                                         nsScriptObjectHolder &aHandler);
                                         nsScriptObjectHolder<JSObject>& aHandler);
    virtual nsresult GetCompiledEventHandler(nsIAtom *aName,
                                             nsScriptObjectHolder &aHandler);
                                             nsScriptObjectHolder<JSObject>& aHandler);

private:
    nsRefPtr<nsXULElement> mElement;
@@ -718,7 +718,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsScriptEventHandlerOwnerTearoff)
nsresult
nsScriptEventHandlerOwnerTearoff::GetCompiledEventHandler(
                                                nsIAtom *aName,
                                                nsScriptObjectHolder &aHandler)
                                                nsScriptObjectHolder<JSObject>& aHandler)
{
    XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheTests);
    aHandler.drop();
@@ -727,7 +727,7 @@ nsScriptEventHandlerOwnerTearoff::GetCompiledEventHandler(
        mElement->FindPrototypeAttribute(kNameSpaceID_None, aName);
    if (attr) {
        XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheHits);
        aHandler.setObject(attr->mEventHandler);
        aHandler.set(attr->mEventHandler);
    }

    return NS_OK;
@@ -740,7 +740,7 @@ nsScriptEventHandlerOwnerTearoff::CompileEventHandler(
                                                const nsAString& aBody,
                                                const char* aURL,
                                                PRUint32 aLineNo,
                                                nsScriptObjectHolder &aHandler)
                                                nsScriptObjectHolder<JSObject>& aHandler)
{
    nsresult rv;

@@ -809,13 +809,13 @@ nsScriptEventHandlerOwnerTearoff::CompileEventHandler(
            rv = nsContentUtils::HoldScriptObject(aContext->GetScriptTypeID(),
                                                  elem,
                                                  &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode),
                                                  aHandler,
                                                  aHandler.get(),
                                                  elem->mHoldsScriptObject);
            if (NS_FAILED(rv)) return rv;

            elem->mHoldsScriptObject = true;
        }
        attr->mEventHandler = aHandler.getObject();
        attr->mEventHandler = aHandler.get();
    }

    return NS_OK;
@@ -3002,7 +3002,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
                                            mScriptObject.mLangID);
    NS_ASSERTION(context != nsnull, "Have no context for deserialization");
    NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
    nsScriptObjectHolder newScriptObject(context);
    nsScriptObjectHolder<JSScript> newScriptObject(context);
    rv = context->Deserialize(aStream, newScriptObject);
    if (NS_FAILED(rv)) {
        NS_WARNING("Language deseralization failed");
@@ -3138,7 +3138,7 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,

    // Ok, compile it to create a prototype script object!

    nsScriptObjectHolder newScriptObject(context);
    nsScriptObjectHolder<JSScript> newScriptObject(context);
    rv = context->CompileScript(aText,
                                aTextLength,
                                // Use the enclosing document's principal
+2 −2
Original line number Diff line number Diff line
@@ -336,13 +336,13 @@ public:

    void UnlinkJSObjects();

    void Set(nsScriptObjectHolder &aHolder)
    void Set(nsScriptObjectHolder<JSScript>& aHolder)
    {
        NS_ASSERTION(mScriptObject.mLangID == aHolder.getScriptTypeID(),
                     "Wrong language, this will leak the previous object.");

        mScriptObject.mLangID = aHolder.getScriptTypeID();
        Set(aHolder.getScript());
        Set(aHolder.get());
    }
    void Set(JSScript* aObject);

Loading