LCOV - code coverage report
Current view: directory - dom/base - nsWrapperCacheInlines.h (source / functions) Found Hit Coverage
Test: app.info Lines: 46 42 91.3 %
Date: 2012-06-02 Functions: 8 8 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Gecko DOM code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  *   Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2008
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *    Peter Van der Beken <peterv@propagandism.org>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsWrapperCacheInline_h___
      40                 : #define nsWrapperCacheInline_h___
      41                 : 
      42                 : #include "nsWrapperCache.h"
      43                 : #include "xpcpublic.h"
      44                 : 
      45                 : inline JSObject*
      46          794617 : nsWrapperCache::GetWrapperPreserveColor() const
      47                 : {
      48          794617 :   JSObject *obj = GetJSObjectFromBits();
      49          794617 :   return !IsProxy() || !obj || js::IsProxy(obj) ? obj : nsnull;
      50                 : }
      51                 : 
      52                 : inline JSObject*
      53          201085 : nsWrapperCache::GetWrapper() const
      54                 : {
      55          201085 :     JSObject* obj = GetWrapperPreserveColor();
      56          201085 :     xpc_UnmarkGrayObject(obj);
      57          201085 :     return obj;
      58                 : }
      59                 : 
      60                 : inline void
      61           24082 : nsWrapperCache::SetWrapper(JSObject* aWrapper)
      62                 : {
      63           24082 :     NS_ASSERTION(!PreservingWrapper(), "Clearing a preserved wrapper!");
      64           24082 :     NS_ASSERTION(aWrapper, "Use ClearWrapper!");
      65                 : 
      66           24082 :     JSObject *obj = GetJSObjectFromBits();
      67           24082 :     if (obj && mozilla::dom::binding::isExpandoObject(obj)) {
      68               0 :         NS_ASSERTION(mozilla::dom::binding::instanceIsProxy(aWrapper),
      69                 :                      "We have an expando but this isn't a DOM proxy?");
      70                 :         js::SetProxyExtra(aWrapper, mozilla::dom::binding::JSPROXYSLOT_EXPANDO,
      71               0 :                           js::ObjectValue(*obj));
      72                 :     }
      73                 : 
      74           24082 :     SetWrapperBits(aWrapper);
      75           24082 : }
      76                 : 
      77                 : inline JSObject*
      78          368077 : nsWrapperCache::GetExpandoObjectPreserveColor() const
      79                 : {
      80          368077 :     JSObject *obj = GetJSObjectFromBits();
      81          368077 :     if (!obj) {
      82          358646 :         return NULL;
      83                 :     }
      84                 : 
      85            9431 :     if (!IsProxy()) {
      86                 :         // If we support non-proxy dom binding objects then this should be:
      87                 :         //return mozilla::dom::binding::isExpandoObject(obj) ? obj : js::GetSlot(obj, EXPANDO_SLOT);
      88            9332 :         return NULL;
      89                 :     }
      90                 : 
      91                 :     // FIXME unmark gray?
      92              99 :     if (mozilla::dom::binding::instanceIsProxy(obj)) {
      93              99 :         return GetExpandoFromSlot(obj);
      94                 :     }
      95                 : 
      96               0 :     return mozilla::dom::binding::isExpandoObject(obj) ? obj : NULL;
      97                 : }
      98                 : 
      99                 : inline JSObject*
     100            4420 : nsWrapperCache::GetExpandoFromSlot(JSObject *obj)
     101                 : {
     102            4420 :     NS_ASSERTION(mozilla::dom::binding::instanceIsProxy(obj),
     103                 :                  "Asking for an expando but this isn't a DOM proxy?");
     104            4420 :     const js::Value &v = js::GetProxyExtra(obj, mozilla::dom::binding::JSPROXYSLOT_EXPANDO);
     105            4420 :     return v.isUndefined() ? NULL : v.toObjectOrNull();
     106                 : }
     107                 : 
     108                 : inline void
     109           24078 : nsWrapperCache::ClearWrapper()
     110                 : {
     111           24078 :     NS_ASSERTION(!PreservingWrapper(), "Clearing a preserved wrapper!");
     112           24078 :     JSObject *obj = GetJSObjectFromBits();
     113           24078 :     if (!obj) {
     114               0 :         return;
     115                 :     }
     116                 : 
     117                 :     JSObject *expando;
     118           24078 :     if (mozilla::dom::binding::instanceIsProxy(obj)) {
     119            4321 :         expando = GetExpandoFromSlot(obj);
     120                 :     }
     121                 :     else {
     122                 :         // If we support non-proxy dom binding objects then this should be:
     123                 :         //expando = js::GetSlot(obj, EXPANDO_SLOT);
     124           19757 :         expando = NULL;
     125                 :     }
     126                 : 
     127           24078 :     SetWrapperBits(expando);
     128                 : }
     129                 : 
     130                 : inline void
     131          236785 : nsWrapperCache::ClearWrapperIfProxy()
     132                 : {
     133          236785 :     if (!IsProxy()) {
     134          235183 :         return;
     135                 :     }
     136                 : 
     137            1602 :     RemoveExpandoObject();
     138                 : 
     139            1602 :     SetWrapperBits(NULL);
     140                 : }
     141                 : 
     142                 : inline bool
     143          556869 : nsWrapperCache::IsBlack()
     144                 : {
     145          556869 :   JSObject* o = GetWrapperPreserveColor();
     146          556869 :   return o && !xpc_IsGrayGCThing(o);
     147                 : }
     148                 : 
     149                 : #endif /* nsWrapperCache_h___ */

Generated by: LCOV version 1.7