1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/ErrorReporter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* diagnostic reporting for CSS style sheet parser */ 1.10 + 1.11 +#ifndef mozilla_css_ErrorReporter_h_ 1.12 +#define mozilla_css_ErrorReporter_h_ 1.13 + 1.14 +// XXX turn this off for minimo builds 1.15 +#define CSS_REPORT_PARSE_ERRORS 1.16 + 1.17 +#include "nsString.h" 1.18 + 1.19 +struct nsCSSToken; 1.20 +class nsCSSStyleSheet; 1.21 +class nsCSSScanner; 1.22 +class nsIURI; 1.23 + 1.24 +namespace mozilla { 1.25 +namespace css { 1.26 + 1.27 +class Loader; 1.28 + 1.29 +// If CSS_REPORT_PARSE_ERRORS is not defined, all of this class's 1.30 +// methods become inline stubs. 1.31 +class MOZ_STACK_CLASS ErrorReporter { 1.32 +public: 1.33 + ErrorReporter(const nsCSSScanner &aScanner, 1.34 + const nsCSSStyleSheet *aSheet, 1.35 + const Loader *aLoader, 1.36 + nsIURI *aURI); 1.37 + ~ErrorReporter(); 1.38 + 1.39 + static void ReleaseGlobals(); 1.40 + 1.41 + void OutputError(); 1.42 + void OutputError(uint32_t aLineNumber, uint32_t aLineOffset); 1.43 + void ClearError(); 1.44 + 1.45 + // In all overloads of ReportUnexpected, aMessage is a stringbundle 1.46 + // name, which will be processed as a format string with the 1.47 + // indicated number of parameters. 1.48 + 1.49 + // no parameters 1.50 + void ReportUnexpected(const char *aMessage); 1.51 + // one parameter, a string 1.52 + void ReportUnexpected(const char *aMessage, const nsString& aParam); 1.53 + // one parameter, a token 1.54 + void ReportUnexpected(const char *aMessage, const nsCSSToken& aToken); 1.55 + // two parameters, a token and a character, in that order 1.56 + void ReportUnexpected(const char *aMessage, const nsCSSToken& aToken, 1.57 + char16_t aChar); 1.58 + 1.59 + // for ReportUnexpectedEOF, aExpected can be either a stringbundle 1.60 + // name or a single character. In the former case there may not be 1.61 + // any format parameters. 1.62 + void ReportUnexpectedEOF(const char *aExpected); 1.63 + void ReportUnexpectedEOF(char16_t aExpected); 1.64 + 1.65 +private: 1.66 + void AddToError(const nsString &aErrorText); 1.67 + 1.68 +#ifdef CSS_REPORT_PARSE_ERRORS 1.69 + nsAutoString mError; 1.70 + nsString mErrorLine; 1.71 + nsString mFileName; 1.72 + const nsCSSScanner *mScanner; 1.73 + const nsCSSStyleSheet *mSheet; 1.74 + const Loader *mLoader; 1.75 + nsIURI *mURI; 1.76 + uint64_t mInnerWindowID; 1.77 + uint32_t mErrorLineNumber; 1.78 + uint32_t mPrevErrorLineNumber; 1.79 + uint32_t mErrorColNumber; 1.80 +#endif 1.81 +}; 1.82 + 1.83 +#ifndef CSS_REPORT_PARSE_ERRORS 1.84 +inline ErrorReporter::ErrorReporter(const nsCSSScanner&, 1.85 + const nsCSSStyleSheet*, 1.86 + const Loader*, 1.87 + nsIURI*) {} 1.88 +inline ErrorReporter::~ErrorReporter() {} 1.89 + 1.90 +inline void ErrorReporter::ReleaseGlobals() {} 1.91 + 1.92 +inline void ErrorReporter::OutputError() {} 1.93 +inline void ErrorReporter::ClearError() {} 1.94 + 1.95 +inline void ErrorReporter::ReportUnexpected(const char *) {} 1.96 +inline void ErrorReporter::ReportUnexpected(const char *, const nsString &) {} 1.97 +inline void ErrorReporter::ReportUnexpected(const char *, const nsCSSToken &) {} 1.98 +inline void ErrorReporter::ReportUnexpected(const char *, const nsCSSToken &, 1.99 + char16_t) {} 1.100 + 1.101 +inline void ErrorReporter::ReportUnexpectedEOF(const char *) {} 1.102 +inline void ErrorReporter::ReportUnexpectedEOF(char16_t) {} 1.103 + 1.104 +inline void ErrorReporter::AddToError(const nsString &) {} 1.105 +#endif 1.106 + 1.107 +} // namespace css 1.108 +} // namespace mozilla 1.109 + 1.110 +#endif // mozilla_css_ErrorReporter_h_