LCOV - code coverage report
Current view: directory - js/xpconnect/src - XPCInlines.h (source / functions) Found Hit Coverage
Test: app.info Lines: 289 259 89.6 %
Date: 2012-07-07 Functions: 65 61 93.8 %

       1                 : /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: set ts=4 sw=4 et tw=79:
       3                 :  *
       4                 :  * ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is Mozilla Communicator client code, released
      18                 :  * March 31, 1998.
      19                 :  *
      20                 :  * The Initial Developer of the Original Code is
      21                 :  * Netscape Communications Corporation.
      22                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      23                 :  * the Initial Developer. All Rights Reserved.
      24                 :  *
      25                 :  * Contributor(s):
      26                 :  *   John Bandhauer <jband@netscape.com> (original author)
      27                 :  *
      28                 :  * Alternatively, the contents of this file may be used under the terms of
      29                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      30                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      31                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      32                 :  * of those above. If you wish to allow use of your version of this file only
      33                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      34                 :  * use your version of this file under the terms of the MPL, indicate your
      35                 :  * decision by deleting the provisions above and replace them with the notice
      36                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      37                 :  * the provisions above, a recipient may use your version of this file under
      38                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      39                 :  *
      40                 :  * ***** END LICENSE BLOCK ***** */
      41                 : 
      42                 : /* private inline methods (#include'd by xpcprivate.h). */
      43                 : 
      44                 : #ifndef xpcinlines_h___
      45                 : #define xpcinlines_h___
      46                 : 
      47                 : #include "jsfriendapi.h"
      48                 : 
      49                 : /***************************************************************************/
      50                 : bool
      51           18584 : xpc::PtrAndPrincipalHashKey::KeyEquals(const PtrAndPrincipalHashKey* aKey) const
      52                 : {
      53           18584 :     if (aKey->mPtr != mPtr)
      54              24 :         return false;
      55           18560 :     if (aKey->mPrincipal == mPrincipal)
      56           18560 :         return true;
      57                 : 
      58                 :     bool equals;
      59               0 :     if (NS_FAILED(mPrincipal->EqualsIgnoringDomain(aKey->mPrincipal, &equals))) {
      60               0 :         NS_ERROR("we failed, guessing!");
      61               0 :         return false;
      62                 :     }
      63                 : 
      64               0 :     return equals;
      65                 : }
      66                 : 
      67                 : inline void
      68            3465 : XPCJSRuntime::AddVariantRoot(XPCTraceableVariant* variant)
      69                 : {
      70            3465 :     variant->AddToRootSet(GetMapLock(), &mVariantRoots);
      71            3465 : }
      72                 : 
      73                 : inline void
      74          114354 : XPCJSRuntime::AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS)
      75                 : {
      76          114354 :     wrappedJS->AddToRootSet(GetMapLock(), &mWrappedJSRoots);
      77          114354 : }
      78                 : 
      79                 : inline void
      80               0 : XPCJSRuntime::AddObjectHolderRoot(XPCJSObjectHolder* holder)
      81                 : {
      82               0 :     holder->AddToRootSet(GetMapLock(), &mObjectHolderRoots);
      83               0 : }
      84                 : 
      85                 : /***************************************************************************/
      86                 : 
      87                 : inline JSBool
      88         9541346 : XPCCallContext::IsValid() const
      89                 : {
      90         9541346 :     return mState != INIT_FAILED;
      91                 : }
      92                 : 
      93                 : inline nsXPConnect*
      94          361861 : XPCCallContext::GetXPConnect() const
      95                 : {
      96          361861 :     CHECK_STATE(HAVE_CONTEXT);
      97          361861 :     return mXPC;
      98                 : }
      99                 : 
     100                 : inline XPCJSRuntime*
     101        14138260 : XPCCallContext::GetRuntime() const
     102                 : {
     103        14138260 :     CHECK_STATE(HAVE_CONTEXT);
     104        14138260 :     return mXPCContext->GetRuntime();
     105                 : }
     106                 : 
     107                 : inline XPCPerThreadData*
     108        33690547 : XPCCallContext::GetThreadData() const
     109                 : {
     110        33690547 :     CHECK_STATE(HAVE_CONTEXT);
     111        33690547 :     return mThreadData;
     112                 : }
     113                 : 
     114                 : inline XPCContext*
     115        23034386 : XPCCallContext::GetXPCContext() const
     116                 : {
     117        23034386 :     CHECK_STATE(HAVE_CONTEXT);
     118        23034386 :     return mXPCContext;
     119                 : }
     120                 : 
     121                 : inline JSContext*
     122        78985597 : XPCCallContext::GetJSContext() const
     123                 : {
     124        78985597 :     CHECK_STATE(HAVE_CONTEXT);
     125        78985597 :     return mJSContext;
     126                 : }
     127                 : 
     128                 : inline JSBool
     129                 : XPCCallContext::GetContextPopRequired() const
     130                 : {
     131                 :     CHECK_STATE(HAVE_CONTEXT);
     132                 :     return mContextPopRequired;
     133                 : }
     134                 : 
     135                 : inline XPCContext::LangType
     136             395 : XPCCallContext::GetCallerLanguage() const
     137                 : {
     138             395 :     CHECK_STATE(HAVE_CONTEXT);
     139             395 :     return mCallerLanguage;
     140                 : }
     141                 : 
     142                 : inline XPCContext::LangType
     143                 : XPCCallContext::GetPrevCallerLanguage() const
     144                 : {
     145                 :     CHECK_STATE(HAVE_CONTEXT);
     146                 :     return mPrevCallerLanguage;
     147                 : }
     148                 : 
     149                 : inline XPCCallContext*
     150           19991 : XPCCallContext::GetPrevCallContext() const
     151                 : {
     152           19991 :     CHECK_STATE(HAVE_CONTEXT);
     153           19991 :     return mPrevCallContext;
     154                 : }
     155                 : 
     156                 : inline JSObject*
     157         8547439 : XPCCallContext::GetScopeForNewJSObjects() const
     158                 : {
     159         8547439 :     CHECK_STATE(HAVE_SCOPE);
     160         8547439 :     return mScopeForNewJSObjects;
     161                 : }
     162                 : 
     163                 : inline void
     164         3036825 : XPCCallContext::SetScopeForNewJSObjects(JSObject *scope)
     165                 : {
     166         3036825 :     NS_ABORT_IF_FALSE(mState == HAVE_CONTEXT, "wrong call context state");
     167         3036825 :     NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(scope, mJSContext), "wrong compartment");
     168         3036825 :     mScopeForNewJSObjects = scope;
     169         3036825 :     mState = HAVE_SCOPE;
     170         3036825 : }
     171                 : 
     172                 : inline JSObject*
     173         6820236 : XPCCallContext::GetFlattenedJSObject() const
     174                 : {
     175         6820236 :     CHECK_STATE(HAVE_OBJECT);
     176         6820236 :     return mFlattenedJSObject;
     177                 : }
     178                 : 
     179                 : inline nsISupports*
     180             596 : XPCCallContext::GetIdentityObject() const
     181                 : {
     182             596 :     CHECK_STATE(HAVE_OBJECT);
     183             596 :     if (mWrapper)
     184             596 :         return mWrapper->GetIdentityObject();
     185                 :     return mFlattenedJSObject ?
     186               0 :            static_cast<nsISupports*>(xpc_GetJSPrivate(mFlattenedJSObject)) :
     187               0 :            nsnull;
     188                 : }
     189                 : 
     190                 : inline XPCWrappedNative*
     191        38807721 : XPCCallContext::GetWrapper() const
     192                 : {
     193        38807721 :     if (mState == INIT_FAILED)
     194               0 :         return nsnull;
     195                 : 
     196        38807721 :     CHECK_STATE(HAVE_OBJECT);
     197        38807721 :     return mWrapper;
     198                 : }
     199                 : 
     200                 : inline XPCWrappedNativeProto*
     201             596 : XPCCallContext::GetProto() const
     202                 : {
     203             596 :     CHECK_STATE(HAVE_OBJECT);
     204             596 :     if (mWrapper)
     205             596 :         return mWrapper->GetProto();
     206               0 :     return mFlattenedJSObject ? GetSlimWrapperProto(mFlattenedJSObject) : nsnull;
     207                 : }
     208                 : 
     209                 : inline JSBool
     210            9786 : XPCCallContext::CanGetTearOff() const
     211                 : {
     212            9786 :     return mState >= HAVE_OBJECT;
     213                 : }
     214                 : 
     215                 : inline XPCWrappedNativeTearOff*
     216         6776472 : XPCCallContext::GetTearOff() const
     217                 : {
     218         6776472 :     CHECK_STATE(HAVE_OBJECT);
     219         6776472 :     return mTearOff;
     220                 : }
     221                 : 
     222                 : inline XPCNativeScriptableInfo*
     223             326 : XPCCallContext::GetScriptableInfo() const
     224                 : {
     225             326 :     CHECK_STATE(HAVE_OBJECT);
     226             326 :     return mScriptableInfo;
     227                 : }
     228                 : 
     229                 : inline JSBool
     230            9786 : XPCCallContext::CanGetSet() const
     231                 : {
     232            9786 :     return mState >= HAVE_NAME;
     233                 : }
     234                 : 
     235                 : inline XPCNativeSet*
     236         1692046 : XPCCallContext::GetSet() const
     237                 : {
     238         1692046 :     CHECK_STATE(HAVE_NAME);
     239         1692046 :     return mSet;
     240                 : }
     241                 : 
     242                 : inline JSBool
     243            9786 : XPCCallContext::CanGetInterface() const
     244                 : {
     245            9786 :     return mState >= HAVE_NAME;
     246                 : }
     247                 : 
     248                 : inline XPCNativeInterface*
     249         8483678 : XPCCallContext::GetInterface() const
     250                 : {
     251         8483678 :     CHECK_STATE(HAVE_NAME);
     252         8483678 :     return mInterface;
     253                 : }
     254                 : 
     255                 : inline XPCNativeMember*
     256         6840818 : XPCCallContext::GetMember() const
     257                 : {
     258         6840818 :     CHECK_STATE(HAVE_NAME);
     259         6840818 :     return mMember;
     260                 : }
     261                 : 
     262                 : inline JSBool
     263         6791632 : XPCCallContext::HasInterfaceAndMember() const
     264                 : {
     265         6791632 :     return mState >= HAVE_NAME && mInterface && mMember;
     266                 : }
     267                 : 
     268                 : inline jsid
     269                 : XPCCallContext::GetName() const
     270                 : {
     271                 :     CHECK_STATE(HAVE_NAME);
     272                 :     return mName;
     273                 : }
     274                 : 
     275                 : inline JSBool
     276         1677403 : XPCCallContext::GetStaticMemberIsLocal() const
     277                 : {
     278         1677403 :     CHECK_STATE(HAVE_NAME);
     279         1677403 :     return mStaticMemberIsLocal;
     280                 : }
     281                 : 
     282                 : inline unsigned
     283         6753807 : XPCCallContext::GetArgc() const
     284                 : {
     285         6753807 :     CHECK_STATE(READY_TO_CALL);
     286         6753807 :     return mArgc;
     287                 : }
     288                 : 
     289                 : inline jsval*
     290         6753807 : XPCCallContext::GetArgv() const
     291                 : {
     292         6753807 :     CHECK_STATE(READY_TO_CALL);
     293         6753807 :     return mArgv;
     294                 : }
     295                 : 
     296                 : inline jsval*
     297                 : XPCCallContext::GetRetVal() const
     298                 : {
     299                 :     CHECK_STATE(READY_TO_CALL);
     300                 :     return mRetVal;
     301                 : }
     302                 : 
     303                 : inline void
     304        12881860 : XPCCallContext::SetRetVal(jsval val)
     305                 : {
     306        12881860 :     CHECK_STATE(HAVE_ARGS);
     307        12881860 :     if (mRetVal)
     308        12881860 :         *mRetVal = val;
     309        12881860 : }
     310                 : 
     311                 : inline jsid
     312         1691604 : XPCCallContext::GetResolveName() const
     313                 : {
     314         1691604 :     CHECK_STATE(HAVE_CONTEXT);
     315         1691604 :     return mThreadData->GetResolveName();
     316                 : }
     317                 : 
     318                 : inline jsid
     319         3064366 : XPCCallContext::SetResolveName(jsid name)
     320                 : {
     321         3064366 :     CHECK_STATE(HAVE_CONTEXT);
     322         3064366 :     return mThreadData->SetResolveName(name);
     323                 : }
     324                 : 
     325                 : inline XPCWrappedNative*
     326          224040 : XPCCallContext::GetResolvingWrapper() const
     327                 : {
     328          224040 :     CHECK_STATE(HAVE_OBJECT);
     329          224040 :     return mThreadData->GetResolvingWrapper();
     330                 : }
     331                 : 
     332                 : inline XPCWrappedNative*
     333         1038382 : XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w)
     334                 : {
     335         1038382 :     CHECK_STATE(HAVE_OBJECT);
     336         1038382 :     return mThreadData->SetResolvingWrapper(w);
     337                 : }
     338                 : 
     339                 : inline PRUint16
     340         6753807 : XPCCallContext::GetMethodIndex() const
     341                 : {
     342         6753807 :     CHECK_STATE(HAVE_OBJECT);
     343         6753807 :     return mMethodIndex;
     344                 : }
     345                 : 
     346                 : inline void
     347                 : XPCCallContext::SetMethodIndex(PRUint16 index)
     348                 : {
     349                 :     CHECK_STATE(HAVE_OBJECT);
     350                 :     mMethodIndex = index;
     351                 : }
     352                 : 
     353                 : inline JSBool
     354                 : XPCCallContext::GetDestroyJSContextInDestructor() const
     355                 : {
     356                 :     CHECK_STATE(HAVE_CONTEXT);
     357                 :     return mDestroyJSContextInDestructor;
     358                 : }
     359                 : 
     360                 : inline void
     361               0 : XPCCallContext::SetDestroyJSContextInDestructor(JSBool b)
     362                 : {
     363               0 :     CHECK_STATE(HAVE_CONTEXT);
     364               0 :     mDestroyJSContextInDestructor = b;
     365               0 : }
     366                 : 
     367                 : /***************************************************************************/
     368                 : 
     369                 : inline const nsIID*
     370         3602665 : XPCNativeInterface::GetIID() const
     371                 : {
     372                 :     const nsIID* iid;
     373         3602665 :     return NS_SUCCEEDED(mInfo->GetIIDShared(&iid)) ? iid : nsnull;
     374                 : }
     375                 : 
     376                 : inline const char*
     377          106331 : XPCNativeInterface::GetNameString() const
     378                 : {
     379                 :     const char* name;
     380          106331 :     return NS_SUCCEEDED(mInfo->GetNameShared(&name)) ? name : nsnull;
     381                 : }
     382                 : 
     383                 : inline XPCNativeMember*
     384        11652929 : XPCNativeInterface::FindMember(jsid name) const
     385                 : {
     386        11652929 :     const XPCNativeMember* member = mMembers;
     387        62795166 :     for (int i = (int) mMemberCount; i > 0; i--, member++)
     388        56126754 :         if (member->GetName() == name)
     389         4984517 :             return const_cast<XPCNativeMember*>(member);
     390         6668412 :     return nsnull;
     391                 : }
     392                 : 
     393                 : inline JSBool
     394           23858 : XPCNativeInterface::HasAncestor(const nsIID* iid) const
     395                 : {
     396           23858 :     bool found = false;
     397           23858 :     mInfo->HasAncestor(iid, &found);
     398           23858 :     return found;
     399                 : }
     400                 : 
     401                 : /***************************************************************************/
     402                 : 
     403                 : inline JSBool
     404         6073039 : XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
     405                 :                          PRUint16* pInterfaceIndex) const
     406                 : {
     407                 :     XPCNativeInterface* const * iface;
     408         6073039 :     int count = (int) mInterfaceCount;
     409                 :     int i;
     410                 : 
     411                 :     // look for interface names first
     412                 : 
     413        18497648 :     for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
     414        12424726 :         if (name == (*iface)->GetName()) {
     415             117 :             if (pMember)
     416             117 :                 *pMember = nsnull;
     417             117 :             if (pInterfaceIndex)
     418             117 :                 *pInterfaceIndex = (PRUint16) i;
     419             117 :             return true;
     420                 :         }
     421                 :     }
     422                 : 
     423                 :     // look for method names
     424        12735137 :     for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
     425        11632220 :         XPCNativeMember* member = (*iface)->FindMember(name);
     426        11632220 :         if (member) {
     427         4970005 :             if (pMember)
     428         4970005 :                 *pMember = member;
     429         4970005 :             if (pInterfaceIndex)
     430         4970005 :                 *pInterfaceIndex = (PRUint16) i;
     431         4970005 :             return true;
     432                 :         }
     433                 :     }
     434         1102917 :     return false;
     435                 : }
     436                 : 
     437                 : inline JSBool
     438         5986520 : XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
     439                 :                          XPCNativeInterface** pInterface) const
     440                 : {
     441                 :     PRUint16 index;
     442         5986520 :     if (!FindMember(name, pMember, &index))
     443         1016398 :         return false;
     444         4970122 :     *pInterface = mInterfaces[index];
     445         4970122 :     return true;
     446                 : }
     447                 : 
     448                 : inline JSBool
     449         3310533 : XPCNativeSet::FindMember(jsid name,
     450                 :                          XPCNativeMember** pMember,
     451                 :                          XPCNativeInterface** pInterface,
     452                 :                          XPCNativeSet* protoSet,
     453                 :                          JSBool* pIsLocal) const
     454                 : {
     455                 :     XPCNativeMember* Member;
     456                 :     XPCNativeInterface* Interface;
     457                 :     XPCNativeMember* protoMember;
     458                 : 
     459         3310533 :     if (!FindMember(name, &Member, &Interface))
     460           31275 :         return false;
     461                 : 
     462         3279258 :     *pMember = Member;
     463         3279258 :     *pInterface = Interface;
     464                 : 
     465                 :     *pIsLocal =
     466         3279258 :         !Member ||
     467                 :         !protoSet ||
     468                 :         (protoSet != this &&
     469           95917 :          !protoSet->MatchesSetUpToInterface(this, Interface) &&
     470           86519 :          (!protoSet->FindMember(name, &protoMember, (PRUint16*)nsnull) ||
     471         3461694 :           protoMember != Member));
     472                 : 
     473         3279258 :     return true;
     474                 : }
     475                 : 
     476                 : inline XPCNativeInterface*
     477               0 : XPCNativeSet::FindNamedInterface(jsid name) const
     478                 : {
     479               0 :     XPCNativeInterface* const * pp = mInterfaces;
     480                 : 
     481               0 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
     482               0 :         XPCNativeInterface* iface = *pp;
     483                 : 
     484               0 :         if (name == iface->GetName())
     485               0 :             return iface;
     486                 :     }
     487               0 :     return nsnull;
     488                 : }
     489                 : 
     490                 : inline XPCNativeInterface*
     491          345000 : XPCNativeSet::FindInterfaceWithIID(const nsIID& iid) const
     492                 : {
     493          345000 :     XPCNativeInterface* const * pp = mInterfaces;
     494                 : 
     495          728543 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
     496          706514 :         XPCNativeInterface* iface = *pp;
     497                 : 
     498          706514 :         if (iface->GetIID()->Equals(iid))
     499          322971 :             return iface;
     500                 :     }
     501           22029 :     return nsnull;
     502                 : }
     503                 : 
     504                 : inline JSBool
     505         1703240 : XPCNativeSet::HasInterface(XPCNativeInterface* aInterface) const
     506                 : {
     507         1703240 :     XPCNativeInterface* const * pp = mInterfaces;
     508                 : 
     509         3733896 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
     510         3403966 :         if (aInterface == *pp)
     511         1373310 :             return true;
     512                 :     }
     513          329930 :     return false;
     514                 : }
     515                 : 
     516                 : inline JSBool
     517            5076 : XPCNativeSet::HasInterfaceWithAncestor(XPCNativeInterface* aInterface) const
     518                 : {
     519            5076 :     return HasInterfaceWithAncestor(aInterface->GetIID());
     520                 : }
     521                 : 
     522                 : inline JSBool
     523           13852 : XPCNativeSet::HasInterfaceWithAncestor(const nsIID* iid) const
     524                 : {
     525                 :     // We can safely skip the first interface which is *always* nsISupports.
     526           13852 :     XPCNativeInterface* const * pp = mInterfaces+1;
     527           33858 :     for (int i = (int) mInterfaceCount; i > 1; i--, pp++)
     528           23858 :         if ((*pp)->HasAncestor(iid))
     529            3852 :             return true;
     530                 : 
     531                 :     // This is rare, so check last.
     532           10000 :     if (iid == &NS_GET_IID(nsISupports))
     533               0 :         return true;
     534                 : 
     535           10000 :     return false;
     536                 : }
     537                 : 
     538                 : inline JSBool
     539           95917 : XPCNativeSet::MatchesSetUpToInterface(const XPCNativeSet* other,
     540                 :                                       XPCNativeInterface* iface) const
     541                 : {
     542           95917 :     int count = JS_MIN((int)mInterfaceCount, (int)other->mInterfaceCount);
     543                 : 
     544           95917 :     XPCNativeInterface* const * pp1 = mInterfaces;
     545           95917 :     XPCNativeInterface* const * pp2 = other->mInterfaces;
     546                 : 
     547          190738 :     for (int i = (int) count; i > 0; i--, pp1++, pp2++) {
     548          104219 :         XPCNativeInterface* cur = (*pp1);
     549          104219 :         if (cur != (*pp2))
     550               0 :             return false;
     551          104219 :         if (cur == iface)
     552            9398 :             return true;
     553                 :     }
     554           86519 :     return false;
     555                 : }
     556                 : 
     557         4964847 : inline void XPCNativeSet::Mark()
     558                 : {
     559         4964847 :     if (IsMarked())
     560         4743030 :         return;
     561                 : 
     562          221817 :     XPCNativeInterface* const * pp = mInterfaces;
     563                 : 
     564          761321 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
     565          539504 :         (*pp)->Mark();
     566                 : 
     567          221817 :     MarkSelfOnly();
     568                 : }
     569                 : 
     570                 : #ifdef DEBUG
     571         4960961 : inline void XPCNativeSet::ASSERT_NotMarked()
     572                 : {
     573         4960961 :     NS_ASSERTION(!IsMarked(), "bad");
     574                 : 
     575         4960961 :     XPCNativeInterface* const * pp = mInterfaces;
     576                 : 
     577        18076287 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
     578        13115326 :         NS_ASSERTION(!(*pp)->IsMarked(), "bad");
     579         4960961 : }
     580                 : #endif
     581                 : 
     582                 : /***************************************************************************/
     583                 : 
     584                 : inline
     585         5444174 : JSObject* XPCWrappedNativeTearOff::GetJSObjectPreserveColor() const
     586                 : {
     587         5444174 :     return mJSObject;
     588                 : }
     589                 : 
     590                 : inline
     591              60 : JSObject* XPCWrappedNativeTearOff::GetJSObject()
     592                 : {
     593              60 :     JSObject *obj = GetJSObjectPreserveColor();
     594              60 :     xpc_UnmarkGrayObject(obj);
     595              60 :     return obj;
     596                 : }
     597                 : 
     598                 : inline
     599             120 : void XPCWrappedNativeTearOff::SetJSObject(JSObject*  JSObj)
     600                 : {
     601             120 :         mJSObject = JSObj;
     602             120 : }
     603                 : 
     604                 : inline
     605         1441147 : XPCWrappedNativeTearOff::~XPCWrappedNativeTearOff()
     606                 : {
     607         1441147 :     NS_ASSERTION(!(GetInterface()||GetNative()||GetJSObjectPreserveColor()),
     608                 :                  "tearoff not empty in dtor");
     609         1441147 : }
     610                 : 
     611                 : /***************************************************************************/
     612                 : 
     613                 : inline JSBool
     614          345000 : XPCWrappedNative::HasInterfaceNoQI(const nsIID& iid)
     615                 : {
     616          345000 :     return nsnull != GetSet()->FindInterfaceWithIID(iid);
     617                 : }
     618                 : 
     619                 : inline void
     620         2232934 : XPCWrappedNative::SweepTearOffs()
     621                 : {
     622                 :     XPCWrappedNativeTearOffChunk* chunk;
     623         4797247 :     for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
     624         2564313 :         XPCWrappedNativeTearOff* to = chunk->mTearOffs;
     625         5128626 :         for (int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK; i > 0; i--, to++) {
     626         2564313 :             JSBool marked = to->IsMarked();
     627         2564313 :             to->Unmark();
     628         2564313 :             if (marked)
     629            3763 :                 continue;
     630                 : 
     631                 :             // If this tearoff does not have a live dedicated JSObject,
     632                 :             // then let's recycle it.
     633         2560550 :             if (!to->GetJSObjectPreserveColor()) {
     634         2560376 :                 nsISupports* obj = to->GetNative();
     635         2560376 :                 if (obj) {
     636          381821 :                     obj->Release();
     637          381821 :                     to->SetNative(nsnull);
     638                 :                 }
     639         2560376 :                 to->SetInterface(nsnull);
     640                 :             }
     641                 :         }
     642                 :     }
     643         2232934 : }
     644                 : 
     645                 : /***************************************************************************/
     646                 : 
     647                 : inline JSBool
     648             302 : xpc_ForcePropertyResolve(JSContext* cx, JSObject* obj, jsid id)
     649                 : {
     650                 :     jsval prop;
     651                 : 
     652             302 :     if (!JS_LookupPropertyById(cx, obj, id, &prop))
     653               0 :         return false;
     654             302 :     return true;
     655                 : }
     656                 : 
     657                 : inline JSObject*
     658         1452482 : xpc_NewSystemInheritingJSObject(JSContext *cx, JSClass *clasp, JSObject *proto,
     659                 :                                 bool uniqueType, JSObject *parent)
     660                 : {
     661                 :     // Global creation should go through XPCWrappedNative::WrapNewGlobal().
     662         1452482 :     MOZ_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
     663                 : 
     664                 :     JSObject *obj;
     665         1452482 :     if (uniqueType) {
     666          186900 :         obj = JS_NewObjectWithUniqueType(cx, clasp, proto, parent);
     667                 :     } else {
     668         1265582 :         obj = JS_NewObject(cx, clasp, proto, parent);
     669                 :     }
     670         1452482 :     if (obj && JS_IsSystemObject(cx, parent) && !JS_MakeSystemObject(cx, obj))
     671               0 :         obj = NULL;
     672         1452482 :     return obj;
     673                 : }
     674                 : 
     675                 : inline jsid
     676               0 : GetRTIdByIndex(JSContext *cx, unsigned index)
     677                 : {
     678               0 :   XPCJSRuntime *rt = nsXPConnect::FastGetXPConnect()->GetRuntime();
     679               0 :   return rt->GetStringID(index);
     680                 : }
     681                 : 
     682                 : inline
     683              25 : JSBool ThrowBadParam(nsresult rv, unsigned paramNum, XPCCallContext& ccx)
     684                 : {
     685              25 :     XPCThrower::ThrowBadParam(rv, paramNum, ccx);
     686              25 :     return false;
     687                 : }
     688                 : 
     689                 : inline
     690           38043 : void ThrowBadResult(nsresult result, XPCCallContext& ccx)
     691                 : {
     692                 :     XPCThrower::ThrowBadResult(NS_ERROR_XPC_NATIVE_RETURNED_FAILURE,
     693           38043 :                                result, ccx);
     694           38043 : }
     695                 : 
     696                 : inline void
     697           17251 : XPCLazyCallContext::SetWrapper(XPCWrappedNative* wrapper,
     698                 :                                XPCWrappedNativeTearOff* tearoff)
     699                 : {
     700           17251 :     mWrapper = wrapper;
     701           17251 :     mTearOff = tearoff;
     702           17251 :     if (mTearOff)
     703               0 :         mFlattenedJSObject = mTearOff->GetJSObject();
     704                 :     else
     705           17251 :         mFlattenedJSObject = mWrapper->GetFlatJSObject();
     706           17251 : }
     707                 : inline void
     708           10982 : XPCLazyCallContext::SetWrapper(JSObject* flattenedJSObject)
     709                 : {
     710           10982 :     NS_ASSERTION(IS_SLIM_WRAPPER_OBJECT(flattenedJSObject),
     711                 :                  "What kind of object is this?");
     712           10982 :     mWrapper = nsnull;
     713           10982 :     mTearOff = nsnull;
     714           10982 :     mFlattenedJSObject = flattenedJSObject;
     715           10982 : }
     716                 : 
     717                 : /***************************************************************************/
     718                 : 
     719                 : #endif /* xpcinlines_h___ */

Generated by: LCOV version 1.7