1998-07-16 01:16:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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/
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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.
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
*/
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nsJSEnvironment.h"
|
|
|
|
#include "nsIScriptObjectOwner.h"
|
1999-09-08 23:14:30 +00:00
|
|
|
#include "nsIScriptContextOwner.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
1999-12-03 09:24:22 +00:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
2000-09-01 01:54:35 +00:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMText.h"
|
1998-10-20 17:07:23 +00:00
|
|
|
#include "nsIDOMAttr.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nsIDOMNamedNodeMap.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
2000-02-16 06:59:07 +00:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
1998-09-11 18:05:11 +00:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
1999-05-04 20:48:16 +00:00
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
1998-11-21 00:12:33 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1998-12-22 22:03:20 +00:00
|
|
|
#include "nsIScriptNameSetRegistry.h"
|
|
|
|
#include "nsIScriptNameSpaceManager.h"
|
|
|
|
#include "nsDOMCID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-04-24 02:37:41 +00:00
|
|
|
#include "nsIXPConnect.h"
|
1999-08-19 20:36:31 +00:00
|
|
|
#include "nsIJSContextStack.h"
|
1999-09-05 00:43:39 +00:00
|
|
|
#include "nsIJSRuntimeService.h"
|
1999-12-03 03:40:30 +00:00
|
|
|
#include "nsIPref.h"
|
1999-08-29 21:58:42 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-12-18 20:29:29 +00:00
|
|
|
#include "nsJSUtils.h"
|
2000-04-24 04:41:27 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
2000-06-24 16:18:41 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIPrompt.h"
|
2000-06-20 03:45:21 +00:00
|
|
|
#include "nsIObserverService.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
// Force PR_LOGGING so we can get JS strict warnings even in release builds
|
|
|
|
#define FORCE_PR_LOG 1
|
|
|
|
#include "prlog.h"
|
2000-05-15 04:21:04 +00:00
|
|
|
#include "prthread.h"
|
1999-12-03 03:40:30 +00:00
|
|
|
|
1999-02-25 04:29:08 +00:00
|
|
|
#include "nsIJVMManager.h"
|
|
|
|
#include "nsILiveConnectManager.h"
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
const size_t gStackSize = 8192;
|
|
|
|
|
1998-12-22 22:03:20 +00:00
|
|
|
static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID);
|
1999-12-03 03:40:30 +00:00
|
|
|
static NS_DEFINE_IID(kPrefServiceCID, NS_PREF_CID);
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gJSDiagnostics = nsnull;
|
|
|
|
#endif
|
1998-07-16 01:16:47 +00:00
|
|
|
|
2000-04-15 01:56:47 +00:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
|
1998-08-12 04:56:40 +00:00
|
|
|
void PR_CALLBACK
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_ScriptErrorReporter(JSContext *cx,
|
|
|
|
const char *message,
|
1999-09-08 23:14:30 +00:00
|
|
|
JSErrorReport *report)
|
1998-08-12 04:56:40 +00:00
|
|
|
{
|
1999-12-18 20:29:29 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> context;
|
2000-04-24 04:41:27 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
1999-09-08 23:14:30 +00:00
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
// XXX this means we are not going to get error reports on non DOM contexts
|
|
|
|
nsJSUtils::nsGetDynamicScriptContext(cx, getter_AddRefs(context));
|
|
|
|
if (context) {
|
2000-06-20 03:51:07 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject( dont_AddRef( context->GetGlobalObject() ) );
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
if (globalObject) {
|
|
|
|
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
|
|
|
|
if(NS_FAILED(globalObject->GetGlobalObjectOwner(getter_AddRefs(owner))) ||
|
|
|
|
!owner) {
|
|
|
|
NS_WARN_IF_FALSE(PR_FALSE, "Failed to get a global Object Owner");
|
|
|
|
return;
|
|
|
|
}
|
2000-04-15 01:56:47 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
//send error event first, then proceed
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
globalObject->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
if (docShell) {
|
2000-08-21 08:44:55 +00:00
|
|
|
static PRInt32 errorDepth = 0; // Recursion prevention
|
|
|
|
errorDepth++;
|
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
2000-08-21 08:44:55 +00:00
|
|
|
|
|
|
|
if(presContext && errorDepth < 2) {
|
2000-04-24 04:41:27 +00:00
|
|
|
nsEvent errorevent;
|
|
|
|
errorevent.eventStructType = NS_EVENT;
|
|
|
|
errorevent.message = NS_SCRIPT_ERROR;
|
|
|
|
|
2000-08-21 08:44:55 +00:00
|
|
|
// HandleDOMEvent() must be synchronous for the recursion block
|
|
|
|
// (errorDepth) to work.
|
2000-04-24 04:41:27 +00:00
|
|
|
globalObject->HandleDOMEvent(presContext, &errorevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
2000-08-21 08:44:55 +00:00
|
|
|
|
|
|
|
errorDepth--;
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
|
|
|
|
// Make an nsIScriptError and populate it with information from
|
|
|
|
// this error.
|
|
|
|
nsCOMPtr<nsIScriptError>
|
2000-09-13 23:57:52 +00:00
|
|
|
errorObject(do_CreateInstance("@mozilla.org/scripterror;1"));
|
2000-04-24 04:41:27 +00:00
|
|
|
|
|
|
|
// XXX possible here to distinguish between XUL and content js?
|
|
|
|
// or could just expose setCategory and twiddle it later.
|
|
|
|
const char *category = "XUL/Content JavaScript";
|
|
|
|
|
|
|
|
if (errorObject != nsnull) {
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (report) {
|
|
|
|
nsAutoString fileUni;
|
|
|
|
fileUni.AssignWithConversion(report->filename);
|
|
|
|
const PRUnichar *newFileUni = fileUni.ToNewUnicode();
|
|
|
|
PRUint32 column = report->uctokenptr - report->uclinebuf;
|
2000-06-12 23:52:31 +00:00
|
|
|
rv = errorObject->Init(NS_REINTERPRET_CAST(const PRUnichar*, report->ucmessage), newFileUni,
|
|
|
|
NS_REINTERPRET_CAST(const PRUnichar*, report->uclinebuf), report->lineno,
|
2000-04-24 04:41:27 +00:00
|
|
|
column, report->flags, category);
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free((void *)newFileUni);
|
2000-04-24 04:41:27 +00:00
|
|
|
} else if (message) {
|
|
|
|
nsAutoString messageUni;
|
|
|
|
messageUni.AssignWithConversion(message);
|
|
|
|
const PRUnichar *newMessageUni = messageUni.ToNewUnicode();
|
|
|
|
rv = errorObject->Init(newMessageUni, nsnull, nsnull,
|
|
|
|
0, 0, 0, category);
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free((void *)newMessageUni);
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
owner->ReportScriptError(errorObject);
|
2000-04-15 01:56:47 +00:00
|
|
|
}
|
1999-12-18 20:29:29 +00:00
|
|
|
}
|
1999-09-08 23:14:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-15 01:56:47 +00:00
|
|
|
// Print it to stderr as well, for the benefit of those invoking
|
|
|
|
// mozilla with -console.
|
|
|
|
nsAutoString error;
|
2000-04-15 19:03:12 +00:00
|
|
|
error.AssignWithConversion("JavaScript ");
|
2000-09-01 03:10:33 +00:00
|
|
|
if (JSREPORT_IS_STRICT(report->flags))
|
|
|
|
error.AppendWithConversion("strict ");
|
2000-04-15 19:03:12 +00:00
|
|
|
error.AppendWithConversion(JSREPORT_IS_WARNING(report->flags) ? "warning: " : "error: ");
|
|
|
|
error.AppendWithConversion("\n");
|
|
|
|
error.AppendWithConversion(report->filename);
|
|
|
|
error.AppendWithConversion(" line ");
|
|
|
|
error.AppendInt(report->lineno, 10);
|
|
|
|
error.AppendWithConversion(": ");
|
2000-06-12 23:52:31 +00:00
|
|
|
error.Append(NS_REINTERPRET_CAST(const PRUnichar*, report->ucmessage));
|
2000-04-15 19:03:12 +00:00
|
|
|
error.AppendWithConversion("\n");
|
2000-04-24 04:41:27 +00:00
|
|
|
if (status != nsEventStatus_eIgnore)
|
|
|
|
error.AppendWithConversion("Error was suppressed by event handler\n");
|
2000-04-15 01:56:47 +00:00
|
|
|
|
|
|
|
char *errorStr = error.ToNewCString();
|
|
|
|
if (errorStr) {
|
|
|
|
fprintf(stderr, "%s\n", errorStr);
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(errorStr);
|
2000-04-15 01:56:47 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (report) {
|
|
|
|
if (!gJSDiagnostics)
|
|
|
|
gJSDiagnostics = PR_NewLogModule("JSDiagnostics");
|
|
|
|
|
|
|
|
if (gJSDiagnostics) {
|
|
|
|
PR_LOG(gJSDiagnostics,
|
|
|
|
JSREPORT_IS_WARNING(report->flags) ? PR_LOG_WARNING : PR_LOG_ERROR,
|
|
|
|
("file %s, line %u: %s\n%s%s",
|
|
|
|
report->filename, report->lineno, message,
|
|
|
|
report->linebuf ? report->linebuf : "",
|
|
|
|
(report->linebuf &&
|
|
|
|
report->linebuf[strlen(report->linebuf)-1] != '\n')
|
|
|
|
? "\n"
|
|
|
|
: ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
// XXX do we really want to be doing this?
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_ClearPendingException(cx);
|
1998-08-12 04:56:40 +00:00
|
|
|
}
|
|
|
|
|
2000-06-24 16:18:41 +00:00
|
|
|
#define MAYBE_GC_BRANCH_COUNT_MASK 0x00000fff // 4095
|
|
|
|
#define MAYBE_STOP_BRANCH_COUNT_MASK 0x003fffff
|
|
|
|
|
|
|
|
JSBool PR_CALLBACK
|
|
|
|
nsJSContext::DOMBranchCallback(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
// Get the native context
|
|
|
|
nsJSContext *ctx = (nsJSContext *)::JS_GetContextPrivate(cx);
|
|
|
|
NS_ENSURE_TRUE(ctx, JS_TRUE);
|
|
|
|
|
|
|
|
// Filter out most of the calls to this callback
|
|
|
|
if (++ctx->mBranchCallbackCount & MAYBE_GC_BRANCH_COUNT_MASK)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
// Run the GC if we get this far.
|
|
|
|
JS_MaybeGC(cx);
|
|
|
|
|
|
|
|
// Filter out most of the calls to this callback that make it this far
|
|
|
|
if (ctx->mBranchCallbackCount & MAYBE_STOP_BRANCH_COUNT_MASK)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
// If we get here we're most likely executing an infinite loop in JS,
|
|
|
|
// we'll tell the user about this and we'll give the user the option
|
|
|
|
// of stopping the execution of the script.
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global(dont_AddRef(ctx->GetGlobalObject()));
|
|
|
|
NS_ENSURE_TRUE(global, JS_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
global->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
NS_ENSURE_TRUE(docShell, JS_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> ireq(do_QueryInterface(docShell));
|
|
|
|
NS_ENSURE_TRUE(ireq, JS_TRUE);
|
|
|
|
|
|
|
|
// Get the nsIPrompt interface from the docshell
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
|
|
|
ireq->GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(prompt));
|
|
|
|
NS_ENSURE_TRUE(prompt, JS_TRUE);
|
|
|
|
|
|
|
|
nsAutoString title, msg;
|
|
|
|
title.AssignWithConversion("Script warning");
|
|
|
|
msg.AssignWithConversion("A script on this page is causing mozilla to "
|
|
|
|
"run slowly. If it continues to run, your "
|
|
|
|
"computer may become unresponsive.\n\nDo you "
|
|
|
|
"want to abort the script?");
|
|
|
|
|
|
|
|
JSBool ret = JS_TRUE;
|
|
|
|
|
|
|
|
// Open the dialog.
|
|
|
|
if (NS_FAILED(prompt->Confirm(title.GetUnicode(), msg.GetUnicode(), &ret)))
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
return !ret;
|
|
|
|
}
|
|
|
|
|
2000-09-02 01:58:51 +00:00
|
|
|
#define JS_OPTIONS_DOT_STR "javascript.options."
|
|
|
|
|
|
|
|
static const char js_options_dot_str[] = JS_OPTIONS_DOT_STR;
|
|
|
|
static const char js_strict_option_str[] = JS_OPTIONS_DOT_STR "strict";
|
|
|
|
static const char js_werror_option_str[] = JS_OPTIONS_DOT_STR "werror";
|
|
|
|
|
|
|
|
int PR_CALLBACK
|
|
|
|
nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsJSContext *context = NS_REINTERPRET_CAST(nsJSContext *, data);
|
|
|
|
PRUint32 oldDefaultJSOptions = context->mDefaultJSOptions;
|
|
|
|
PRUint32 newDefaultJSOptions = oldDefaultJSOptions;
|
|
|
|
|
|
|
|
PRBool strict;
|
|
|
|
if (NS_SUCCEEDED(prefs->GetBoolPref(js_strict_option_str, &strict))) {
|
|
|
|
if (strict)
|
|
|
|
newDefaultJSOptions |= JSOPTION_STRICT;
|
|
|
|
else
|
|
|
|
newDefaultJSOptions &= ~JSOPTION_STRICT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool werror;
|
|
|
|
if (NS_SUCCEEDED(prefs->GetBoolPref(js_werror_option_str, &werror))) {
|
|
|
|
if (werror)
|
|
|
|
newDefaultJSOptions |= JSOPTION_WERROR;
|
|
|
|
else
|
|
|
|
newDefaultJSOptions &= ~JSOPTION_WERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newDefaultJSOptions != oldDefaultJSOptions) {
|
|
|
|
// Set options only if we used the old defaults; otherwise the page has
|
|
|
|
// customized some via the options object and we defer to its wisdom.
|
|
|
|
if (::JS_GetOptions(context->mContext) == oldDefaultJSOptions)
|
|
|
|
::JS_SetOptions(context->mContext, newDefaultJSOptions);
|
|
|
|
|
|
|
|
// Save the new defaults for the next page load (InitContext).
|
|
|
|
context->mDefaultJSOptions = newDefaultJSOptions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsJSContext::nsJSContext(JSRuntime *aRuntime)
|
|
|
|
{
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_INIT_REFCNT();
|
2000-08-26 23:32:56 +00:00
|
|
|
mRootedScriptObject = nsnull;
|
2000-09-07 10:51:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mDefaultJSOptions = JSOPTION_STRICT; // lint catching for development
|
|
|
|
#else
|
2000-09-02 01:58:51 +00:00
|
|
|
mDefaultJSOptions = 0;
|
2000-09-07 10:51:59 +00:00
|
|
|
#endif
|
2000-01-08 00:24:24 +00:00
|
|
|
mContext = ::JS_NewContext(aRuntime, gStackSize);
|
1999-12-03 03:40:30 +00:00
|
|
|
if (mContext) {
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_SetContextPrivate(mContext, (void *)this);
|
1999-12-03 03:40:30 +00:00
|
|
|
|
|
|
|
// Check for the JS strict option, which enables extra error checks
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-09-02 01:58:51 +00:00
|
|
|
(void) prefs->RegisterCallback(js_options_dot_str,
|
|
|
|
JSOptionChangedCallback,
|
|
|
|
this);
|
|
|
|
(void) JSOptionChangedCallback(js_options_dot_str, this);
|
1999-12-03 03:40:30 +00:00
|
|
|
}
|
2000-06-24 16:18:41 +00:00
|
|
|
|
|
|
|
::JS_SetBranchCallback(mContext, DOMBranchCallback);
|
1999-12-03 03:40:30 +00:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mIsInitialized = PR_FALSE;
|
|
|
|
mNumEvaluations = 0;
|
1999-09-08 23:14:30 +00:00
|
|
|
mSecurityManager = nsnull;
|
|
|
|
mOwner = nsnull;
|
1999-10-28 14:12:56 +00:00
|
|
|
mTerminationFunc = nsnull;
|
2000-03-28 00:15:56 +00:00
|
|
|
mScriptsEnabled = PR_TRUE;
|
2000-06-24 16:18:41 +00:00
|
|
|
mBranchCallbackCount = 0;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
const char kScriptSecurityManagerContractID[] = NS_SCRIPTSECURITYMANAGER_CONTRACTID;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsJSContext::~nsJSContext()
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (mSecurityManager) {
|
2000-09-13 23:57:52 +00:00
|
|
|
nsServiceManager::ReleaseService(kScriptSecurityManagerContractID,
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mSecurityManager);
|
|
|
|
mSecurityManager = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cope with JS_NewContext failure in ctor (XXXbe move NewContext to Init?)
|
|
|
|
if (!mContext)
|
|
|
|
return;
|
|
|
|
|
2000-09-02 01:58:51 +00:00
|
|
|
// Unregister our "javascript.options.*" pref-changed callback.
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
(void) prefs->UnregisterCallback(js_options_dot_str,
|
|
|
|
JSOptionChangedCallback,
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
2000-08-26 23:32:56 +00:00
|
|
|
// if we were handed an object to remember to unroot now, do it
|
|
|
|
if (mRootedScriptObject)
|
|
|
|
::JS_RemoveRoot(mContext, &mRootedScriptObject);
|
|
|
|
|
1999-12-17 00:08:28 +00:00
|
|
|
/* Remove global object reference to window object, so it can be collected. */
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_SetGlobalObject(mContext, nsnull);
|
|
|
|
::JS_DestroyContext(mContext);
|
1999-12-18 20:29:29 +00:00
|
|
|
|
|
|
|
// Let xpconnect resync its JSContext tracker (this is optional)
|
|
|
|
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
xpc->SyncJSContexts();
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSContext, NS_GET_IID(nsIScriptContext));
|
1998-07-16 01:16:47 +00:00
|
|
|
|
2000-03-29 01:18:21 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsJSContext::EvaluateStringWithValue(const nsAReadableString& aScript,
|
2000-03-29 01:18:21 +00:00
|
|
|
void *aScopeObject,
|
|
|
|
nsIPrincipal *aPrincipal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
const char* aVersion,
|
|
|
|
void* aRetValue,
|
|
|
|
PRBool* aIsUndefined)
|
|
|
|
{
|
2000-05-12 02:06:07 +00:00
|
|
|
// Beware that the result is not rooted! Be very careful not to run
|
|
|
|
// the GC before rooting the result somehow!
|
2000-03-29 01:18:21 +00:00
|
|
|
if (!mScriptsEnabled) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (!aScopeObject)
|
|
|
|
aScopeObject = ::JS_GetGlobalObject(mContext);
|
|
|
|
|
|
|
|
// Safety first: get an object representing the script's principals, i.e.,
|
|
|
|
// the entities who signed this script, or the fully-qualified-domain-name
|
|
|
|
// or "codebase" from which it was loaded.
|
|
|
|
JSPrincipals *jsprin;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = aPrincipal;
|
|
|
|
if (aPrincipal) {
|
|
|
|
aPrincipal->GetJSPrincipals(&jsprin);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global = dont_AddRef(GetGlobalObject());
|
|
|
|
if (!global)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
rv = objPrincipal->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
principal->GetJSPrincipals(&jsprin);
|
|
|
|
}
|
|
|
|
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
|
|
|
|
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
rv = GetSecurityManager(getter_AddRefs(securityManager));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = securityManager->CanExecuteScripts(principal, &ok);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push our JSContext on the current thread's context stack so JS called
|
|
|
|
// from native code via XPConnect uses the right context. Do this whether
|
|
|
|
// or not the SecurityManager said "ok", in order to simplify control flow
|
|
|
|
// below where we pop before returning.
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1", &rv);
|
2000-03-29 01:18:21 +00:00
|
|
|
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The result of evaluation, used only if there were no errors. This need
|
|
|
|
// not be a GC root currently, provided we run the GC only from the branch
|
|
|
|
// callback or from ScriptEvaluated. TODO: use JS_Begin/EndRequest to keep
|
|
|
|
// the GC from racing with JS execution on any thread.
|
|
|
|
jsval val;
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
JSVersion newVersion;
|
|
|
|
|
|
|
|
// SecurityManager said "ok", but don't execute if aVersion is specified
|
|
|
|
// and unknown. Do execute with the default version (and avoid thrashing
|
|
|
|
// the context's version) if aVersion is not specified.
|
|
|
|
ok = (!aVersion ||
|
|
|
|
(newVersion = ::JS_StringToVersion(aVersion)) != JSVERSION_UNKNOWN);
|
|
|
|
if (ok) {
|
|
|
|
JSVersion oldVersion;
|
|
|
|
|
|
|
|
if (aVersion)
|
|
|
|
oldVersion = ::JS_SetVersion(mContext, newVersion);
|
|
|
|
mRef = nsnull;
|
|
|
|
mTerminationFunc = nsnull;
|
|
|
|
ok = ::JS_EvaluateUCScriptForPrincipals(mContext,
|
|
|
|
(JSObject *)aScopeObject,
|
|
|
|
jsprin,
|
2000-09-13 03:24:57 +00:00
|
|
|
(jschar*)(const PRUnichar*)nsPromiseFlatString(aScript).get(),
|
2000-03-29 01:18:21 +00:00
|
|
|
aScript.Length(),
|
|
|
|
aURL,
|
|
|
|
aLineNo,
|
|
|
|
&val);
|
|
|
|
if (aVersion)
|
|
|
|
::JS_SetVersion(mContext, oldVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whew! Finally done with these manually ref-counted things.
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
|
|
|
|
// If all went well, convert val to a string (XXXbe unless undefined?).
|
|
|
|
if (ok) {
|
|
|
|
if (aIsUndefined) *aIsUndefined = JSVAL_IS_VOID(val);
|
|
|
|
*NS_STATIC_CAST(jsval*, aRetValue) = val;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aIsUndefined) *aIsUndefined = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop here, after JS_ValueToString and any other possible evaluation.
|
|
|
|
if (NS_FAILED(stack->Pop(nsnull)))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-15 20:58:41 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsJSContext::EvaluateString(const nsAReadableString& aScript,
|
1999-12-07 22:14:17 +00:00
|
|
|
void *aScopeObject,
|
1999-11-12 06:08:14 +00:00
|
|
|
nsIPrincipal *aPrincipal,
|
1999-09-15 20:58:41 +00:00
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
const char* aVersion,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsAWritableString& aRetValue,
|
1999-09-15 20:58:41 +00:00
|
|
|
PRBool* aIsUndefined)
|
|
|
|
{
|
2000-03-28 00:15:56 +00:00
|
|
|
if (!mScriptsEnabled) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
aRetValue.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-29 21:58:42 +00:00
|
|
|
nsresult rv;
|
1999-12-07 22:14:17 +00:00
|
|
|
if (!aScopeObject)
|
2000-01-08 00:24:24 +00:00
|
|
|
aScopeObject = ::JS_GetGlobalObject(mContext);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
|
|
|
// Safety first: get an object representing the script's principals, i.e.,
|
|
|
|
// the entities who signed this script, or the fully-qualified-domain-name
|
|
|
|
// or "codebase" from which it was loaded.
|
1999-08-29 21:58:42 +00:00
|
|
|
JSPrincipals *jsprin;
|
1999-11-12 06:08:14 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = aPrincipal;
|
|
|
|
if (aPrincipal) {
|
|
|
|
aPrincipal->GetJSPrincipals(&jsprin);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-12-17 00:08:28 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global = dont_AddRef(GetGlobalObject());
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (!global)
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-26 15:33:57 +00:00
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv))
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-26 15:33:57 +00:00
|
|
|
rv = objPrincipal->GetPrincipal(getter_AddRefs(principal));
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 06:08:14 +00:00
|
|
|
principal->GetJSPrincipals(&jsprin);
|
1999-09-17 20:13:52 +00:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
|
|
|
|
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
rv = GetSecurityManager(getter_AddRefs(securityManager));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-11-12 06:08:14 +00:00
|
|
|
rv = securityManager->CanExecuteScripts(principal, &ok);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push our JSContext on the current thread's context stack so JS called
|
|
|
|
// from native code via XPConnect uses the right context. Do this whether
|
|
|
|
// or not the SecurityManager said "ok", in order to simplify control flow
|
|
|
|
// below where we pop before returning.
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1", &rv);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
|
|
|
// The result of evaluation, used only if there were no errors. This need
|
|
|
|
// not be a GC root currently, provided we run the GC only from the branch
|
|
|
|
// callback or from ScriptEvaluated. TODO: use JS_Begin/EndRequest to keep
|
|
|
|
// the GC from racing with JS execution on any thread.
|
|
|
|
jsval val;
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
JSVersion newVersion;
|
|
|
|
|
|
|
|
// SecurityManager said "ok", but don't execute if aVersion is specified
|
|
|
|
// and unknown. Do execute with the default version (and avoid thrashing
|
|
|
|
// the context's version) if aVersion is not specified.
|
1999-11-16 01:15:05 +00:00
|
|
|
ok = (!aVersion ||
|
2000-01-08 00:24:24 +00:00
|
|
|
(newVersion = ::JS_StringToVersion(aVersion)) != JSVERSION_UNKNOWN);
|
1999-11-16 01:15:05 +00:00
|
|
|
if (ok) {
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
JSVersion oldVersion;
|
|
|
|
|
|
|
|
if (aVersion)
|
2000-01-08 00:24:24 +00:00
|
|
|
oldVersion = ::JS_SetVersion(mContext, newVersion);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mRef = nsnull;
|
|
|
|
mTerminationFunc = nsnull;
|
|
|
|
ok = ::JS_EvaluateUCScriptForPrincipals(mContext,
|
1999-12-07 22:14:17 +00:00
|
|
|
(JSObject *)aScopeObject,
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
jsprin,
|
2000-09-13 03:24:57 +00:00
|
|
|
(jschar*)(const PRUnichar*)nsPromiseFlatString(aScript).get(),
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
aScript.Length(),
|
|
|
|
aURL,
|
|
|
|
aLineNo,
|
|
|
|
&val);
|
|
|
|
if (aVersion)
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_SetVersion(mContext, oldVersion);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whew! Finally done with these manually ref-counted things.
|
1999-08-29 21:58:42 +00:00
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
|
|
|
// If all went well, convert val to a string (XXXbe unless undefined?).
|
|
|
|
if (ok) {
|
2000-03-28 00:15:56 +00:00
|
|
|
if (aIsUndefined) *aIsUndefined = JSVAL_IS_VOID(val);
|
2000-01-08 00:24:24 +00:00
|
|
|
JSString* jsstring = ::JS_ValueToString(mContext, val);
|
1999-11-12 06:08:14 +00:00
|
|
|
if (jsstring)
|
2000-06-12 23:52:31 +00:00
|
|
|
aRetValue.Assign(NS_REINTERPRET_CAST(const PRUnichar*, ::JS_GetStringChars(jsstring)));
|
1999-11-12 06:08:14 +00:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
1999-08-19 20:36:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-03-28 00:15:56 +00:00
|
|
|
if (aIsUndefined) *aIsUndefined = PR_TRUE;
|
1999-08-19 20:36:31 +00:00
|
|
|
aRetValue.Truncate();
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2000-09-15 06:17:08 +00:00
|
|
|
ScriptEvaluated(PR_TRUE);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
|
|
|
// Pop here, after JS_ValueToString and any other possible evaluation.
|
|
|
|
if (NS_FAILED(stack->Pop(nsnull)))
|
1999-11-12 06:08:14 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::CompileScript(const PRUnichar* aText,
|
|
|
|
PRInt32 aTextLength,
|
|
|
|
void *aScopeObject,
|
|
|
|
nsIPrincipal *aPrincipal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
const char* aVersion,
|
|
|
|
void** aScriptObject)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrincipal);
|
|
|
|
|
|
|
|
if (!aScopeObject)
|
2000-01-08 00:24:24 +00:00
|
|
|
aScopeObject = ::JS_GetGlobalObject(mContext);
|
1999-11-12 06:08:14 +00:00
|
|
|
|
|
|
|
JSPrincipals *jsprin;
|
|
|
|
aPrincipal->GetJSPrincipals(&jsprin);
|
|
|
|
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
|
|
|
|
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
rv = GetSecurityManager(getter_AddRefs(securityManager));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = securityManager->CanExecuteScripts(aPrincipal, &ok);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aScriptObject = nsnull;
|
|
|
|
if (ok) {
|
|
|
|
JSVersion newVersion;
|
|
|
|
|
|
|
|
// SecurityManager said "ok", but don't compile if aVersion is specified
|
|
|
|
// and unknown. Do compile with the default version (and avoid thrashing
|
|
|
|
// the context's version) if aVersion is not specified.
|
|
|
|
if (!aVersion ||
|
2000-01-08 00:24:24 +00:00
|
|
|
(newVersion = ::JS_StringToVersion(aVersion)) != JSVERSION_UNKNOWN) {
|
1999-11-12 06:08:14 +00:00
|
|
|
JSVersion oldVersion;
|
|
|
|
if (aVersion)
|
2000-01-08 00:24:24 +00:00
|
|
|
oldVersion = ::JS_SetVersion(mContext, newVersion);
|
1999-11-12 06:08:14 +00:00
|
|
|
|
|
|
|
JSScript* script =
|
|
|
|
::JS_CompileUCScriptForPrincipals(mContext,
|
|
|
|
(JSObject*) aScopeObject,
|
|
|
|
jsprin,
|
|
|
|
(jschar*) aText,
|
|
|
|
aTextLength,
|
|
|
|
aURL,
|
|
|
|
aLineNo);
|
|
|
|
if (script) {
|
|
|
|
*aScriptObject = (void*) ::JS_NewScriptObject(mContext, script);
|
|
|
|
if (! *aScriptObject) {
|
|
|
|
::JS_DestroyScript(mContext, script);
|
|
|
|
script = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!script)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (aVersion)
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_SetVersion(mContext, oldVersion);
|
1999-11-12 06:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whew! Finally done with these manually ref-counted things.
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::ExecuteScript(void* aScriptObject,
|
|
|
|
void *aScopeObject,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsAWritableString* aRetValue,
|
1999-11-12 06:08:14 +00:00
|
|
|
PRBool* aIsUndefined)
|
|
|
|
{
|
2000-03-28 00:15:56 +00:00
|
|
|
if (!mScriptsEnabled) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
aRetValue->Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 06:08:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!aScopeObject)
|
2000-01-08 00:24:24 +00:00
|
|
|
aScopeObject = ::JS_GetGlobalObject(mContext);
|
1999-11-12 06:08:14 +00:00
|
|
|
|
|
|
|
// Push our JSContext on our thread's context stack, in case native code
|
|
|
|
// called from JS calls back into JS via XPConnect.
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1", &rv);
|
1999-11-12 06:08:14 +00:00
|
|
|
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
|
1999-08-29 21:58:42 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 06:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The result of evaluation, used only if there were no errors. This need
|
|
|
|
// not be a GC root currently, provided we run the GC only from the branch
|
|
|
|
// callback or from ScriptEvaluated. TODO: use JS_Begin/EndRequest to keep
|
|
|
|
// the GC from racing with JS execution on any thread.
|
|
|
|
jsval val;
|
|
|
|
JSBool ok;
|
|
|
|
|
|
|
|
mRef = nsnull;
|
|
|
|
mTerminationFunc = nsnull;
|
|
|
|
ok = ::JS_ExecuteScript(mContext,
|
1999-12-03 03:40:30 +00:00
|
|
|
(JSObject*) aScopeObject,
|
2000-01-08 00:24:24 +00:00
|
|
|
(JSScript*) ::JS_GetPrivate(mContext,
|
1999-12-03 03:40:30 +00:00
|
|
|
(JSObject*)aScriptObject),
|
|
|
|
&val);
|
1999-11-12 06:08:14 +00:00
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
// If all went well, convert val to a string (XXXbe unless undefined?).
|
|
|
|
if (aIsUndefined)
|
|
|
|
*aIsUndefined = JSVAL_IS_VOID(val);
|
|
|
|
if (aRetValue) {
|
2000-01-08 00:24:24 +00:00
|
|
|
JSString* jsstring = ::JS_ValueToString(mContext, val);
|
1999-11-12 06:08:14 +00:00
|
|
|
if (jsstring)
|
2000-06-12 23:52:31 +00:00
|
|
|
aRetValue->Assign(NS_REINTERPRET_CAST(const PRUnichar*, ::JS_GetStringChars(jsstring)));
|
1999-11-12 06:08:14 +00:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aIsUndefined)
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
if (aRetValue)
|
|
|
|
aRetValue->Truncate();
|
|
|
|
}
|
|
|
|
|
2000-09-15 06:17:08 +00:00
|
|
|
ScriptEvaluated(PR_TRUE);
|
1999-11-12 06:08:14 +00:00
|
|
|
|
|
|
|
// Pop here, after JS_ValueToString and any other possible evaluation.
|
|
|
|
if (NS_FAILED(stack->Pop(nsnull)))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
1999-08-29 21:58:42 +00:00
|
|
|
|
1999-11-12 06:08:14 +00:00
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
const char *gEventArgv[] = {"event"};
|
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
void
|
|
|
|
AtomToEventHandlerName(nsIAtom *aName, char *charName, PRUint32 charNameSize)
|
|
|
|
{
|
|
|
|
// optimized to avoid ns*Str*.h explicit/implicit copying and malloc'ing
|
|
|
|
// even nsCAutoString may call an Append that copy-constructs an nsStr from
|
|
|
|
// a const PRUnichar*
|
|
|
|
const PRUnichar *name;
|
|
|
|
aName->GetUnicode(&name);
|
|
|
|
char c;
|
|
|
|
PRUint32 i = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
NS_ASSERTION(name[i] < 128, "non-ASCII event handler name");
|
|
|
|
c = char(name[i]);
|
|
|
|
|
|
|
|
// The HTML content sink must have folded to lowercase already.
|
1999-12-03 06:11:54 +00:00
|
|
|
NS_ASSERTION(c == '\0' || ('a' <= c && c <= 'z'), "non-alphabetic event handler name");
|
1999-12-03 03:40:30 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(i < charNameSize, "overlong event handler name");
|
|
|
|
charName[i++] = c;
|
|
|
|
} while (c != '\0');
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName,
|
|
|
|
const nsAReadableString& aBody,
|
2000-01-08 00:24:24 +00:00
|
|
|
PRBool aShared, void** aHandler)
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
{
|
|
|
|
JSPrincipals *jsprin = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global = getter_AddRefs(GetGlobalObject());
|
|
|
|
if (global) {
|
|
|
|
// XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func?
|
2000-01-26 15:33:57 +00:00
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (globalData) {
|
|
|
|
nsCOMPtr<nsIPrincipal> prin;
|
|
|
|
if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(prin))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
prin->GetJSPrincipals(&jsprin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
char charName[64];
|
|
|
|
AtomToEventHandlerName(aName, charName, sizeof charName);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2000-01-08 00:24:24 +00:00
|
|
|
JSObject *target = (JSObject*)aTarget;
|
1999-12-07 22:14:17 +00:00
|
|
|
JSFunction* fun =
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_CompileUCFunctionForPrincipals(mContext, target, jsprin,
|
|
|
|
charName, 1, gEventArgv,
|
2000-09-13 03:24:57 +00:00
|
|
|
(jschar*)(const PRUnichar*)nsPromiseFlatString(aBody).get(),
|
2000-01-08 00:24:24 +00:00
|
|
|
aBody.Length(),
|
|
|
|
//XXXbe filename, lineno:
|
|
|
|
nsnull, 0);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
|
|
|
if (jsprin)
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
1999-12-03 03:40:30 +00:00
|
|
|
if (!fun)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-12-17 00:08:28 +00:00
|
|
|
|
2000-01-08 00:24:24 +00:00
|
|
|
JSObject *handler = ::JS_GetFunctionObject(fun);
|
|
|
|
if (aHandler)
|
|
|
|
*aHandler = (void*) handler;
|
2000-01-06 00:39:18 +00:00
|
|
|
|
2000-01-08 00:24:24 +00:00
|
|
|
if (aShared) {
|
|
|
|
/* Break scope link to avoid entraining shared compilation scope. */
|
|
|
|
::JS_SetParent(mContext, handler, nsnull);
|
2000-01-06 00:39:18 +00:00
|
|
|
}
|
1999-12-03 03:40:30 +00:00
|
|
|
return NS_OK;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
|
2000-03-29 01:18:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::CompileFunction(void* aTarget,
|
|
|
|
const nsCString& aName,
|
|
|
|
PRUint32 aArgCount,
|
|
|
|
const char** aArgArray,
|
2000-08-23 17:27:06 +00:00
|
|
|
const nsAReadableString& aBody,
|
2000-03-29 01:18:21 +00:00
|
|
|
const char* aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
PRBool aShared,
|
|
|
|
void** aFunctionObject)
|
|
|
|
{
|
|
|
|
JSPrincipals *jsprin = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global = getter_AddRefs(GetGlobalObject());
|
|
|
|
if (global) {
|
|
|
|
// XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func?
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);
|
|
|
|
if (globalData) {
|
|
|
|
nsCOMPtr<nsIPrincipal> prin;
|
|
|
|
if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(prin))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
prin->GetJSPrincipals(&jsprin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *target = (JSObject*)aTarget;
|
|
|
|
JSFunction* fun =
|
|
|
|
::JS_CompileUCFunctionForPrincipals(mContext, target, jsprin,
|
|
|
|
aName, aArgCount, aArgArray,
|
2000-09-13 03:24:57 +00:00
|
|
|
(jschar*)(const PRUnichar*)nsPromiseFlatString(aBody).get(),
|
2000-03-29 01:18:21 +00:00
|
|
|
aBody.Length(),
|
|
|
|
aURL, aLineNo);
|
|
|
|
|
|
|
|
if (jsprin)
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
if (!fun)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
JSObject *handler = ::JS_GetFunctionObject(fun);
|
|
|
|
if (aFunctionObject)
|
|
|
|
*aFunctionObject = (void*) handler;
|
|
|
|
|
|
|
|
// Prevent entraining just like CompileEventHandler does?
|
|
|
|
if (aShared) {
|
|
|
|
/* Break scope link to avoid entraining shared compilation scope. */
|
|
|
|
::JS_SetParent(mContext, handler, nsnull);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 20:13:52 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-07 22:14:17 +00:00
|
|
|
nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc,
|
2000-04-24 04:41:27 +00:00
|
|
|
void *argv, PRBool *aBoolResult, PRBool aReverseReturnResult)
|
1999-09-17 20:13:52 +00:00
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
// This one's a lot easier than EvaluateString because we don't have to
|
|
|
|
// hassle with principals: they're already compiled into the JS function.
|
1999-09-17 20:13:52 +00:00
|
|
|
nsresult rv;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
rv = GetSecurityManager(getter_AddRefs(securityManager));
|
|
|
|
if (NS_FAILED(rv))
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1", &rv);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext)))
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-12-07 02:39:17 +00:00
|
|
|
// this context can be deleted unexpectedly if the JS closes
|
|
|
|
// the owning window. we ran into this problem specifically
|
|
|
|
// when going through the "close window" key event handler
|
|
|
|
// (that is, hitting ^W on Windows). the addref just below
|
|
|
|
// prevents our untimely destruction.
|
1999-12-09 21:44:16 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> kungFuDeathGrip(this);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mRef = nsnull;
|
1999-10-28 14:12:56 +00:00
|
|
|
mTerminationFunc = nsnull;
|
|
|
|
|
2000-06-21 00:21:50 +00:00
|
|
|
// check if the event handler can be run on the object in question
|
|
|
|
rv = securityManager->CheckFunctionAccess(mContext, aHandler, aTarget);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
jsval val;
|
2000-04-14 03:14:53 +00:00
|
|
|
jsval funval = OBJECT_TO_JSVAL(aHandler);
|
2000-06-21 00:21:50 +00:00
|
|
|
PRBool ok = ::JS_CallFunctionValue(mContext, (JSObject *)aTarget, funval,
|
2000-01-08 00:24:24 +00:00
|
|
|
argc, (jsval *)argv, &val);
|
2000-06-21 00:21:50 +00:00
|
|
|
*aBoolResult = ok
|
|
|
|
? !JSVAL_IS_BOOLEAN(val) || (aReverseReturnResult ? !JSVAL_TO_BOOLEAN(val) : JSVAL_TO_BOOLEAN(val))
|
|
|
|
: JS_TRUE;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2000-09-15 06:17:08 +00:00
|
|
|
ScriptEvaluated(PR_TRUE);
|
2000-06-21 00:21:50 +00:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(stack->Pop(nsnull)))
|
1999-09-17 20:13:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-07 22:14:17 +00:00
|
|
|
nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName, void *aHandler)
|
1999-12-03 03:40:30 +00:00
|
|
|
{
|
|
|
|
char charName[64];
|
|
|
|
AtomToEventHandlerName(aName, charName, sizeof charName);
|
|
|
|
|
1999-12-07 22:14:17 +00:00
|
|
|
JSObject *funobj = (JSObject*) aHandler;
|
|
|
|
JSObject *target = (JSObject*) aTarget;
|
1999-12-06 08:27:03 +00:00
|
|
|
|
|
|
|
// Make sure the handler function is parented by its event target object
|
2000-01-08 00:24:24 +00:00
|
|
|
if (funobj && ::JS_GetParent(mContext, funobj) != target) {
|
|
|
|
funobj = ::JS_CloneFunctionObject(mContext, funobj, target);
|
1999-12-06 08:27:03 +00:00
|
|
|
if (!funobj)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!::JS_DefineProperty(mContext, target, charName,
|
|
|
|
OBJECT_TO_JSVAL(funobj), nsnull, nsnull,
|
1999-12-03 03:40:30 +00:00
|
|
|
JSPROP_ENUMERATE | JSPROP_PERMANENT)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::SetDefaultLanguageVersion(const char* aVersion)
|
|
|
|
{
|
2000-01-08 00:24:24 +00:00
|
|
|
(void) ::JS_SetVersion(mContext, ::JS_StringToVersion(aVersion));
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-17 20:13:52 +00:00
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP_(nsIScriptGlobalObject*)
|
|
|
|
nsJSContext::GetGlobalObject()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2000-01-08 00:24:24 +00:00
|
|
|
JSObject *global = ::JS_GetGlobalObject(mContext);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsIScriptGlobalObject *script_global = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != global) {
|
2000-01-08 00:24:24 +00:00
|
|
|
nsISupports* sup = (nsISupports *)::JS_GetPrivate(mContext, global);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (nsnull != sup) {
|
|
|
|
sup->QueryInterface(NS_GET_IID(nsIScriptGlobalObject), (void**) &script_global);
|
|
|
|
}
|
|
|
|
return script_global;
|
|
|
|
}
|
|
|
|
return nsnull;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP_(void*)
|
|
|
|
nsJSContext::GetNativeContext()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
return (void *)mContext;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (!mContext)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(aGlobalObject, &rv);
|
|
|
|
JSObject *global;
|
|
|
|
mIsInitialized = PR_FALSE;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = owner->GetScriptObject(this, (void **)&global);
|
|
|
|
|
|
|
|
// init standard classes
|
2000-08-22 03:51:17 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
extern JSClass WindowClass;
|
|
|
|
|
|
|
|
// Window uses JS_ResolveStandardClass for lazy class initialization.
|
|
|
|
if (JS_GetClass(mContext, global) == &WindowClass) {
|
|
|
|
// No JS_InitStandardClasses, so we must JS_SetGlobalObject explicitly.
|
|
|
|
::JS_SetGlobalObject(mContext, global);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// JS_InitStandardClasses does JS_SetGlobalObject for us, if necessary.
|
|
|
|
if (!::JS_InitStandardClasses(mContext, global))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = InitClasses(); // this will complete global object initialization
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
::JS_SetErrorReporter(mContext, NS_ScriptErrorReporter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
1998-12-30 21:35:35 +00:00
|
|
|
nsresult
|
|
|
|
nsJSContext::InitializeExternalClasses()
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIScriptNameSetRegistry, registry, kCScriptNameSetRegistryCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = registry->InitializeClasses(this);
|
|
|
|
}
|
|
|
|
return rv;
|
1998-12-30 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
1999-03-08 00:14:38 +00:00
|
|
|
nsresult
|
|
|
|
nsJSContext::InitializeLiveConnectClasses()
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
NS_WITH_SERVICE(nsIJVMManager, jvmManager, nsIJVMManager::GetCID(), &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && jvmManager != nsnull) {
|
|
|
|
PRBool javaEnabled = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(jvmManager->IsJavaEnabled(&javaEnabled)) && javaEnabled) {
|
|
|
|
nsCOMPtr<nsILiveConnectManager> liveConnectManager = do_QueryInterface(jvmManager);
|
|
|
|
if (liveConnectManager) {
|
2000-01-08 00:24:24 +00:00
|
|
|
rv = liveConnectManager->InitLiveConnectClasses(mContext, ::JS_GetGlobalObject(mContext));
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return all is well until things are stable.
|
|
|
|
return NS_OK;
|
1999-03-08 00:14:38 +00:00
|
|
|
}
|
|
|
|
|
2000-09-01 03:10:33 +00:00
|
|
|
static JSPropertySpec OptionsProperties[] = {
|
|
|
|
{"strict", JSOPTION_STRICT, JSPROP_ENUMERATE | JSPROP_PERMANENT},
|
|
|
|
{"werror", JSOPTION_WERROR, JSPROP_ENUMERATE | JSPROP_PERMANENT},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2000-09-01 13:03:40 +00:00
|
|
|
static JSBool PR_CALLBACK
|
2000-09-01 03:10:33 +00:00
|
|
|
GetOptionsProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|
|
|
{
|
|
|
|
if (JSVAL_IS_INT(id)) {
|
|
|
|
uint32 optbit = (uint32) JSVAL_TO_INT(id);
|
|
|
|
if ((optbit & (optbit - 1)) == 0 && optbit <= JSOPTION_WERROR)
|
|
|
|
*vp = (JS_GetOptions(cx) & optbit) ? JSVAL_TRUE : JSVAL_FALSE;
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-09-01 13:03:40 +00:00
|
|
|
static JSBool PR_CALLBACK
|
2000-09-01 03:10:33 +00:00
|
|
|
SetOptionsProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|
|
|
{
|
|
|
|
if (JSVAL_IS_INT(id)) {
|
|
|
|
uint32 optbit = (uint32) JSVAL_TO_INT(id);
|
|
|
|
if ((optbit & (optbit - 1)) == 0 && optbit <= JSOPTION_WERROR) {
|
|
|
|
JSBool optval;
|
|
|
|
if (!JS_ValueToBoolean(cx, *vp, &optval))
|
|
|
|
return JS_FALSE;
|
|
|
|
uint32 optset = JS_GetOptions(cx);
|
|
|
|
if (optval)
|
|
|
|
optset |= optbit;
|
|
|
|
else
|
|
|
|
optset &= ~optbit;
|
|
|
|
JS_SetOptions(cx, optset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSClass OptionsClass = {
|
|
|
|
"JSOptions",
|
|
|
|
0,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, GetOptionsProperty, SetOptionsProperty,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
|
|
|
};
|
|
|
|
|
2000-04-27 04:02:22 +00:00
|
|
|
#ifdef NS_TRACE_MALLOC
|
|
|
|
|
|
|
|
#include <errno.h> // XXX assume Linux if NS_TRACE_MALLOC
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "nsTraceMalloc.h"
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
TraceMallocDisable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
NS_TraceMallocDisable();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
TraceMallocEnable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
NS_TraceMallocEnable();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2000-05-17 06:58:48 +00:00
|
|
|
TraceMallocOpenLogFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
2000-04-27 04:02:22 +00:00
|
|
|
{
|
2000-05-17 06:58:48 +00:00
|
|
|
int fd;
|
2000-04-27 04:02:22 +00:00
|
|
|
JSString *str;
|
|
|
|
char *filename;
|
|
|
|
|
2000-05-17 06:58:48 +00:00
|
|
|
if (argc == 0) {
|
2000-04-27 04:02:22 +00:00
|
|
|
fd = -1;
|
|
|
|
} else {
|
|
|
|
str = JS_ValueToString(cx, argv[0]);
|
|
|
|
if (!str)
|
|
|
|
return JS_FALSE;
|
|
|
|
filename = JS_GetStringBytes(str);
|
|
|
|
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
|
|
|
if (fd < 0) {
|
|
|
|
JS_ReportError(cx, "can't open %s: %s", filename, strerror(errno));
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-05-17 06:58:48 +00:00
|
|
|
*rval = INT_TO_JSVAL(fd);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
TraceMallocChangeLogFD(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
int fd, oldfd;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
oldfd = -1;
|
|
|
|
} else {
|
|
|
|
if (!JS_ValueToECMAInt32(cx, argv[0], &fd))
|
|
|
|
return JS_FALSE;
|
|
|
|
oldfd = NS_TraceMallocChangeLogFD(fd);
|
|
|
|
if (oldfd == -2) {
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-27 04:02:22 +00:00
|
|
|
*rval = INT_TO_JSVAL(oldfd);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-17 04:44:14 +00:00
|
|
|
static JSBool
|
2000-05-17 06:58:48 +00:00
|
|
|
TraceMallocCloseLogFD(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
2000-05-17 04:44:14 +00:00
|
|
|
{
|
|
|
|
int32 fd;
|
|
|
|
|
2000-05-17 06:58:48 +00:00
|
|
|
if (argc == 0)
|
2000-05-17 04:44:14 +00:00
|
|
|
return JS_TRUE;
|
|
|
|
if (!JS_ValueToECMAInt32(cx, argv[0], &fd))
|
|
|
|
return JS_FALSE;
|
|
|
|
NS_TraceMallocCloseLogFD((int) fd);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-08-09 02:43:09 +00:00
|
|
|
static JSBool
|
|
|
|
TraceMallocLogTimestamp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
JSString *str;
|
|
|
|
const char *caption;
|
|
|
|
|
|
|
|
str = JS_ValueToString(cx, argv[0]);
|
|
|
|
if (!str)
|
|
|
|
return JS_FALSE;
|
|
|
|
caption = JS_GetStringBytes(str);
|
|
|
|
NS_TraceMallocLogTimestamp(caption);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-08-29 01:52:13 +00:00
|
|
|
static JSBool
|
|
|
|
TraceMallocDumpAllocations(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
JSString *str;
|
|
|
|
const char *pathname;
|
|
|
|
|
|
|
|
str = JS_ValueToString(cx, argv[0]);
|
|
|
|
if (!str)
|
|
|
|
return JS_FALSE;
|
|
|
|
pathname = JS_GetStringBytes(str);
|
|
|
|
if (NS_TraceMallocDumpAllocations(pathname) < 0) {
|
|
|
|
JS_ReportError(cx, "can't dump to %s: %s", pathname, strerror(errno));
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-27 04:02:22 +00:00
|
|
|
static JSFunctionSpec TraceMallocFunctions[] = {
|
2000-08-29 01:52:13 +00:00
|
|
|
{"TraceMallocDisable", TraceMallocDisable, 0, 0, 0},
|
|
|
|
{"TraceMallocEnable", TraceMallocEnable, 0, 0, 0},
|
|
|
|
{"TraceMallocOpenLogFile", TraceMallocOpenLogFile, 1, 0, 0},
|
|
|
|
{"TraceMallocChangeLogFD", TraceMallocChangeLogFD, 1, 0, 0},
|
|
|
|
{"TraceMallocCloseLogFD", TraceMallocCloseLogFD, 1, 0, 0},
|
|
|
|
{"TraceMallocLogTimestamp", TraceMallocLogTimestamp, 1, 0, 0},
|
|
|
|
{"TraceMallocDumpAllocations", TraceMallocDumpAllocations, 1, 0, 0},
|
2000-09-01 03:10:33 +00:00
|
|
|
{nsnull, nsnull, 0, 0, 0}
|
2000-04-27 04:02:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* NS_TRACE_MALLOC */
|
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::InitClasses()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2000-09-02 01:58:51 +00:00
|
|
|
nsresult rv = NS_OK;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global = dont_AddRef(GetGlobalObject());
|
2000-09-01 03:10:33 +00:00
|
|
|
JSObject *globalObj = ::JS_GetGlobalObject(mContext);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2000-09-02 01:58:51 +00:00
|
|
|
if (NS_FAILED(NS_InitWindowClass(this, global)) ||
|
|
|
|
NS_FAILED(NS_InitNodeClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitElementClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitDocumentClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitTextClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitAttrClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitNamedNodeMapClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitNodeListClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitKeyEventClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(InitializeLiveConnectClasses()) ||
|
|
|
|
NS_FAILED(InitializeExternalClasses()) ||
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
// XXX Temporarily here. These shouldn't be hardcoded.
|
2000-09-02 01:58:51 +00:00
|
|
|
NS_FAILED(NS_InitHTMLImageElementClass(this, nsnull)) ||
|
|
|
|
NS_FAILED(NS_InitHTMLOptionElementClass(this, nsnull))) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
// Initialize XPConnect classes
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-09-01 03:10:33 +00:00
|
|
|
rv = xpc->InitClasses(mContext, globalObj);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
1999-12-18 20:29:29 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to init xpconnect classes");
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
2000-04-27 04:02:22 +00:00
|
|
|
|
2000-09-02 04:19:45 +00:00
|
|
|
// Initialize the options object and set default options in mContext
|
2000-09-01 03:10:33 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
JSObject *optionsObj = ::JS_DefineObject(mContext, globalObj, "options",
|
|
|
|
&OptionsClass, nsnull, 0);
|
2000-09-02 01:58:51 +00:00
|
|
|
if (optionsObj &&
|
|
|
|
::JS_DefineProperties(mContext, optionsObj, OptionsProperties)) {
|
|
|
|
::JS_SetOptions(mContext, mDefaultJSOptions);
|
|
|
|
}
|
|
|
|
else {
|
2000-09-01 03:10:33 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-27 04:02:22 +00:00
|
|
|
#ifdef NS_TRACE_MALLOC
|
|
|
|
// Attempt to initialize TraceMalloc functions
|
2000-09-01 03:10:33 +00:00
|
|
|
::JS_DefineFunctions(mContext, globalObj, TraceMallocFunctions);
|
2000-04-27 04:02:22 +00:00
|
|
|
#endif
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mIsInitialized = PR_TRUE;
|
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-12-30 02:46:36 +00:00
|
|
|
nsJSContext::IsContextInitialized()
|
|
|
|
{
|
2000-04-05 02:40:08 +00:00
|
|
|
return (mIsInitialized) ? NS_OK : NS_ERROR_NOT_INITIALIZED;
|
1998-12-30 02:46:36 +00:00
|
|
|
}
|
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-20 09:51:02 +00:00
|
|
|
nsJSContext::AddNamedReference(void *aSlot, void *aScriptObject, const char *aName)
|
1998-08-20 22:25:21 +00:00
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
return (::JS_AddNamedRoot(mContext, aSlot, aName)) ? NS_OK : NS_ERROR_FAILURE;
|
1998-08-20 22:25:21 +00:00
|
|
|
}
|
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-20 22:25:21 +00:00
|
|
|
nsJSContext::RemoveReference(void *aSlot, void *aScriptObject)
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
return (::JS_RemoveRoot(mContext, aSlot)) ? NS_OK : NS_ERROR_FAILURE;
|
1998-08-20 22:25:21 +00:00
|
|
|
}
|
|
|
|
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHODIMP
|
1998-10-26 23:22:21 +00:00
|
|
|
nsJSContext::GC()
|
|
|
|
{
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_GC(mContext);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
return NS_OK;
|
1998-10-26 23:22:21 +00:00
|
|
|
}
|
|
|
|
|
1999-03-12 22:24:30 +00:00
|
|
|
NS_IMETHODIMP
|
2000-09-15 06:17:08 +00:00
|
|
|
nsJSContext::ScriptEvaluated(PRBool aTerminated)
|
1999-03-12 22:24:30 +00:00
|
|
|
{
|
2000-09-15 06:17:08 +00:00
|
|
|
if (aTerminated && mTerminationFunc) {
|
1999-10-28 14:12:56 +00:00
|
|
|
(*mTerminationFunc)(mRef);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mRef = nsnull;
|
1999-10-28 14:12:56 +00:00
|
|
|
mTerminationFunc = nsnull;
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mNumEvaluations++;
|
|
|
|
|
|
|
|
if (mNumEvaluations > 20) {
|
|
|
|
mNumEvaluations = 0;
|
2000-02-04 09:50:25 +00:00
|
|
|
::JS_MaybeGC(mContext);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
|
2000-06-24 16:18:41 +00:00
|
|
|
mBranchCallbackCount = 0;
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
return NS_OK;
|
1999-03-12 22:24:30 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-12-21 16:51:10 +00:00
|
|
|
nsJSContext::GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr)
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mNameSpaceManager.get()) {
|
|
|
|
rv = NS_NewScriptNameSpaceManager(getter_AddRefs(mNameSpaceManager));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-09-13 23:57:52 +00:00
|
|
|
// XXXbe used contractid rather than CID?
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_WITH_SERVICE(nsIScriptNameSetRegistry, registry, kCScriptNameSetRegistryCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = registry->PopulateNameSpace(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtr = mNameSpaceManager;
|
|
|
|
NS_ADDREF(*aInstancePtr);
|
|
|
|
return rv;
|
1998-12-21 16:51:10 +00:00
|
|
|
}
|
|
|
|
|
1998-11-21 00:12:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-29 21:58:42 +00:00
|
|
|
nsJSContext::GetSecurityManager(nsIScriptSecurityManager **aInstancePtr)
|
1998-11-21 00:12:33 +00:00
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (!mSecurityManager) {
|
2000-09-13 23:57:52 +00:00
|
|
|
nsresult rv = nsServiceManager::GetService(kScriptSecurityManagerContractID,
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_GET_IID(nsIScriptSecurityManager),
|
|
|
|
(nsISupports**)&mSecurityManager);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
*aInstancePtr = mSecurityManager;
|
|
|
|
NS_ADDREF(*aInstancePtr);
|
|
|
|
return NS_OK;
|
1998-11-21 00:12:33 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-08 23:14:30 +00:00
|
|
|
nsJSContext::SetOwner(nsIScriptContextOwner* owner)
|
|
|
|
{
|
|
|
|
// The owner should not be addrefed!! We'll be told
|
|
|
|
// when the owner goes away.
|
|
|
|
mOwner = owner;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-08 23:14:30 +00:00
|
|
|
nsJSContext::GetOwner(nsIScriptContextOwner** owner)
|
|
|
|
{
|
|
|
|
*owner = mOwner;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IF_ADDREF(*owner);
|
1999-09-08 23:14:30 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-28 14:12:56 +00:00
|
|
|
nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc,
|
|
|
|
nsISupports* aRef)
|
|
|
|
{
|
|
|
|
mTerminationFunc = aFunc;
|
|
|
|
mRef = aRef;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-26 23:32:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::SetRootedScriptObject(void *aObject)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRootedScriptObject == nsnull, "two rooted script objects stored");
|
|
|
|
mRootedScriptObject = aObject;
|
|
|
|
if (::JS_AddNamedRoot(mContext, &mRootedScriptObject, "jscontext_savedroot"))
|
|
|
|
return NS_OK;
|
|
|
|
mRootedScriptObject = nsnull;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-03-28 00:15:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::GetScriptsEnabled(PRBool *aEnabled)
|
|
|
|
{
|
|
|
|
*aEnabled = mScriptsEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::SetScriptsEnabled(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
mScriptsEnabled = aEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsJSEnvironment *nsJSEnvironment::sTheEnvironment = nsnull;
|
|
|
|
|
|
|
|
nsJSEnvironment *
|
|
|
|
nsJSEnvironment::GetScriptingEnvironment()
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (nsnull == sTheEnvironment) {
|
|
|
|
sTheEnvironment = new nsJSEnvironment();
|
2000-06-20 03:45:21 +00:00
|
|
|
NS_IF_ADDREF(sTheEnvironment); // released in |Observe|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
}
|
|
|
|
return sTheEnvironment;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
const char kJSRuntimeServiceContractID[] = "@mozilla.org/js/xpc/RuntimeService;1";
|
2000-03-11 06:32:42 +00:00
|
|
|
static int globalCount;
|
2000-05-15 04:21:04 +00:00
|
|
|
static PRThread *gDOMThread;
|
|
|
|
|
2000-06-02 23:04:50 +00:00
|
|
|
static JSBool PR_CALLBACK
|
2000-05-15 04:21:04 +00:00
|
|
|
DOMGCCallback(JSContext *cx, JSGCStatus status)
|
|
|
|
{
|
|
|
|
if (status == JSGC_BEGIN && PR_GetCurrentThread() != gDOMThread)
|
|
|
|
return JS_FALSE;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsJSEnvironment::nsJSEnvironment()
|
|
|
|
{
|
2000-06-20 03:45:21 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
|
|
|
|
// So that we get deleted on XPCOM shutdown, set up an
|
|
|
|
// observer.
|
|
|
|
nsresult rv;
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
2000-06-20 03:45:21 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "going to leak a nsJSEnvironment");
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
nsAutoString topic;
|
|
|
|
topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
|
|
|
observerService->AddObserver(this,topic.GetUnicode());
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
mRuntimeService = nsnull;
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = nsServiceManager::GetService(kJSRuntimeServiceContractID,
|
2000-06-20 03:45:21 +00:00
|
|
|
NS_GET_IID(nsIJSRuntimeService),
|
|
|
|
(nsISupports**)&mRuntimeService);
|
1999-09-05 00:43:39 +00:00
|
|
|
// get the JSRuntime from the runtime svc, if possible
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv))
|
1999-09-07 19:44:15 +00:00
|
|
|
return; // XXX swallow error! need Init()?
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
rv = mRuntimeService->GetRuntime(&mRuntime);
|
|
|
|
if (NS_FAILED(rv))
|
1999-09-07 19:44:15 +00:00
|
|
|
return; // XXX swallow error! need Init()?
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2000-05-15 04:21:04 +00:00
|
|
|
gDOMThread = PR_GetCurrentThread();
|
|
|
|
::JS_SetGCCallbackRT(mRuntime, DOMGCCallback);
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
// Initialize LiveConnect. XXXbe use contractid rather than GetCID
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_WITH_SERVICE(nsILiveConnectManager, manager,
|
|
|
|
nsIJVMManager::GetCID(), &rv);
|
|
|
|
|
|
|
|
// Should the JVM manager perhaps define methods for starting up LiveConnect?
|
|
|
|
if (NS_SUCCEEDED(rv) && manager != nsnull) {
|
|
|
|
PRBool started = PR_FALSE;
|
|
|
|
rv = manager->StartupLiveConnect(mRuntime, started);
|
|
|
|
}
|
2000-03-11 06:32:42 +00:00
|
|
|
|
|
|
|
globalCount++;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsJSEnvironment::~nsJSEnvironment()
|
|
|
|
{
|
2000-03-11 06:32:42 +00:00
|
|
|
if (--globalCount == 0)
|
|
|
|
nsJSUtils::nsClearCachedSecurityManager();
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (mRuntimeService)
|
2000-09-13 23:57:52 +00:00
|
|
|
nsServiceManager::ReleaseService(kJSRuntimeServiceContractID, mRuntimeService);
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 03:45:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsJSEnvironment,nsIObserver);
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsJSEnvironment::Observe(nsISupports *aSubject,
|
|
|
|
const PRUnichar *aTopic,
|
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsAutoString topic;
|
|
|
|
topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
|
|
|
NS_ASSERTION(topic.EqualsWithConversion(aTopic), "not shutdown");
|
|
|
|
#endif
|
|
|
|
NS_RELEASE_THIS(); // release ref from |GetScriptingEnvironment|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsIScriptContext* nsJSEnvironment::GetNewContext()
|
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsIScriptContext *context;
|
|
|
|
context = new nsJSContext(mRuntime);
|
|
|
|
NS_ADDREF(context);
|
|
|
|
return context;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
extern "C" NS_DOM nsresult NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
|
1999-08-09 19:14:49 +00:00
|
|
|
nsIScriptContext **aContext)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
nsJSEnvironment *environment = nsJSEnvironment::GetScriptingEnvironment();
|
|
|
|
if (!environment)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsIScriptContext *scriptContext = environment->GetNewContext();
|
|
|
|
if (!scriptContext)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*aContext = scriptContext;
|
|
|
|
|
|
|
|
// Bind the script context and the global object
|
|
|
|
scriptContext->InitContext(aGlobal);
|
|
|
|
aGlobal->SetContext(scriptContext);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|