From 67d914af3365b62d6968ad1eb4338a98a653e9d3 Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Thu, 30 Mar 2000 09:40:11 +0000 Subject: [PATCH] Switch from nsIScriptErrorLogger approach - having the Console Service support multiple factory interfaces for different kinds of console methods - to having a separate script error class. Per discussion with jband. Add a few #ifndef __nsidefineforthisfile__ guards to .h files. git-svn-id: svn://10.0.0.236/trunk@64592 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpfe/components/console/Makefile.in | 1 - mozilla/xpfe/components/console/makefile.win | 3 -- .../components/console/nsConsoleMessage.h | 5 +++ .../components/console/nsConsoleService.cpp | 24 +---------- .../components/console/nsConsoleService.h | 10 +++-- .../console/nsConsoleServiceModule.cpp | 10 +++++ .../components/console/nsIScriptError.idl | 31 ++++++-------- .../console/nsIScriptErrorLogger.idl | 40 ------------------- .../xpfe/components/console/nsScriptError.cpp | 29 +++++++++----- .../xpfe/components/console/nsScriptError.h | 22 ++-------- 10 files changed, 60 insertions(+), 115 deletions(-) delete mode 100644 mozilla/xpfe/components/console/nsIScriptErrorLogger.idl diff --git a/mozilla/xpfe/components/console/Makefile.in b/mozilla/xpfe/components/console/Makefile.in index e9993d2b799..8f19ca67c08 100644 --- a/mozilla/xpfe/components/console/Makefile.in +++ b/mozilla/xpfe/components/console/Makefile.in @@ -47,7 +47,6 @@ XPIDLSRCS = \ nsIConsoleMessage.idl \ nsIConsoleListener.idl \ nsIScriptError.idl \ - nsIScriptErrorLogger.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/console/makefile.win b/mozilla/xpfe/components/console/makefile.win index 668fbe88e8e..e35bac7d6fe 100644 --- a/mozilla/xpfe/components/console/makefile.win +++ b/mozilla/xpfe/components/console/makefile.win @@ -38,10 +38,8 @@ XPIDLSRCS = \ .\nsIConsoleMessage.idl \ .\nsIConsoleListener.idl \ .\nsIScriptError.idl \ - .\nsIScriptErrorLogger.idl \ $(NULL) - LINCS = \ $(NULL) @@ -50,7 +48,6 @@ LLIBS = \ $(DIST)\lib\xpcom.lib \ $(NULL) - OBJS = \ .\$(OBJDIR)\nsConsoleMessage.obj \ .\$(OBJDIR)\nsConsoleService.obj \ diff --git a/mozilla/xpfe/components/console/nsConsoleMessage.h b/mozilla/xpfe/components/console/nsConsoleMessage.h index 393ae956c73..4ce5ea40677 100644 --- a/mozilla/xpfe/components/console/nsConsoleMessage.h +++ b/mozilla/xpfe/components/console/nsConsoleMessage.h @@ -19,6 +19,9 @@ * */ +#ifndef __nsconsolemessage_h__ +#define __nsconsolemessage_h__ + #include "nsIConsoleMessage.h" #include "nsString.h" @@ -38,3 +41,5 @@ public: private: nsAutoString mMessage; }; + +#endif /* __nsconsolemessage_h__ */ diff --git a/mozilla/xpfe/components/console/nsConsoleService.cpp b/mozilla/xpfe/components/console/nsConsoleService.cpp index 1f2437ec9fe..7607ef807fd 100644 --- a/mozilla/xpfe/components/console/nsConsoleService.cpp +++ b/mozilla/xpfe/components/console/nsConsoleService.cpp @@ -28,13 +28,8 @@ #include "nsConsoleService.h" #include "nsConsoleMessage.h" -#include "nsScriptError.h" -// NS_IMPL_THREADSAFE_ISUPPORTS(nsConsoleService, NS_GET_IID(nsIConsoleService)); - -NS_IMPL_THREADSAFE_ISUPPORTS2(nsConsoleService, - nsIConsoleService, - nsIScriptErrorLogger); +NS_IMPL_THREADSAFE_ISUPPORTS(nsConsoleService, NS_GET_IID(nsIConsoleService)); nsConsoleService::nsConsoleService() { @@ -194,20 +189,3 @@ nsConsoleService::UnregisterListener(nsIConsoleListener *listener) { mListeners->RemoveElement(listener); return NS_OK; } - -// nsIScriptErrorLogger methods -NS_IMETHODIMP -nsConsoleService::LogScriptError(const PRUnichar *message, - const PRUnichar *sourceName, - const PRUnichar *sourceLine, - PRUint32 lineNumber, - PRUint32 columnNumber, - PRUint32 flags, - const char *category) -{ - // LogMessage adds a ref to this, and eventual release does delete. - nsScriptError *err = new nsScriptError(message, sourceName, sourceLine, - lineNumber, columnNumber, - flags, category); - return this->LogMessage(err); -} diff --git a/mozilla/xpfe/components/console/nsConsoleService.h b/mozilla/xpfe/components/console/nsConsoleService.h index c6d60ccdfc7..6c0aebd14d7 100644 --- a/mozilla/xpfe/components/console/nsConsoleService.h +++ b/mozilla/xpfe/components/console/nsConsoleService.h @@ -24,13 +24,16 @@ * 'lil description of this file. */ +#ifndef __nsconsoleservice_h__ +#define __nsconsoleservice_h__ + + #include "nsSupportsArray.h" #include "nsCOMPtr.h" #include "nsIConsoleService.h" -#include "nsIScriptErrorLogger.h" -class nsConsoleService : public nsIConsoleService, nsIScriptErrorLogger +class nsConsoleService : public nsIConsoleService { public: nsConsoleService(); @@ -38,7 +41,6 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSICONSOLESERVICE - NS_DECL_NSISCRIPTERRORLOGGER private: // Circular buffer of saved messages @@ -56,3 +58,5 @@ private: // Listeners to notify whenever a new message is logged. nsCOMPtr mListeners; }; + +#endif /* __nsconsoleservice_h__ */ diff --git a/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp b/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp index 36a681ea3d0..07c78413421 100644 --- a/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp +++ b/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp @@ -23,8 +23,10 @@ #include "nsIGenericFactory.h" #include "nsConsoleService.h" +#include "nsScriptError.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError) static nsModuleComponentInfo components[] = { @@ -32,6 +34,11 @@ static nsModuleComponentInfo components[] = nsConsoleServiceConstructor, nsnull, // RegisterConsoleService nsnull, // UnregisterConsoleService + }, + { "Script Error", NS_SCRIPTERROR_CID, NS_SCRIPTERROR_PROGID, + nsScriptErrorConstructor, + nsnull, + nsnull, } }; @@ -51,3 +58,6 @@ static nsModuleComponentInfo components[] = NS_IMPL_NSGETMODULE("nsConsoleServiceModule", components) + + + diff --git a/mozilla/xpfe/components/console/nsIScriptError.idl b/mozilla/xpfe/components/console/nsIScriptError.idl index 6fcd23b2b1d..6f3d09dde13 100644 --- a/mozilla/xpfe/components/console/nsIScriptError.idl +++ b/mozilla/xpfe/components/console/nsIScriptError.idl @@ -51,24 +51,19 @@ interface nsIScriptError : nsIConsoleMessage readonly attribute PRUint32 flags; readonly attribute string category; + + void init(in wstring message, + in wstring sourceName, + in wstring sourcLine, + in PRUint32 lineNumber, + in PRUint32 columnNumber, + in PRUint32 flags, + in string category); }; -// jband asks: save more info for debuggy stuff in console? -// e.g. title of window, maybe weak reference to originating window? -// maybe just way to get from url to loaded document. - - - -// struct JSErrorReport { -// const char *filename; /* source file name, URL, etc., or null */ -// uintN lineno; /* source line number */ -// const char *linebuf; /* offending source line without final \n */ -// const char *tokenptr; /* pointer to error token in linebuf */ -// const jschar *uclinebuf; /* unicode (original) line buffer */ -// const jschar *uctokenptr; /* unicode (original) token pointer */ -// uintN flags; /* error/warning, etc. */ -// uintN errorNumber; /* the error number, e.g. see js.msg */ -// const jschar *ucmessage; /* the (default) error message */ -// const jschar **messageArgs; /* arguments for the error message */ -// }; +%{ C++ +#define NS_SCRIPTERROR_CID \ +{ 0xe38e53b9, 0x5bb0, 0x456a, { 0xb5, 0x53, 0x57, 0x93, 0x70, 0xcb, 0x15, 0x67 }} +#define NS_SCRIPTERROR_PROGID "scripterror" +%} diff --git a/mozilla/xpfe/components/console/nsIScriptErrorLogger.idl b/mozilla/xpfe/components/console/nsIScriptErrorLogger.idl deleted file mode 100644 index 1c3e87d2cf0..00000000000 --- a/mozilla/xpfe/components/console/nsIScriptErrorLogger.idl +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -/* - * Interface (for nsConsoleService to expose) for logging script errors; - * logs an nsIScriptError to the console service. - */ - -#include "nsISupports.idl" - -[scriptable, uuid(5eb93360-1dd2-11b2-9986-d1c3d4821e3f)] -interface nsIScriptErrorLogger : nsISupports -{ - void logScriptError(in wstring message, - in wstring sourceName, - in wstring sourceLine, - in PRUint32 lineNumber, - in PRUint32 columnNumber, - in PRUint32 flags, - in string category); -}; diff --git a/mozilla/xpfe/components/console/nsScriptError.cpp b/mozilla/xpfe/components/console/nsScriptError.cpp index 89c10e12bc9..9204b6daad4 100644 --- a/mozilla/xpfe/components/console/nsScriptError.cpp +++ b/mozilla/xpfe/components/console/nsScriptError.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -77,11 +77,22 @@ nsScriptError::GetCategory(char **result) { return NS_OK; } - - - - - - - - +NS_IMETHODIMP +nsScriptError::Init(const PRUnichar *message, + const PRUnichar *sourceName, + const PRUnichar *sourceLine, + PRUint32 lineNumber, + PRUint32 columnNumber, + PRUint32 flags, + const char *category) +{ + mMessage.SetString(message); + mSourceName.SetString(sourceName); + mLineNumber = lineNumber; + mSourceLine.SetString(sourceLine); + mColumnNumber = columnNumber; + mFlags = flags; + mCategory.SetString(category); + + return NS_OK; +} diff --git a/mozilla/xpfe/components/console/nsScriptError.h b/mozilla/xpfe/components/console/nsScriptError.h index b8528e63937..f271fbfa9b3 100644 --- a/mozilla/xpfe/components/console/nsScriptError.h +++ b/mozilla/xpfe/components/console/nsScriptError.h @@ -20,6 +20,9 @@ * Contributor(s): */ +#ifndef __nsscripterror_h__ +#define __nsscripterror_h__ + #include "nsIScriptError.h" #include "nsString.h" @@ -31,23 +34,6 @@ public: // TODO - do something reasonable on getting null from these babies. - nsScriptError(const PRUnichar *message, - const PRUnichar *sourceName, // or URL - const PRUnichar *sourceLine, - PRUint32 lineNumber, - PRUint32 columnNumber, - PRUint32 flags, - const char *category) - { - mMessage.SetString(message); - mSourceName.SetString(sourceName); - mLineNumber = lineNumber; - mSourceLine.SetString(sourceLine); - mColumnNumber = columnNumber; - mFlags = flags; - mCategory.SetString(category); - } - NS_DECL_ISUPPORTS NS_DECL_NSICONSOLEMESSAGE NS_DECL_NSISCRIPTERROR @@ -62,4 +48,4 @@ private: nsCAutoString mCategory; }; - +#endif /* __nsscripterror_h__ */