From 75ddcfbe90f5e92509ce1e2af8643c87688f0b45 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Tue, 6 Aug 2002 12:55:44 +0000 Subject: [PATCH] Make XBL report XML parse errors. b=156714 r=caillon sr=ben git-svn-id: svn://10.0.0.236/trunk@126502 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/xbl/src/nsXBLContentSink.cpp | 36 ++++++++++++++++++++ mozilla/content/xbl/src/nsXBLContentSink.h | 5 +++ 2 files changed, 41 insertions(+) diff --git a/mozilla/content/xbl/src/nsXBLContentSink.cpp b/mozilla/content/xbl/src/nsXBLContentSink.cpp index 502be77c0b7..ae36ea083ab 100644 --- a/mozilla/content/xbl/src/nsXBLContentSink.cpp +++ b/mozilla/content/xbl/src/nsXBLContentSink.cpp @@ -54,6 +54,8 @@ #include "nsXBLProtoImplProperty.h" #include "nsXBLProtoImplMethod.h" #include "nsXBLProtoImplField.h" +#include "nsIConsoleService.h" +#include "nsIScriptError.h" nsresult NS_NewXBLContentSink(nsIXMLContentSink** aResult, @@ -183,6 +185,40 @@ nsXBLContentSink::FlushText(PRBool aCreateTextNode, return nsXMLContentSink::FlushText(aCreateTextNode, aDidFlush); } +NS_IMETHODIMP +nsXBLContentSink::ReportError(const PRUnichar* aErrorText, + const PRUnichar* aSourceText) +{ + // XXX We should make sure the binding has no effect, but that it also + // gets destroyed properly without leaking. Perhaps we should even + // ensure that the content that was bound is displayed with no + // binding. + + // Report the error to the error console. + nsCOMPtr consoleService = + do_GetService(NS_CONSOLESERVICE_CONTRACTID); + if (consoleService) { + // XXX It would be nice if the parser didn't pre-format it for us, + // because then we could create a instance of nsIScriptError and the + // error console would format this much more nicely for us. + // However, that would require duplicating even more code between + // the XML content sink and the XUL content sink. + + consoleService->LogStringMessage(aErrorText); + } + +#ifdef DEBUG + // Report the error to stderr. + fprintf(stderr, + "\n%s\n%s\n\n", + NS_LossyConvertUCS2toASCII(aErrorText).get(), + NS_LossyConvertUCS2toASCII(aSourceText).get()); +#endif + + // Most of what this does won't be too useful, but whatever... + return nsXMLContentSink::ReportError(aErrorText, aSourceText); +} + NS_IMETHODIMP nsXBLContentSink::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, diff --git a/mozilla/content/xbl/src/nsXBLContentSink.h b/mozilla/content/xbl/src/nsXBLContentSink.h index 44ec675d422..553b44aba83 100644 --- a/mozilla/content/xbl/src/nsXBLContentSink.h +++ b/mozilla/content/xbl/src/nsXBLContentSink.h @@ -134,6 +134,11 @@ protected: // nsXMLContentSink overrides nsresult FlushText(PRBool aCreateTextNode=PR_TRUE, PRBool* aDidFlush=nsnull); + + // nsIExpatSink overrides + NS_IMETHOD ReportError(const PRUnichar* aErrorText, + const PRUnichar* aSourceText); + protected: XBLPrimaryState mState; XBLSecondaryState mSecondaryState;