LCOV - code coverage report
Current view: directory - content/xbl/src - nsXBLProtoImplMethod.h (source / functions) Found Hit Coverage
Test: app.info Lines: 51 0 0.0 %
Date: 2012-06-02 Functions: 15 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       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 Mozilla Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   David Hyatt <hyatt@netscape.com> (Original Author)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or 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 nsXBLProtoImplMethod_h__
      40                 : #define nsXBLProtoImplMethod_h__
      41                 : 
      42                 : #include "nsIAtom.h"
      43                 : #include "nsString.h"
      44                 : #include "jsapi.h"
      45                 : #include "nsIContent.h"
      46                 : #include "nsString.h"
      47                 : #include "nsXBLProtoImplMember.h"
      48                 : #include "nsXBLSerialize.h"
      49                 : 
      50                 : struct nsXBLParameter {
      51                 :   nsXBLParameter* mNext;
      52                 :   char* mName;
      53                 : 
      54               0 :   nsXBLParameter(const nsAString& aName) {
      55               0 :     MOZ_COUNT_CTOR(nsXBLParameter);
      56               0 :     mName = ToNewCString(aName);
      57               0 :     mNext = nsnull;
      58               0 :   }
      59                 : 
      60               0 :   ~nsXBLParameter() {
      61               0 :     MOZ_COUNT_DTOR(nsXBLParameter);
      62               0 :     nsMemory::Free(mName);
      63               0 :     NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext);
      64               0 :   }
      65                 : };
      66                 : 
      67                 : struct nsXBLUncompiledMethod {
      68                 :   nsXBLParameter* mParameters;
      69                 :   nsXBLParameter* mLastParameter;
      70                 :   nsXBLTextWithLineNumber mBodyText;
      71                 : 
      72               0 :   nsXBLUncompiledMethod() :
      73                 :     mParameters(nsnull),
      74                 :     mLastParameter(nsnull),
      75               0 :     mBodyText()
      76                 :   {
      77               0 :     MOZ_COUNT_CTOR(nsXBLUncompiledMethod);
      78               0 :   }
      79                 : 
      80               0 :   ~nsXBLUncompiledMethod() {
      81               0 :     MOZ_COUNT_DTOR(nsXBLUncompiledMethod);
      82               0 :     delete mParameters;
      83               0 :   }
      84                 : 
      85               0 :   PRInt32 GetParameterCount() {
      86               0 :     PRInt32 result = 0;
      87               0 :     for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext)
      88               0 :       result++;
      89               0 :     return result;
      90                 :   }
      91                 : 
      92               0 :   void AppendBodyText(const nsAString& aText) {
      93               0 :     mBodyText.AppendText(aText);
      94               0 :   }
      95                 : 
      96               0 :   void AddParameter(const nsAString& aText) {
      97               0 :     nsXBLParameter* param = new nsXBLParameter(aText);
      98               0 :     if (!param)
      99               0 :       return;
     100               0 :     if (!mParameters)
     101               0 :       mParameters = param;
     102                 :     else
     103               0 :       mLastParameter->mNext = param;
     104               0 :     mLastParameter = param;
     105                 :   }
     106                 : 
     107               0 :   void SetLineNumber(PRUint32 aLineNumber) {
     108               0 :     mBodyText.SetLineNumber(aLineNumber);
     109               0 :   }
     110                 : };
     111                 : 
     112                 : class nsXBLProtoImplMethod: public nsXBLProtoImplMember
     113                 : {
     114                 : public:
     115                 :   nsXBLProtoImplMethod(const PRUnichar* aName);
     116                 :   virtual ~nsXBLProtoImplMethod();
     117                 : 
     118                 :   void AppendBodyText(const nsAString& aBody);
     119                 :   void AddParameter(const nsAString& aName);
     120                 : 
     121                 :   void SetLineNumber(PRUint32 aLineNumber);
     122                 :   
     123                 :   virtual nsresult InstallMember(nsIScriptContext* aContext,
     124                 :                                  nsIContent* aBoundElement, 
     125                 :                                  void* aScriptObject,
     126                 :                                  void* aTargetClassObject,
     127                 :                                  const nsCString& aClassStr);
     128                 :   virtual nsresult CompileMember(nsIScriptContext* aContext,
     129                 :                                  const nsCString& aClassStr,
     130                 :                                  JSObject* aClassObject);
     131                 : 
     132                 :   virtual void Trace(TraceCallback aCallback, void *aClosure) const;
     133                 : 
     134                 :   nsresult Read(nsIScriptContext* aContext, nsIObjectInputStream* aStream);
     135                 :   virtual nsresult Write(nsIScriptContext* aContext, nsIObjectOutputStream* aStream);
     136                 : 
     137               0 :   bool IsCompiled() const
     138                 :   {
     139               0 :     return !(mUncompiledMethod & BIT_UNCOMPILED);
     140                 :   }
     141               0 :   void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod)
     142                 :   {
     143               0 :     mUncompiledMethod = PRUptrdiff(aUncompiledMethod) | BIT_UNCOMPILED;
     144               0 :   }
     145               0 :   nsXBLUncompiledMethod* GetUncompiledMethod() const
     146                 :   {
     147               0 :     PRUptrdiff unmasked = mUncompiledMethod & ~BIT_UNCOMPILED;
     148               0 :     return reinterpret_cast<nsXBLUncompiledMethod*>(unmasked);
     149                 :   }
     150                 : 
     151                 : protected:
     152                 :   enum { BIT_UNCOMPILED = 1 << 0 };
     153                 : 
     154                 :   union {
     155                 :     PRUptrdiff mUncompiledMethod; // An object that represents the method before being compiled.
     156                 :     JSObject* mJSMethodObject;    // The JS object for the method (after compilation)
     157                 :   };
     158                 : 
     159                 : #ifdef DEBUG
     160                 :   bool mIsCompiled;
     161                 : #endif
     162                 : };
     163                 : 
     164               0 : class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
     165                 : public:
     166               0 :   nsXBLProtoImplAnonymousMethod() :
     167               0 :     nsXBLProtoImplMethod(EmptyString().get())
     168               0 :   {}
     169                 :   
     170                 :   nsresult Execute(nsIContent* aBoundElement);
     171                 : 
     172                 :   // Override InstallMember; these methods never get installed as members on
     173                 :   // binding instantiations (though they may hang out in mMembers on the
     174                 :   // prototype implementation).
     175               0 :   virtual nsresult InstallMember(nsIScriptContext* aContext,
     176                 :                                  nsIContent* aBoundElement, 
     177                 :                                  void* aScriptObject,
     178                 :                                  void* aTargetClassObject,
     179                 :                                  const nsCString& aClassStr) {
     180               0 :     return NS_OK;
     181                 :   }
     182                 : 
     183                 :   using nsXBLProtoImplMethod::Write;
     184                 :   nsresult Write(nsIScriptContext* aContext,
     185                 :                  nsIObjectOutputStream* aStream,
     186                 :                  XBLBindingSerializeDetails aType);
     187                 : };
     188                 : 
     189                 : #endif // nsXBLProtoImplMethod_h__

Generated by: LCOV version 1.7