From 3f45ba68ae020cc21c383d0f148da213a36b62e2 Mon Sep 17 00:00:00 2001 From: "vidur%netscape.com" Date: Wed, 8 Sep 1999 23:16:49 +0000 Subject: [PATCH] Added nsIScriptContextOwner::ReportScriptError. git-svn-id: svn://10.0.0.236/trunk@46439 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 47 +++++++++++++++++++++++++++- mozilla/webshell/src/nsWebShell.cpp | 47 +++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 63df8965b7c..5fe8e40daa2 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -318,6 +318,10 @@ public: NS_IMETHOD GetScriptContext(nsIScriptContext **aContext); NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject **aGlobal); NS_IMETHOD ReleaseScriptContext(nsIScriptContext *aContext); + NS_IMETHOD ReportScriptError(const char* aErrorString, + const char* aFileName, + PRInt32 aLineNo, + const char* aLineBuf); #ifdef NECKO // nsIDocumentLoaderObserver @@ -746,7 +750,10 @@ nsWebShell::~nsWebShell() mScriptGlobal->SetWebShell(nsnull); NS_RELEASE(mScriptGlobal); } - NS_IF_RELEASE(mScriptContext); + if (nsnull != mScriptContext) { + mScriptContext->SetOwner(nsnull); + NS_RELEASE(mScriptContext); + } InitFrameData(PR_TRUE); mIsFrame = PR_FALSE; @@ -3303,6 +3310,9 @@ nsWebShell::CreateScriptEnvironment() if (nsnull == mScriptContext) { res = NS_CreateScriptContext(mScriptGlobal, &mScriptContext); + if (NS_SUCCEEDED(res)) { + mScriptContext->SetOwner(this); + } } return res; @@ -3348,6 +3358,41 @@ nsWebShell::ReleaseScriptContext(nsIScriptContext *aContext) return NS_OK; } +NS_IMETHODIMP +nsWebShell::ReportScriptError(const char* aErrorString, + const char* aFileName, + PRInt32 aLineNo, + const char* aLineBuf) +{ + // XXX To be implemented by scc. The following implementation + // is temporary. + + nsCAutoString error; + error.SetString(aErrorString); + error += "\n"; + + if (aFileName) { + error += "URL: "; + error += aFileName; + error += "\n"; + } + + if(aLineNo) { + error += "LineNo: "; + error.Append(aLineNo, 10); + error += "\n"; + } + + if(aLineBuf) { + error += "Line text: '"; + error += aLineBuf; + error += "'\n"; + } + + printf("JavaScript Error: %s\n", error.GetBuffer()); + + return NS_OK; +} NS_IMETHODIMP nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader, diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 63df8965b7c..5fe8e40daa2 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -318,6 +318,10 @@ public: NS_IMETHOD GetScriptContext(nsIScriptContext **aContext); NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject **aGlobal); NS_IMETHOD ReleaseScriptContext(nsIScriptContext *aContext); + NS_IMETHOD ReportScriptError(const char* aErrorString, + const char* aFileName, + PRInt32 aLineNo, + const char* aLineBuf); #ifdef NECKO // nsIDocumentLoaderObserver @@ -746,7 +750,10 @@ nsWebShell::~nsWebShell() mScriptGlobal->SetWebShell(nsnull); NS_RELEASE(mScriptGlobal); } - NS_IF_RELEASE(mScriptContext); + if (nsnull != mScriptContext) { + mScriptContext->SetOwner(nsnull); + NS_RELEASE(mScriptContext); + } InitFrameData(PR_TRUE); mIsFrame = PR_FALSE; @@ -3303,6 +3310,9 @@ nsWebShell::CreateScriptEnvironment() if (nsnull == mScriptContext) { res = NS_CreateScriptContext(mScriptGlobal, &mScriptContext); + if (NS_SUCCEEDED(res)) { + mScriptContext->SetOwner(this); + } } return res; @@ -3348,6 +3358,41 @@ nsWebShell::ReleaseScriptContext(nsIScriptContext *aContext) return NS_OK; } +NS_IMETHODIMP +nsWebShell::ReportScriptError(const char* aErrorString, + const char* aFileName, + PRInt32 aLineNo, + const char* aLineBuf) +{ + // XXX To be implemented by scc. The following implementation + // is temporary. + + nsCAutoString error; + error.SetString(aErrorString); + error += "\n"; + + if (aFileName) { + error += "URL: "; + error += aFileName; + error += "\n"; + } + + if(aLineNo) { + error += "LineNo: "; + error.Append(aLineNo, 10); + error += "\n"; + } + + if(aLineBuf) { + error += "Line text: '"; + error += aLineBuf; + error += "'\n"; + } + + printf("JavaScript Error: %s\n", error.GetBuffer()); + + return NS_OK; +} NS_IMETHODIMP nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader,