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-06-02 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            3463 : XPCJSRuntime::AddVariantRoot(XPCTraceableVariant* variant)
      69                 : {
      70            3463 :     variant->AddToRootSet(GetMapLock(), &mVariantRoots);
      71            3463 : }
      72                 : 
      73                 : inline void
      74          114050 : XPCJSRuntime::AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS)
      75                 : {
      76          114050 :     wrappedJS->AddToRootSet(GetMapLock(), &mWrappedJSRoots);
      77          114050 : }
      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         9536288 : XPCCallContext::IsValid() const
      89                 : {
      90         9536288 :     return mState != INIT_FAILED;
      91                 : }
      92                 : 
      93                 : inline nsXPConnect*
      94          361965 : XPCCallContext::GetXPConnect() const
      95                 : {
      96          361965 :     CHECK_STATE(HAVE_CONTEXT);
      97          361965 :     return mXPC;
      98                 : }
      99                 : 
     100                 : inline XPCJSRuntime*
     101        14136285 : XPCCallContext::GetRuntime() const
     102                 : {
     103        14136285 :     CHECK_STATE(HAVE_CONTEXT);
     104        14136285 :     return mXPCContext->GetRuntime();
     105                 : }
     106                 : 
     107                 : inline XPCPerThreadData*
     108        33690646 : XPCCallContext::GetThreadData() const
     109                 : {
     110        33690646 :     CHECK_STATE(HAVE_CONTEXT);
     111        33690646 :     return mThreadData;
     112                 : }
     113                 : 
     114                 : inline XPCContext*
     115        23030074 : XPCCallContext::GetXPCContext() const
     116                 : {
     117        23030074 :     CHECK_STATE(HAVE_CONTEXT);
     118        23030074 :     return mXPCContext;
     119                 : }
     120                 : 
     121                 : inline JSContext*
     122        78974517 : XPCCallContext::GetJSContext() const
     123                 : {
     124        78974517 :     CHECK_STATE(HAVE_CONTEXT);
     125        78974517 :     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             397 : XPCCallContext::GetCallerLanguage() const
     137                 : {
     138             397 :     CHECK_STATE(HAVE_CONTEXT);
     139             397 :     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           19993 : XPCCallContext::GetPrevCallContext() const
     151                 : {
     152           19993 :     CHECK_STATE(HAVE_CONTEXT);
     153           19993 :     return mPrevCallContext;
     154                 : }
     155                 : 
     156                 : inline JSObject*
     157         8544038 : XPCCallContext::GetScopeForNewJSObjects() const
     158                 : {
     159         8544038 :     CHECK_STATE(HAVE_SCOPE);
     160         8544038 :     return mScopeForNewJSObjects;
     161                 : }
     162                 : 
     163                 : inline void
     164         3036037 : XPCCallContext::SetScopeForNewJSObjects(JSObject *scope)
     165                 : {
     166         3036037 :     NS_ABORT_IF_FALSE(mState == HAVE_CONTEXT, "wrong call context state");
     167         3036037 :     NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(scope, mJSContext), "wrong compartment");
     168         3036037 :     mScopeForNewJSObjects = scope;
     169         3036037 :     mState = HAVE_SCOPE;
     170         3036037 : }
     171                 : 
     172                 : inline JSObject*
     173         6818757 : XPCCallContext::GetFlattenedJSObject() const
     174                 : {
     175         6818757 :     CHECK_STATE(HAVE_OBJECT);
     176         6818757 :     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        38800898 : XPCCallContext::GetWrapper() const
     192                 : {
     193        38800898 :     if (mState == INIT_FAILED)
     194               0 :         return nsnull;
     195                 : 
     196        38800898 :     CHECK_STATE(HAVE_OBJECT);
     197        38800898 :     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         6774943 : XPCCallContext::GetTearOff() const
     217                 : {
     218         6774943 :     CHECK_STATE(HAVE_OBJECT);
     219         6774943 :     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         1692180 : XPCCallContext::GetSet() const
     237                 : {
     238         1692180 :     CHECK_STATE(HAVE_NAME);
     239         1692180 :     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         8482352 : XPCCallContext::GetInterface() const
     250                 : {
     251         8482352 :     CHECK_STATE(HAVE_NAME);
     252         8482352 :     return mInterface;
     253                 : }
     254                 : 
     255                 : inline XPCNativeMember*
     256         6839291 : XPCCallContext::GetMember() const
     257                 : {
     258         6839291 :     CHECK_STATE(HAVE_NAME);
     259         6839291 :     return mMember;
     260                 : }
     261                 : 
     262                 : inline JSBool
     263         6790172 : XPCCallContext::HasInterfaceAndMember() const
     264                 : {
     265         6790172 :     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         1677528 : XPCCallContext::GetStaticMemberIsLocal() const
     277                 : {
     278         1677528 :     CHECK_STATE(HAVE_NAME);
     279         1677528 :     return mStaticMemberIsLocal;
     280                 : }
     281                 : 
     282                 : inline unsigned
     283         6752344 : XPCCallContext::GetArgc() const
     284                 : {
     285         6752344 :     CHECK_STATE(READY_TO_CALL);
     286         6752344 :     return mArgc;
     287                 : }
     288                 : 
     289                 : inline jsval*
     290         6752344 : XPCCallContext::GetArgv() const
     291                 : {
     292         6752344 :     CHECK_STATE(READY_TO_CALL);
     293         6752344 :     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        12879528 : XPCCallContext::SetRetVal(jsval val)
     305                 : {
     306        12879528 :     CHECK_STATE(HAVE_ARGS);
     307        12879528 :     if (mRetVal)
     308        12879528 :         *mRetVal = val;
     309        12879528 : }
     310                 : 
     311                 : inline jsid
     312         1692821 : XPCCallContext::GetResolveName() const
     313                 : {
     314         1692821 :     CHECK_STATE(HAVE_CONTEXT);
     315         1692821 :     return mThreadData->GetResolveName();
     316                 : }
     317                 : 
     318                 : inline jsid
     319         3062892 : XPCCallContext::SetResolveName(jsid name)
     320                 : {
     321         3062892 :     CHECK_STATE(HAVE_CONTEXT);
     322         3062892 :     return mThreadData->SetResolveName(name);
     323                 : }
     324                 : 
     325                 : inline XPCWrappedNative*
     326          224081 : XPCCallContext::GetResolvingWrapper() const
     327                 : {
     328          224081 :     CHECK_STATE(HAVE_OBJECT);
     329          224081 :     return mThreadData->GetResolvingWrapper();
     330                 : }
     331                 : 
     332                 : inline XPCWrappedNative*
     333         1037978 : XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w)
     334                 : {
     335         1037978 :     CHECK_STATE(HAVE_OBJECT);
     336         1037978 :     return mThreadData->SetResolvingWrapper(w);
     337                 : }
     338                 : 
     339                 : inline PRUint16
     340         6752344 : XPCCallContext::GetMethodIndex() const
     341                 : {
     342         6752344 :     CHECK_STATE(HAVE_OBJECT);
     343         6752344 :     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         3602886 : XPCNativeInterface::GetIID() const
     371                 : {
     372                 :     const nsIID* iid;
     373         3602886 :     return NS_SUCCEEDED(mInfo->GetIIDShared(&iid)) ? iid : nsnull;
     374                 : }
     375                 : 
     376                 : inline const char*
     377          105994 : XPCNativeInterface::GetNameString() const
     378                 : {
     379                 :     const char* name;
     380          105994 :     return NS_SUCCEEDED(mInfo->GetNameShared(&name)) ? name : nsnull;
     381                 : }
     382                 : 
     383                 : inline XPCNativeMember*
     384        11657545 : XPCNativeInterface::FindMember(jsid name) const
     385                 : {
     386        11657545 :     const XPCNativeMember* member = mMembers;
     387        62811826 :     for (int i = (int) mMemberCount; i > 0; i--, member++)
     388        56141304 :         if (member->GetName() == name)
     389         4987023 :             return const_cast<XPCNativeMember*>(member);
     390         6670522 :     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         6075238 : XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
     405                 :                          PRUint16* pInterfaceIndex) const
     406                 : {
     407                 :     XPCNativeInterface* const * iface;
     408         6075238 :     int count = (int) mInterfaceCount;
     409                 :     int i;
     410                 : 
     411                 :     // look for interface names first
     412                 : 
     413        18501945 :     for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
     414        12426824 :         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        12739313 :     for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
     425        11636729 :         XPCNativeMember* member = (*iface)->FindMember(name);
     426        11636729 :         if (member) {
     427         4972537 :             if (pMember)
     428         4972537 :                 *pMember = member;
     429         4972537 :             if (pInterfaceIndex)
     430         4972537 :                 *pInterfaceIndex = (PRUint16) i;
     431         4972537 :             return true;
     432                 :         }
     433                 :     }
     434         1102584 :     return false;
     435                 : }
     436                 : 
     437                 : inline JSBool
     438         5988716 : XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
     439                 :                          XPCNativeInterface** pInterface) const
     440                 : {
     441                 :     PRUint16 index;
     442         5988716 :     if (!FindMember(name, pMember, &index))
     443         1016062 :         return false;
     444         4972654 :     *pInterface = mInterfaces[index];
     445         4972654 :     return true;
     446                 : }
     447                 : 
     448                 : inline JSBool
     449         3311789 : 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         3311789 :     if (!FindMember(name, &Member, &Interface))
     460           31216 :         return false;
     461                 : 
     462         3280573 :     *pMember = Member;
     463         3280573 :     *pInterface = Interface;
     464                 : 
     465                 :     *pIsLocal =
     466         3280573 :         !Member ||
     467                 :         !protoSet ||
     468                 :         (protoSet != this &&
     469           95896 :          !protoSet->MatchesSetUpToInterface(this, Interface) &&
     470           86522 :          (!protoSet->FindMember(name, &protoMember, (PRUint16*)nsnull) ||
     471         3462991 :           protoMember != Member));
     472                 : 
     473         3280573 :     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          344741 : XPCNativeSet::FindInterfaceWithIID(const nsIID& iid) const
     492                 : {
     493          344741 :     XPCNativeInterface* const * pp = mInterfaces;
     494                 : 
     495          728025 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
     496          705995 :         XPCNativeInterface* iface = *pp;
     497                 : 
     498          705995 :         if (iface->GetIID()->Equals(iid))
     499          322711 :             return iface;
     500                 :     }
     501           22030 :     return nsnull;
     502                 : }
     503                 : 
     504                 : inline JSBool
     505         1703557 : XPCNativeSet::HasInterface(XPCNativeInterface* aInterface) const
     506                 : {
     507         1703557 :     XPCNativeInterface* const * pp = mInterfaces;
     508                 : 
     509         3734564 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
     510         3404596 :         if (aInterface == *pp)
     511         1373589 :             return true;
     512                 :     }
     513          329968 :     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           95896 : XPCNativeSet::MatchesSetUpToInterface(const XPCNativeSet* other,
     540                 :                                       XPCNativeInterface* iface) const
     541                 : {
     542           95896 :     int count = JS_MIN((int)mInterfaceCount, (int)other->mInterfaceCount);
     543                 : 
     544           95896 :     XPCNativeInterface* const * pp1 = mInterfaces;
     545           95896 :     XPCNativeInterface* const * pp2 = other->mInterfaces;
     546                 : 
     547          190717 :     for (int i = (int) count; i > 0; i--, pp1++, pp2++) {
     548          104195 :         XPCNativeInterface* cur = (*pp1);
     549          104195 :         if (cur != (*pp2))
     550               0 :             return false;
     551          104195 :         if (cur == iface)
     552            9374 :             return true;
     553                 :     }
     554           86522 :     return false;
     555                 : }
     556                 : 
     557         4964937 : inline void XPCNativeSet::Mark()
     558                 : {
     559         4964937 :     if (IsMarked())
     560         4743170 :         return;
     561                 : 
     562          221767 :     XPCNativeInterface* const * pp = mInterfaces;
     563                 : 
     564          761163 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
     565          539396 :         (*pp)->Mark();
     566                 : 
     567          221767 :     MarkSelfOnly();
     568                 : }
     569                 : 
     570                 : #ifdef DEBUG
     571         4961050 : inline void XPCNativeSet::ASSERT_NotMarked()
     572                 : {
     573         4961050 :     NS_ASSERTION(!IsMarked(), "bad");
     574                 : 
     575         4961050 :     XPCNativeInterface* const * pp = mInterfaces;
     576                 : 
     577        18076183 :     for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
     578        13115133 :         NS_ASSERTION(!(*pp)->IsMarked(), "bad");
     579         4961050 : }
     580                 : #endif
     581                 : 
     582                 : /***************************************************************************/
     583                 : 
     584                 : inline
     585         5445046 : JSObject* XPCWrappedNativeTearOff::GetJSObjectPreserveColor() const
     586                 : {
     587         5445046 :     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         1441469 : XPCWrappedNativeTearOff::~XPCWrappedNativeTearOff()
     606                 : {
     607         1441469 :     NS_ASSERTION(!(GetInterface()||GetNative()||GetJSObjectPreserveColor()),
     608                 :                  "tearoff not empty in dtor");
     609         1441469 : }
     610                 : 
     611                 : /***************************************************************************/
     612                 : 
     613                 : inline JSBool
     614          344741 : XPCWrappedNative::HasInterfaceNoQI(const nsIID& iid)
     615                 : {
     616          344741 :     return nsnull != GetSet()->FindInterfaceWithIID(iid);
     617                 : }
     618                 : 
     619                 : inline void
     620         2233014 : XPCWrappedNative::SweepTearOffs()
     621                 : {
     622                 :     XPCWrappedNativeTearOffChunk* chunk;
     623         4797556 :     for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
     624         2564542 :         XPCWrappedNativeTearOff* to = chunk->mTearOffs;
     625         5129084 :         for (int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK; i > 0; i--, to++) {
     626         2564542 :             JSBool marked = to->IsMarked();
     627         2564542 :             to->Unmark();
     628         2564542 :             if (marked)
     629            3764 :                 continue;
     630                 : 
     631                 :             // If this tearoff does not have a live dedicated JSObject,
     632                 :             // then let's recycle it.
     633         2560778 :             if (!to->GetJSObjectPreserveColor()) {
     634         2560602 :                 nsISupports* obj = to->GetNative();
     635         2560602 :                 if (obj) {
     636          381844 :                     obj->Release();
     637          381844 :                     to->SetNative(nsnull);
     638                 :                 }
     639         2560602 :                 to->SetInterface(nsnull);
     640                 :             }
     641                 :         }
     642                 :     }
     643         2233014 : }
     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         1452797 : xpc_NewSystemInheritingJSObject(JSContext *cx, JSClass *clasp, JSObject *proto,
     659                 :                                 bool uniqueType, JSObject *parent)
     660                 : {
     661                 :     // Global creation should go through XPCWrappedNative::WrapNewGlobal().
     662         1452797 :     MOZ_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
     663                 : 
     664                 :     JSObject *obj;
     665         1452797 :     if (uniqueType) {
     666          186922 :         obj = JS_NewObjectWithUniqueType(cx, clasp, proto, parent);
     667                 :     } else {
     668         1265875 :         obj = JS_NewObject(cx, clasp, proto, parent);
     669                 :     }
     670         1452797 :     if (obj && JS_IsSystemObject(cx, parent) && !JS_MakeSystemObject(cx, obj))
     671               0 :         obj = NULL;
     672         1452797 :     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           38046 : void ThrowBadResult(nsresult result, XPCCallContext& ccx)
     691                 : {
     692                 :     XPCThrower::ThrowBadResult(NS_ERROR_XPC_NATIVE_RETURNED_FAILURE,
     693           38046 :                                result, ccx);
     694           38046 : }
     695                 : 
     696                 : inline void
     697           17258 : XPCLazyCallContext::SetWrapper(XPCWrappedNative* wrapper,
     698                 :                                XPCWrappedNativeTearOff* tearoff)
     699                 : {
     700           17258 :     mWrapper = wrapper;
     701           17258 :     mTearOff = tearoff;
     702           17258 :     if (mTearOff)
     703               0 :         mFlattenedJSObject = mTearOff->GetJSObject();
     704                 :     else
     705           17258 :         mFlattenedJSObject = mWrapper->GetFlatJSObject();
     706           17258 : }
     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