2001-09-25 22:43:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
(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
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
(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
|
|
|
*
|
2001-09-25 22:43:09 +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.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:43:09 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-05-26 07:44:19 +00:00
|
|
|
* Contributor(s):
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:43:09 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:43:09 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
(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"
|
1999-09-08 23:14:30 +00:00
|
|
|
#include "nsIScriptContextOwner.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2005-06-08 02:13:10 +00:00
|
|
|
#include "nsIDOMChromeWindow.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"
|
2005-05-20 03:12:22 +00:00
|
|
|
#include "nsIDOMChromeWindow.h"
|
1998-11-21 00:12:33 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1998-12-22 22:03:20 +00:00
|
|
|
#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-08-29 21:58:42 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
1999-12-18 20:29:29 +00:00
|
|
|
#include "nsJSUtils.h"
|
2000-04-24 04:41:27 +00:00
|
|
|
#include "nsIDocShell.h"
|
2000-12-07 02:08:21 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2004-01-04 00:29:27 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2000-12-07 02:08:21 +00:00
|
|
|
#include "nsIScriptError.h"
|
2000-06-24 16:18:41 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-06-24 16:18:41 +00:00
|
|
|
#include "nsIPrompt.h"
|
2000-06-20 03:45:21 +00:00
|
|
|
#include "nsIObserverService.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
2001-06-05 01:00:48 +00:00
|
|
|
#include "nsIThread.h"
|
2001-11-27 09:46:38 +00:00
|
|
|
#include "nsITimer.h"
|
2001-09-05 04:29:13 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
2002-07-25 18:31:10 +00:00
|
|
|
#include "nsIAtom.h"
|
2004-04-29 23:34:19 +00:00
|
|
|
#include "nsContentUtils.h"
|
2005-06-07 23:20:06 +00:00
|
|
|
#include "jscntxt.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
// For locale aware string methods
|
2004-06-15 16:38:43 +00:00
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsIPlatformCharset.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
2003-06-24 21:09:57 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsILocaleService.h"
|
|
|
|
#include "nsICollation.h"
|
|
|
|
#include "nsCollationCID.h"
|
|
|
|
|
2005-06-08 02:13:10 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "jsgc.h" // for WAY_TOO_MUCH_GC, if defined for GC debugging
|
|
|
|
#endif
|
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
|
|
|
|
|
2005-02-02 21:41:07 +00:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
|
2001-05-05 10:18:53 +00:00
|
|
|
#ifdef MOZ_LOGGING
|
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
|
2001-05-05 10:18:53 +00:00
|
|
|
#endif
|
1999-12-03 03:40:30 +00:00
|
|
|
#include "prlog.h"
|
2000-05-15 04:21:04 +00:00
|
|
|
#include "prthread.h"
|
1999-12-03 03:40:30 +00:00
|
|
|
|
2003-03-25 06:54:52 +00:00
|
|
|
#ifdef OJI
|
1999-02-25 04:29:08 +00:00
|
|
|
#include "nsIJVMManager.h"
|
|
|
|
#include "nsILiveConnectManager.h"
|
2003-03-25 06:54:52 +00:00
|
|
|
#endif
|
1999-02-25 04:29:08 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
const size_t gStackSize = 8192;
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-24 23:06:12 +00:00
|
|
|
static PRLogModuleInfo* gJSDiagnostics;
|
2000-10-28 22:17:53 +00:00
|
|
|
#endif
|
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
// Thank you Microsoft!
|
2005-01-28 23:05:36 +00:00
|
|
|
#ifndef WINCE
|
2003-06-24 21:09:57 +00:00
|
|
|
#ifdef CompareString
|
|
|
|
#undef CompareString
|
|
|
|
#endif
|
2005-01-28 23:05:36 +00:00
|
|
|
#endif // WINCE
|
2001-11-27 09:46:38 +00:00
|
|
|
|
|
|
|
#define NS_GC_DELAY 2000 // ms
|
|
|
|
#define NS_FIRST_GC_DELAY 10000 // ms
|
|
|
|
|
2004-06-09 18:36:25 +00:00
|
|
|
// if you add statics here, add them to the list in nsJSEnvironment::Startup
|
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static nsITimer *sGCTimer;
|
|
|
|
static PRBool sReadyForGC;
|
2001-11-27 09:46:38 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsScriptNameSpaceManager *gNameSpaceManager;
|
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static nsIJSRuntimeService *sRuntimeService;
|
|
|
|
JSRuntime *nsJSEnvironment::sRuntime;
|
2002-05-03 03:02:07 +00:00
|
|
|
|
|
|
|
static const char kJSRuntimeServiceContractID[] =
|
|
|
|
"@mozilla.org/js/xpc/RuntimeService;1";
|
|
|
|
|
2005-02-02 21:41:07 +00:00
|
|
|
static const char kDOMStringBundleURL[] =
|
2005-02-23 16:53:28 +00:00
|
|
|
"chrome://global/locale/dom/dom.properties";
|
2005-02-02 21:41:07 +00:00
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static PRThread *gDOMThread;
|
2002-05-03 03:02:07 +00:00
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static JSGCCallback gOldJSGCCallback;
|
2002-05-03 03:02:07 +00:00
|
|
|
|
2004-06-09 18:36:25 +00:00
|
|
|
static PRBool sIsInitialized;
|
2003-06-24 23:06:12 +00:00
|
|
|
static PRBool sDidShutdown;
|
2002-05-03 03:02:07 +00:00
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static PRInt32 sContextCount;
|
2002-05-03 03:02:07 +00:00
|
|
|
|
2004-02-11 22:22:05 +00:00
|
|
|
static PRTime sMaxScriptRunTime;
|
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static nsIScriptSecurityManager *sSecurityManager;
|
2002-05-03 03:02:07 +00:00
|
|
|
|
2003-06-24 23:06:12 +00:00
|
|
|
static nsICollation *gCollation;
|
2003-06-24 21:09:57 +00:00
|
|
|
|
2004-06-15 16:38:43 +00:00
|
|
|
static nsIUnicodeDecoder *gDecoder;
|
2003-06-24 21:09:57 +00:00
|
|
|
|
2001-03-19 21:46:25 +00:00
|
|
|
void JS_DLL_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
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
// XXX this means we are not going to get error reports on non DOM contexts
|
|
|
|
nsIScriptContext *context = nsJSUtils::GetDynamicScriptContext(cx);
|
|
|
|
|
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
|
|
|
if (context) {
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptGlobalObject *globalObject = 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) {
|
2001-11-02 04:49:07 +00:00
|
|
|
nsAutoString fileName, msg;
|
|
|
|
|
|
|
|
if (report) {
|
|
|
|
fileName.AssignWithConversion(report->filename);
|
|
|
|
|
|
|
|
const PRUnichar *m = NS_REINTERPRET_CAST(const PRUnichar*,
|
|
|
|
report->ucmessage);
|
|
|
|
|
|
|
|
if (m) {
|
|
|
|
msg.Assign(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.IsEmpty() && message) {
|
|
|
|
msg.AssignWithConversion(message);
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
// First, notify the DOM that we have a script error.
|
2005-06-07 23:20:06 +00:00
|
|
|
/* We do not try to report Out Of Memory via a dom
|
|
|
|
* event because the dom event handler would encounter
|
|
|
|
* an OOM exception trying to process the event, and
|
|
|
|
* then we'd need to generate a new OOM event for that
|
|
|
|
* new OOM instance -- this isn't pretty.
|
|
|
|
*/
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIDocShell *docShell = globalObject->GetDocShell();
|
2005-06-07 23:20:06 +00:00
|
|
|
if (docShell &&
|
2005-06-08 23:08:56 +00:00
|
|
|
(!report ||
|
|
|
|
(report->errorNumber != JSMSG_OUT_OF_MEMORY &&
|
|
|
|
!JSREPORT_IS_WARNING(report->flags)))) {
|
2004-02-09 22:48:53 +00:00
|
|
|
static PRInt32 errorDepth; // Recursion prevention
|
|
|
|
++errorDepth;
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2004-02-09 22:48:53 +00:00
|
|
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
if (presContext && errorDepth < 2) {
|
2005-04-28 23:48:28 +00:00
|
|
|
nsScriptErrorEvent errorevent(PR_TRUE, NS_SCRIPT_ERROR);
|
2000-08-21 08:44:55 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
errorevent.fileName = fileName.get();
|
|
|
|
errorevent.errorMsg = msg.get();
|
|
|
|
errorevent.lineNr = report ? report->lineno : 0;
|
|
|
|
|
|
|
|
// HandleDOMEvent() must be synchronous for the recursion block
|
|
|
|
// (errorDepth) to work.
|
|
|
|
globalObject->HandleDOMEvent(presContext, &errorevent, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
2004-01-04 00:29:27 +00:00
|
|
|
}
|
2004-02-09 22:48:53 +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.
|
2004-01-04 00:29:27 +00:00
|
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
|
|
|
do_CreateInstance("@mozilla.org/scripterror;1");
|
2000-04-24 04:41:27 +00:00
|
|
|
|
|
|
|
if (errorObject != nsnull) {
|
2000-12-07 02:08:21 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
const char *category = nsnull;
|
|
|
|
// Set category to XUL or content, if possible.
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellTI(do_QueryInterface(docShell, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv) && docShellTI) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
rv = docShellTI->GetItemType(&docShellType);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
category = docShellType == nsIDocShellTreeItem::typeChrome
|
|
|
|
? "chrome javascript"
|
|
|
|
: "content javascript";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
if (report) {
|
|
|
|
PRUint32 column = report->uctokenptr - report->uclinebuf;
|
2001-08-16 04:05:10 +00:00
|
|
|
|
2001-11-02 04:49:07 +00:00
|
|
|
rv = errorObject->Init(msg.get(), fileName.get(),
|
2001-08-16 04:05:10 +00:00
|
|
|
NS_REINTERPRET_CAST(const PRUnichar*,
|
|
|
|
report->uclinebuf),
|
|
|
|
report->lineno, column, report->flags,
|
|
|
|
category);
|
2000-04-24 04:41:27 +00:00
|
|
|
} else if (message) {
|
2001-11-02 04:49:07 +00:00
|
|
|
rv = errorObject->Init(msg.get(), nsnull, nsnull, 0, 0, 0,
|
|
|
|
category);
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
2001-05-26 07:44:19 +00:00
|
|
|
|
2004-01-04 00:29:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-07-16 17:03:10 +00:00
|
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
consoleService->LogMessage(errorObject);
|
2004-01-04 00:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-15 01:56:47 +00:00
|
|
|
}
|
1999-12-18 20:29:29 +00:00
|
|
|
}
|
1999-09-08 23:14:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
#ifdef DEBUG
|
2000-04-15 01:56:47 +00:00
|
|
|
// Print it to stderr as well, for the benefit of those invoking
|
|
|
|
// mozilla with -console.
|
2004-04-12 22:20:03 +00:00
|
|
|
nsCAutoString error;
|
|
|
|
error.Assign("JavaScript ");
|
2005-06-07 23:20:06 +00:00
|
|
|
if (!report) {
|
|
|
|
error.Append("[no report]: ");
|
|
|
|
error.Append(message);
|
|
|
|
} else {
|
2005-06-08 03:02:00 +00:00
|
|
|
if (JSREPORT_IS_STRICT(report->flags))
|
|
|
|
error.Append("strict ");
|
|
|
|
if (JSREPORT_IS_WARNING(report->flags))
|
|
|
|
error.Append("warning: ");
|
|
|
|
else
|
|
|
|
error.Append("error: ");
|
|
|
|
error.Append(report->filename);
|
|
|
|
error.Append(", line ");
|
|
|
|
error.AppendInt(report->lineno, 10);
|
|
|
|
error.Append(": ");
|
|
|
|
AppendUTF16toUTF8(NS_REINTERPRET_CAST(const PRUnichar*, report->ucmessage),
|
|
|
|
error);
|
|
|
|
if (status != nsEventStatus_eIgnore && !JSREPORT_IS_WARNING(report->flags))
|
|
|
|
error.Append(" Error was suppressed by event handler\n");
|
2005-06-07 23:20:06 +00:00
|
|
|
}
|
2004-04-12 22:20:03 +00:00
|
|
|
fprintf(stderr, "%s\n", error.get());
|
|
|
|
fflush(stderr);
|
2001-05-14 09:56:10 +00:00
|
|
|
#endif
|
2000-04-15 01:56:47 +00:00
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (report) {
|
2000-10-28 22:17:53 +00:00
|
|
|
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"
|
|
|
|
: ""));
|
|
|
|
}
|
1999-12-03 03:40:30 +00:00
|
|
|
}
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2004-06-15 16:38:43 +00:00
|
|
|
JS_STATIC_DLL_CALLBACK(JSBool)
|
|
|
|
LocaleToUnicode(JSContext *cx, char *src, jsval *rval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!gDecoder) {
|
|
|
|
// use app default locale
|
|
|
|
nsCOMPtr<nsILocaleService> localeService =
|
|
|
|
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsILocale> appLocale;
|
|
|
|
rv = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsAutoString localeStr;
|
|
|
|
rv = appLocale->
|
|
|
|
GetCategory(NS_LITERAL_STRING(NSILOCALE_TIME), localeStr);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get app locale info");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPlatformCharset> platformCharset =
|
|
|
|
do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCAutoString charset;
|
|
|
|
rv = platformCharset->GetDefaultCharsetForLocale(localeStr, charset);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// get/create unicode decoder for charset
|
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccm =
|
|
|
|
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
ccm->GetUnicodeDecoder(charset.get(), &gDecoder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *str = nsnull;
|
|
|
|
PRInt32 srcLength = PL_strlen(src);
|
|
|
|
|
|
|
|
if (gDecoder) {
|
|
|
|
PRInt32 unicharLength = srcLength;
|
|
|
|
PRUnichar *unichars = (PRUnichar *)malloc((srcLength + 1) * sizeof(PRUnichar));
|
|
|
|
if (unichars) {
|
|
|
|
rv = gDecoder->Convert(src, &srcLength, unichars, &unicharLength);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// terminate the returned string
|
|
|
|
unichars[unicharLength] = 0;
|
|
|
|
|
|
|
|
// nsIUnicodeDecoder::Convert may use fewer than srcLength PRUnichars
|
|
|
|
if (unicharLength + 1 < srcLength + 1) {
|
|
|
|
PRUnichar *shrunkUnichars =
|
|
|
|
(PRUnichar *)realloc(unichars, (unicharLength + 1) * sizeof(PRUnichar));
|
|
|
|
if (shrunkUnichars)
|
|
|
|
unichars = shrunkUnichars;
|
|
|
|
}
|
|
|
|
str = JS_NewUCString(cx,
|
|
|
|
NS_REINTERPRET_CAST(jschar*, unichars),
|
|
|
|
unicharLength);
|
|
|
|
}
|
|
|
|
if (!str)
|
|
|
|
free(unichars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str) {
|
|
|
|
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rval = STRING_TO_JSVAL(str);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
static JSBool
|
|
|
|
ChangeCase(JSContext *cx, JSString *src, jsval *rval,
|
|
|
|
void(* changeCaseFnc)(const nsAString&, nsAString&))
|
|
|
|
{
|
|
|
|
nsAutoString result;
|
2004-02-09 22:48:53 +00:00
|
|
|
changeCaseFnc(nsDependentJSString(src), result);
|
2003-06-24 21:09:57 +00:00
|
|
|
|
2003-09-18 17:22:33 +00:00
|
|
|
JSString *ucstr = JS_NewUCStringCopyN(cx, (jschar*)result.get(), result.Length());
|
2003-06-24 21:09:57 +00:00
|
|
|
if (!ucstr) {
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rval = STRING_TO_JSVAL(ucstr);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool JS_DLL_CALLBACK
|
|
|
|
LocaleToUpperCase(JSContext *cx, JSString *src, jsval *rval)
|
|
|
|
{
|
|
|
|
return ChangeCase(cx, src, rval, ToUpperCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool JS_DLL_CALLBACK
|
|
|
|
LocaleToLowerCase(JSContext *cx, JSString *src, jsval *rval)
|
|
|
|
{
|
|
|
|
return ChangeCase(cx, src, rval, ToLowerCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool JS_DLL_CALLBACK
|
|
|
|
LocaleCompare(JSContext *cx, JSString *src1, JSString *src2, jsval *rval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!gCollation) {
|
|
|
|
nsCOMPtr<nsILocaleService> localeService =
|
|
|
|
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
|
|
|
rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsICollationFactory> colFactory =
|
|
|
|
do_CreateInstance(kCollationFactoryCID, &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = colFactory->CreateCollation(locale, &gCollation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsDOMClassInfo::ThrowJSException(cx, rv);
|
|
|
|
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 result;
|
2004-08-24 22:50:33 +00:00
|
|
|
rv = gCollation->CompareString(nsICollation::kCollationStrengthDefault,
|
2004-02-09 22:48:53 +00:00
|
|
|
nsDependentJSString(src1),
|
|
|
|
nsDependentJSString(src2),
|
2003-06-24 21:09:57 +00:00
|
|
|
&result);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsDOMClassInfo::ThrowJSException(cx, rv);
|
|
|
|
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rval = INT_TO_JSVAL(result);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-21 19:48:35 +00:00
|
|
|
static void
|
2003-12-02 22:14:48 +00:00
|
|
|
NotifyXPCIfExceptionPending(JSContext *cx)
|
2003-11-21 19:48:35 +00:00
|
|
|
{
|
2003-12-02 22:14:48 +00:00
|
|
|
if (!::JS_IsExceptionPending(cx)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-01 16:50:12 +00:00
|
|
|
nsCOMPtr<nsIXPCNativeCallContext> nccx;
|
|
|
|
nsContentUtils::XPConnect()->
|
|
|
|
GetCurrentNativeCallContext(getter_AddRefs(nccx));
|
|
|
|
if (nccx) {
|
|
|
|
nccx->SetExceptionWasThrown(PR_TRUE);
|
2003-11-21 19:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-11 22:22:05 +00:00
|
|
|
// The number of branch callbacks between calls to JS_MaybeGC
|
2000-06-24 16:18:41 +00:00
|
|
|
#define MAYBE_GC_BRANCH_COUNT_MASK 0x00000fff // 4095
|
|
|
|
|
2004-12-09 00:22:53 +00:00
|
|
|
// The number of branch callbacks before we even check if our start
|
|
|
|
// timestamp is initialized. This is a fairly low number as we want to
|
|
|
|
// initialize the timestamp early enough to not waste much time before
|
|
|
|
// we get there, but we don't want to bother doing this too early as
|
|
|
|
// it's not generally necessary.
|
|
|
|
#define INITIALIZE_TIME_BRANCH_COUNT_MASK 0x000000ff // 255
|
|
|
|
|
|
|
|
// This function is called after each JS branch execution
|
2001-03-19 21:46:25 +00:00
|
|
|
JSBool JS_DLL_CALLBACK
|
2000-06-24 16:18:41 +00:00
|
|
|
nsJSContext::DOMBranchCallback(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
// Get the native context
|
2001-08-07 05:27:42 +00:00
|
|
|
nsJSContext *ctx = NS_STATIC_CAST(nsJSContext *, ::JS_GetContextPrivate(cx));
|
2000-06-24 16:18:41 +00:00
|
|
|
|
2004-12-09 00:22:53 +00:00
|
|
|
PRUint32 callbackCount = ++ctx->mBranchCallbackCount;
|
|
|
|
|
|
|
|
if (callbackCount & INITIALIZE_TIME_BRANCH_COUNT_MASK) {
|
2000-06-24 16:18:41 +00:00
|
|
|
return JS_TRUE;
|
2004-12-09 00:22:53 +00:00
|
|
|
}
|
2000-06-24 16:18:41 +00:00
|
|
|
|
2004-12-09 00:22:53 +00:00
|
|
|
if (callbackCount == INITIALIZE_TIME_BRANCH_COUNT_MASK + 1 &&
|
|
|
|
LL_IS_ZERO(ctx->mBranchCallbackTime)) {
|
|
|
|
// Initialize mBranchCallbackTime to start timing how long the
|
|
|
|
// script has run
|
|
|
|
ctx->mBranchCallbackTime = PR_Now();
|
2000-06-24 16:18:41 +00:00
|
|
|
|
|
|
|
return JS_TRUE;
|
2004-12-09 00:22:53 +00:00
|
|
|
}
|
2000-06-24 16:18:41 +00:00
|
|
|
|
2004-12-09 00:22:53 +00:00
|
|
|
if (callbackCount & MAYBE_GC_BRANCH_COUNT_MASK) {
|
2004-02-11 22:22:05 +00:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-12-09 00:22:53 +00:00
|
|
|
// Run the GC if we get this far.
|
|
|
|
JS_MaybeGC(cx);
|
|
|
|
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
|
2004-02-11 22:22:05 +00:00
|
|
|
PRTime duration;
|
|
|
|
LL_SUB(duration, now, ctx->mBranchCallbackTime);
|
|
|
|
|
|
|
|
// Check the amount of time this script has been running
|
2004-12-09 00:22:53 +00:00
|
|
|
if (LL_CMP(duration, <, sMaxScriptRunTime)) {
|
2004-02-11 22:22:05 +00:00
|
|
|
return JS_TRUE;
|
2004-12-09 00:22:53 +00:00
|
|
|
}
|
2004-02-11 22:22:05 +00:00
|
|
|
|
2000-06-24 16:18:41 +00:00
|
|
|
// 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.
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptGlobalObject *global = ctx->GetGlobalObject();
|
2000-06-24 16:18:41 +00:00
|
|
|
NS_ENSURE_TRUE(global, JS_TRUE);
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIDocShell *docShell = global->GetDocShell();
|
2000-06-24 16:18:41 +00:00
|
|
|
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);
|
|
|
|
|
2005-02-02 21:41:07 +00:00
|
|
|
// Get localizable strings
|
|
|
|
nsCOMPtr<nsIStringBundleService>
|
|
|
|
stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID));
|
|
|
|
if (!stringService)
|
|
|
|
return JS_TRUE;
|
2000-06-24 16:18:41 +00:00
|
|
|
|
2005-02-02 21:41:07 +00:00
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
stringService->CreateBundle(kDOMStringBundleURL, getter_AddRefs(bundle));
|
|
|
|
if (!bundle)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
nsXPIDLString title, msg, stopButton, waitButton;
|
|
|
|
|
|
|
|
nsresult rv;
|
2004-12-09 00:22:53 +00:00
|
|
|
|
2005-02-02 21:41:07 +00:00
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("KillScriptMessage").get(),
|
|
|
|
getter_Copies(msg));
|
|
|
|
rv |= bundle->GetStringFromName(NS_LITERAL_STRING("KillScriptTitle").get(),
|
|
|
|
getter_Copies(title));
|
|
|
|
rv |= bundle->GetStringFromName(NS_LITERAL_STRING("StopScriptButton").get(),
|
|
|
|
getter_Copies(stopButton));
|
|
|
|
rv |= bundle->GetStringFromName(NS_LITERAL_STRING("WaitForScriptButton").get(),
|
|
|
|
getter_Copies(waitButton));
|
|
|
|
|
|
|
|
//GetStringFromName can return NS_OK and still give NULL string
|
|
|
|
if (NS_FAILED(rv) || !title || !msg || !stopButton || !waitButton) {
|
|
|
|
NS_ERROR("Failed to get localized strings.");
|
2000-06-24 16:18:41 +00:00
|
|
|
return JS_TRUE;
|
2004-02-11 22:22:05 +00:00
|
|
|
}
|
2000-06-24 16:18:41 +00:00
|
|
|
|
2005-02-02 21:41:07 +00:00
|
|
|
PRInt32 buttonPressed = 1; //In case user exits dialog by clicking X
|
|
|
|
|
|
|
|
// Open the dialog.
|
|
|
|
rv = prompt->ConfirmEx(title, msg,
|
|
|
|
(nsIPrompt::BUTTON_TITLE_IS_STRING *
|
|
|
|
nsIPrompt::BUTTON_POS_0) +
|
|
|
|
(nsIPrompt::BUTTON_TITLE_IS_STRING *
|
|
|
|
nsIPrompt::BUTTON_POS_1),
|
|
|
|
stopButton, waitButton,
|
|
|
|
nsnull, nsnull, nsnull, &buttonPressed);
|
|
|
|
|
2005-02-08 16:50:52 +00:00
|
|
|
if (NS_FAILED(rv) || (buttonPressed == 1)) {
|
|
|
|
// Allow the script to run this long again
|
|
|
|
ctx->mBranchCallbackTime = PR_Now();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_FALSE;
|
2000-06-24 16:18:41 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2004-04-29 23:34:19 +00:00
|
|
|
nsJSContext *context = NS_REINTERPRET_CAST(nsJSContext *, data);
|
|
|
|
PRUint32 oldDefaultJSOptions = context->mDefaultJSOptions;
|
|
|
|
PRUint32 newDefaultJSOptions = oldDefaultJSOptions;
|
2000-09-02 01:58:51 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
PRBool strict = nsContentUtils::GetBoolPref(js_strict_option_str);
|
|
|
|
if (strict)
|
|
|
|
newDefaultJSOptions |= JSOPTION_STRICT;
|
|
|
|
else
|
|
|
|
newDefaultJSOptions &= ~JSOPTION_STRICT;
|
|
|
|
|
|
|
|
PRBool werror = nsContentUtils::GetBoolPref(js_werror_option_str);
|
|
|
|
if (werror)
|
|
|
|
newDefaultJSOptions |= JSOPTION_WERROR;
|
|
|
|
else
|
|
|
|
newDefaultJSOptions &= ~JSOPTION_WERROR;
|
2000-09-02 01:58:51 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
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);
|
2000-09-02 01:58:51 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
// Save the new defaults for the next page load (InitContext).
|
|
|
|
context->mDefaultJSOptions = newDefaultJSOptions;
|
2000-09-02 01:58:51 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-04-07 17:07:36 +00:00
|
|
|
static jsuword
|
|
|
|
GetThreadStackLimit()
|
|
|
|
{
|
|
|
|
// Store the thread stack limit in a static local to ensure that all
|
|
|
|
// contexts get the same stack limit (they're all on the same thread
|
|
|
|
// anyways), and this also helps prevent returning a stack limit
|
|
|
|
// that is beyond the end of the stack if this method is called way
|
|
|
|
// deep on the stack.
|
|
|
|
|
|
|
|
static jsuword sThreadStackLimit;
|
|
|
|
|
|
|
|
if (sThreadStackLimit == 0) {
|
|
|
|
int stackDummy;
|
|
|
|
jsuword currentStackAddr = (jsuword)&stackDummy;
|
|
|
|
|
|
|
|
// We assume here that the stack grows down, and that a stack
|
|
|
|
// limit of 512k below the current stack addr is ok. If this is
|
|
|
|
// not the case on some platforms, #ifdef's are needed for those
|
|
|
|
// platforms.
|
|
|
|
sThreadStackLimit = currentStackAddr +
|
|
|
|
(0x80000 * JS_STACK_GROWTH_DIRECTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sThreadStackLimit;
|
|
|
|
}
|
|
|
|
|
2001-10-19 04:13:37 +00:00
|
|
|
nsJSContext::nsJSContext(JSRuntime *aRuntime) : mGCOnDestruction(PR_TRUE)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2002-05-03 03:02:07 +00:00
|
|
|
++sContextCount;
|
|
|
|
|
2005-06-08 02:13:10 +00:00
|
|
|
mDefaultJSOptions = JSOPTION_PRIVATE_IS_NSISUPPORTS
|
|
|
|
| JSOPTION_NATIVE_BRANCH_CALLBACK
|
2000-09-07 10:51:59 +00:00
|
|
|
#ifdef DEBUG
|
2005-06-08 02:13:10 +00:00
|
|
|
| JSOPTION_STRICT // lint catching for development
|
2000-09-07 10:51:59 +00:00
|
|
|
#endif
|
2001-08-07 05:27:42 +00:00
|
|
|
;
|
2000-10-26 03:40:23 +00:00
|
|
|
|
|
|
|
// Let xpconnect resync its JSContext tracker. We do this before creating
|
|
|
|
// a new JSContext just in case the heap manager recycles the JSContext
|
|
|
|
// struct.
|
2004-09-01 16:50:12 +00:00
|
|
|
nsContentUtils::XPConnect()->SyncJSContexts();
|
2000-10-26 03:40:23 +00:00
|
|
|
|
2000-01-08 00:24:24 +00:00
|
|
|
mContext = ::JS_NewContext(aRuntime, gStackSize);
|
1999-12-03 03:40:30 +00:00
|
|
|
if (mContext) {
|
2003-06-24 21:43:01 +00:00
|
|
|
::JS_SetContextPrivate(mContext, NS_STATIC_CAST(nsIScriptContext *, this));
|
1999-12-03 03:40:30 +00:00
|
|
|
|
2004-04-07 17:07:36 +00:00
|
|
|
::JS_SetThreadStackLimit(mContext, GetThreadStackLimit());
|
|
|
|
|
2001-09-18 03:32:03 +00:00
|
|
|
// Make sure the new context gets the default context options
|
|
|
|
::JS_SetOptions(mContext, mDefaultJSOptions);
|
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
// Check for the JS strict option, which enables extra error checks
|
2004-04-29 23:34:19 +00:00
|
|
|
nsContentUtils::RegisterPrefCallback(js_options_dot_str,
|
|
|
|
JSOptionChangedCallback,
|
|
|
|
this);
|
|
|
|
JSOptionChangedCallback(js_options_dot_str, this);
|
2000-06-24 16:18:41 +00:00
|
|
|
|
|
|
|
::JS_SetBranchCallback(mContext, DOMBranchCallback);
|
2003-06-24 21:09:57 +00:00
|
|
|
|
|
|
|
static JSLocaleCallbacks localeCallbacks =
|
|
|
|
{
|
|
|
|
LocaleToUpperCase,
|
|
|
|
LocaleToLowerCase,
|
2004-06-15 16:38:43 +00:00
|
|
|
LocaleCompare,
|
|
|
|
LocaleToUnicode
|
2003-06-24 21:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
::JS_SetLocaleCallbacks(mContext, &localeCallbacks);
|
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
|
|
|
mOwner = nsnull;
|
2005-06-09 15:42:19 +00:00
|
|
|
mTerminations = nsnull;
|
2000-03-28 00:15:56 +00:00
|
|
|
mScriptsEnabled = PR_TRUE;
|
2000-06-24 16:18:41 +00:00
|
|
|
mBranchCallbackCount = 0;
|
2004-02-11 22:22:05 +00:00
|
|
|
mBranchCallbackTime = LL_ZERO;
|
2001-05-15 22:26:19 +00:00
|
|
|
mProcessingScriptTag=PR_FALSE;
|
2001-09-05 04:29:13 +00:00
|
|
|
|
|
|
|
InvalidateContextAndWrapperCache();
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsJSContext::~nsJSContext()
|
|
|
|
{
|
2005-06-09 15:42:19 +00:00
|
|
|
NS_PRECONDITION(!mTerminations, "Shouldn't have termination funcs by now");
|
|
|
|
|
(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
|
|
|
// Cope with JS_NewContext failure in ctor (XXXbe move NewContext to Init?)
|
|
|
|
if (!mContext)
|
|
|
|
return;
|
|
|
|
|
2001-02-02 06:05:17 +00:00
|
|
|
// Clear our entry in the JSContext, bugzilla bug 66413
|
|
|
|
::JS_SetContextPrivate(mContext, nsnull);
|
|
|
|
|
2004-03-24 02:04:16 +00:00
|
|
|
// Clear the branch callback, bugzilla bug 238218
|
|
|
|
::JS_SetBranchCallback(mContext, nsnull);
|
|
|
|
|
2000-09-02 01:58:51 +00:00
|
|
|
// Unregister our "javascript.options.*" pref-changed callback.
|
2004-04-29 23:34:19 +00:00
|
|
|
nsContentUtils::UnregisterPrefCallback(js_options_dot_str,
|
|
|
|
JSOptionChangedCallback,
|
|
|
|
this);
|
2000-09-02 01:58:51 +00:00
|
|
|
|
2001-10-31 08:39:09 +00:00
|
|
|
// Release mGlobalWrapperRef before the context is destroyed
|
|
|
|
mGlobalWrapperRef = nsnull;
|
|
|
|
|
2001-08-15 04:49:09 +00:00
|
|
|
// Let xpconnect destroy the JSContext when it thinks the time is right.
|
2004-09-01 16:50:12 +00:00
|
|
|
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (xpc) {
|
2001-11-27 09:46:38 +00:00
|
|
|
PRBool do_gc = mGCOnDestruction && !sGCTimer && sReadyForGC;
|
|
|
|
|
|
|
|
xpc->ReleaseJSContext(mContext, !do_gc);
|
2001-08-15 04:49:09 +00:00
|
|
|
} else {
|
|
|
|
::JS_DestroyContext(mContext);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
}
|
2002-05-03 03:02:07 +00:00
|
|
|
|
|
|
|
--sContextCount;
|
|
|
|
|
|
|
|
if (!sContextCount && sDidShutdown) {
|
|
|
|
// The last context is being deleted, and we're already in the
|
2003-04-17 20:21:00 +00:00
|
|
|
// process of shutting down, release the JS runtime service, and
|
|
|
|
// the security manager.
|
2002-05-03 03:02:07 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(sRuntimeService);
|
2003-04-17 20:21:00 +00:00
|
|
|
NS_IF_RELEASE(sSecurityManager);
|
2003-06-24 21:09:57 +00:00
|
|
|
NS_IF_RELEASE(gCollation);
|
2004-06-15 16:38:43 +00:00
|
|
|
NS_IF_RELEASE(gDecoder);
|
2002-05-03 03:02:07 +00:00
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
// QueryInterface implementation for nsJSContext
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsJSContext)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptContext)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptNotify)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptContext)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsJSContext)
|
|
|
|
NS_IMPL_RELEASE(nsJSContext)
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
2002-03-24 00:16:18 +00:00
|
|
|
nsJSContext::EvaluateStringWithValue(const nsAString& 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) {
|
2003-03-11 22:24:02 +00:00
|
|
|
if (aIsUndefined) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-03-29 01:18:21 +00:00
|
|
|
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;
|
2004-04-18 00:28:47 +00:00
|
|
|
nsIPrincipal *principal = aPrincipal;
|
2000-03-29 01:18:21 +00:00
|
|
|
if (aPrincipal) {
|
2003-11-03 04:26:55 +00:00
|
|
|
aPrincipal->GetJSPrincipals(mContext, &jsprin);
|
2000-03-29 01:18:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptGlobalObject *global = GetGlobalObject();
|
2000-03-29 01:18:21 +00:00
|
|
|
if (!global)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-02-09 22:48:53 +00:00
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
|
|
|
|
do_QueryInterface(global, &rv);
|
2000-03-29 01:18:21 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-04-18 00:28:47 +00:00
|
|
|
principal = objPrincipal->GetPrincipal();
|
|
|
|
if (!principal)
|
2000-03-29 01:18:21 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-11-03 04:26:55 +00:00
|
|
|
principal->GetJSPrincipals(mContext, &jsprin);
|
2000-03-29 01:18:21 +00:00
|
|
|
}
|
|
|
|
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
|
|
|
|
|
|
|
PRBool ok = PR_FALSE;
|
2004-02-09 22:48:53 +00:00
|
|
|
|
|
|
|
rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
|
2000-03-29 01:18:21 +00:00
|
|
|
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.
|
2003-06-24 21:09:57 +00:00
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
2001-07-25 07:54:28 +00:00
|
|
|
do_GetService("@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;
|
|
|
|
}
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
// The result of evaluation, used only if there were no errors. TODO: use
|
|
|
|
// JS_Begin/EndRequest to keep the GC from racing with JS execution on any
|
|
|
|
// thread.
|
2000-03-29 01:18:21 +00:00
|
|
|
jsval val;
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
nsJSContext::TerminationFuncHolder holder(this);
|
2000-03-29 01:18:21 +00:00
|
|
|
if (ok) {
|
2002-02-05 05:43:08 +00:00
|
|
|
JSVersion newVersion = JSVERSION_UNKNOWN;
|
2000-03-29 01:18:21 +00:00
|
|
|
|
|
|
|
// 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) {
|
2002-02-05 05:43:08 +00:00
|
|
|
JSVersion oldVersion = JSVERSION_UNKNOWN;
|
2000-03-29 01:18:21 +00:00
|
|
|
|
|
|
|
if (aVersion)
|
|
|
|
oldVersion = ::JS_SetVersion(mContext, newVersion);
|
|
|
|
ok = ::JS_EvaluateUCScriptForPrincipals(mContext,
|
|
|
|
(JSObject *)aScopeObject,
|
|
|
|
jsprin,
|
2005-04-26 01:23:53 +00:00
|
|
|
(jschar*)PromiseFlatString(aScript).get(),
|
2000-03-29 01:18:21 +00:00
|
|
|
aScript.Length(),
|
|
|
|
aURL,
|
|
|
|
aLineNo,
|
|
|
|
&val);
|
2003-11-21 19:48:35 +00:00
|
|
|
|
2004-06-11 00:48:00 +00:00
|
|
|
if (aVersion) {
|
2000-03-29 01:18:21 +00:00
|
|
|
::JS_SetVersion(mContext, oldVersion);
|
2004-06-11 00:48:00 +00:00
|
|
|
}
|
2003-11-21 19:48:35 +00:00
|
|
|
|
|
|
|
if (!ok) {
|
2003-12-02 22:14:48 +00:00
|
|
|
// Tell XPConnect about any pending exceptions. This is needed
|
2003-11-21 19:48:35 +00:00
|
|
|
// to avoid dropping JS exceptions in case we got here through
|
|
|
|
// nested calls through XPConnect.
|
|
|
|
|
2003-12-02 22:14:48 +00:00
|
|
|
NotifyXPCIfExceptionPending(mContext);
|
2003-11-21 19:48:35 +00:00
|
|
|
}
|
2000-03-29 01:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2003-03-11 22:24:02 +00:00
|
|
|
if (aIsUndefined) {
|
|
|
|
*aIsUndefined = JSVAL_IS_VOID(val);
|
|
|
|
}
|
|
|
|
|
2000-03-29 01:18:21 +00:00
|
|
|
*NS_STATIC_CAST(jsval*, aRetValue) = val;
|
|
|
|
}
|
|
|
|
else {
|
2003-03-11 22:24:02 +00:00
|
|
|
if (aIsUndefined) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
}
|
2000-03-29 01:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pop here, after JS_ValueToString and any other possible evaluation.
|
|
|
|
if (NS_FAILED(stack->Pop(nsnull)))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
// Need to lock, since ScriptEvaluated can GC.
|
|
|
|
PRBool locked = PR_FALSE;
|
|
|
|
if (ok && JSVAL_IS_GCTHING(val)) {
|
|
|
|
locked = ::JS_LockGCThing(mContext, JSVAL_TO_GCTHING(val));
|
|
|
|
if (!locked) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScriptEvaluated needs to come after we pop the stack
|
|
|
|
ScriptEvaluated(PR_TRUE);
|
|
|
|
|
|
|
|
if (locked) {
|
|
|
|
::JS_UnlockGCThing(mContext, JSVAL_TO_GCTHING(val));
|
|
|
|
}
|
|
|
|
|
2000-03-29 01:18:21 +00:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-05-12 22:23:52 +00:00
|
|
|
// Helper function to convert a jsval to an nsAString, and set
|
|
|
|
// exception flags if the conversion fails.
|
|
|
|
static nsresult
|
|
|
|
JSValueToAString(JSContext *cx, jsval val, nsAString *result,
|
|
|
|
PRBool *isUndefined)
|
|
|
|
{
|
|
|
|
if (isUndefined) {
|
|
|
|
*isUndefined = JSVAL_IS_VOID(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString* jsstring = ::JS_ValueToString(cx, val);
|
|
|
|
if (jsstring) {
|
|
|
|
result->Assign(NS_REINTERPRET_CAST(const PRUnichar*,
|
|
|
|
::JS_GetStringChars(jsstring)),
|
|
|
|
::JS_GetStringLength(jsstring));
|
|
|
|
} else {
|
|
|
|
result->Truncate();
|
|
|
|
|
|
|
|
// We failed to convert val to a string. We're either OOM, or the
|
|
|
|
// security manager denied access to .toString(), or somesuch, on
|
|
|
|
// an object. Treat this case as if the result were undefined.
|
|
|
|
|
|
|
|
if (isUndefined) {
|
|
|
|
*isUndefined = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!::JS_IsExceptionPending(cx)) {
|
|
|
|
// JS_ValueToString() returned null w/o an exception
|
|
|
|
// pending. That means we're OOM.
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-12-02 22:14:48 +00:00
|
|
|
// Tell XPConnect about any pending exceptions. This is needed to
|
2003-11-21 19:48:35 +00:00
|
|
|
// avoid dropping JS exceptions in case we got here through nested
|
|
|
|
// calls through XPConnect.
|
2003-12-02 22:14:48 +00:00
|
|
|
|
|
|
|
NotifyXPCIfExceptionPending(cx);
|
2003-05-12 22:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
2002-03-24 00:16:18 +00:00
|
|
|
nsJSContext::EvaluateString(const nsAString& 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,
|
2004-06-11 00:48:00 +00:00
|
|
|
nsAString *aRetValue,
|
1999-09-15 20:58:41 +00:00
|
|
|
PRBool* aIsUndefined)
|
|
|
|
{
|
2000-03-28 00:15:56 +00:00
|
|
|
if (!mScriptsEnabled) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
2004-06-11 00:48:00 +00:00
|
|
|
|
|
|
|
if (aRetValue) {
|
|
|
|
aRetValue->Truncate();
|
|
|
|
}
|
|
|
|
|
2000-03-28 00:15:56 +00:00
|
|
|
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;
|
2004-04-18 00:28:47 +00:00
|
|
|
nsIPrincipal *principal = aPrincipal;
|
1999-11-12 06:08:14 +00:00
|
|
|
if (aPrincipal) {
|
2003-11-03 04:26:55 +00:00
|
|
|
aPrincipal->GetJSPrincipals(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
|
|
|
}
|
|
|
|
else {
|
2004-02-18 02:17:32 +00:00
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
|
|
|
|
do_QueryInterface(GetGlobalObject(), &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;
|
2004-04-18 00:28:47 +00:00
|
|
|
principal = objPrincipal->GetPrincipal();
|
|
|
|
if (!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
|
|
|
return NS_ERROR_FAILURE;
|
2003-11-03 04:26:55 +00:00
|
|
|
principal->GetJSPrincipals(mContext, &jsprin);
|
1999-09-17 20:13:52 +00:00
|
|
|
}
|
2004-02-18 02:17:32 +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;
|
2004-02-09 22:48:53 +00:00
|
|
|
|
|
|
|
rv = sSecurityManager->CanExecuteScripts(mContext, 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.
|
2003-06-24 21:09:57 +00:00
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
2001-07-25 07:54:28 +00:00
|
|
|
do_GetService("@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;
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
nsJSContext::TerminationFuncHolder holder(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
|
|
|
if (ok) {
|
2002-02-05 05:43:08 +00:00
|
|
|
JSVersion newVersion = JSVERSION_UNKNOWN;
|
(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
|
|
|
|
|
|
|
// 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) {
|
2002-02-05 05:43:08 +00:00
|
|
|
JSVersion oldVersion = JSVERSION_UNKNOWN;
|
(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 (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
|
|
|
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,
|
2005-04-26 01:23:53 +00:00
|
|
|
(jschar*)PromiseFlatString(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);
|
2003-11-21 19:48:35 +00:00
|
|
|
|
|
|
|
if (aVersion) {
|
2000-01-08 00:24:24 +00:00
|
|
|
::JS_SetVersion(mContext, oldVersion);
|
2003-11-21 19:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
2003-12-02 22:14:48 +00:00
|
|
|
// Tell XPConnect about any pending exceptions. This is needed
|
|
|
|
// to avoid dropping JS exceptions in case we got here through
|
|
|
|
// nested calls through XPConnect.
|
|
|
|
|
|
|
|
NotifyXPCIfExceptionPending(mContext);
|
2003-11-21 19:48:35 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2004-06-11 00:48:00 +00:00
|
|
|
rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
|
1999-08-19 20:36:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-03-11 22:24:02 +00:00
|
|
|
if (aIsUndefined) {
|
|
|
|
*aIsUndefined = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-11 00:48:00 +00:00
|
|
|
if (aRetValue) {
|
|
|
|
aRetValue->Truncate();
|
|
|
|
}
|
1999-08-19 20:36:31 +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
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
// ScriptEvaluated needs to come after we pop the stack
|
|
|
|
ScriptEvaluated(PR_TRUE);
|
|
|
|
|
1999-11-12 06:08:14 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
1999-11-12 06:08:14 +00:00
|
|
|
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;
|
2003-11-03 04:26:55 +00:00
|
|
|
aPrincipal->GetJSPrincipals(mContext, &jsprin);
|
1999-11-12 06:08:14 +00:00
|
|
|
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
|
|
|
|
|
|
|
PRBool ok = PR_FALSE;
|
2004-02-09 22:48:53 +00:00
|
|
|
|
|
|
|
rv = sSecurityManager->CanExecuteScripts(mContext, aPrincipal, &ok);
|
1999-11-12 06:08:14 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aScriptObject = nsnull;
|
|
|
|
if (ok) {
|
2002-02-05 05:43:08 +00:00
|
|
|
JSVersion newVersion = JSVERSION_UNKNOWN;
|
1999-11-12 06:08:14 +00:00
|
|
|
|
|
|
|
// 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) {
|
2002-02-05 05:43:08 +00:00
|
|
|
JSVersion oldVersion = JSVERSION_UNKNOWN;
|
1999-11-12 06:08:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
1999-11-12 06:08:14 +00:00
|
|
|
nsJSContext::ExecuteScript(void* aScriptObject,
|
|
|
|
void *aScopeObject,
|
2002-03-24 00:16:18 +00:00
|
|
|
nsAString* aRetValue,
|
1999-11-12 06:08:14 +00:00
|
|
|
PRBool* aIsUndefined)
|
|
|
|
{
|
2000-03-28 00:15:56 +00:00
|
|
|
if (!mScriptsEnabled) {
|
2003-03-11 22:24:02 +00:00
|
|
|
if (aIsUndefined) {
|
2000-11-09 04:35:38 +00:00
|
|
|
*aIsUndefined = PR_TRUE;
|
2003-03-11 22:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aRetValue) {
|
2000-09-27 23:08:09 +00:00
|
|
|
aRetValue->Truncate();
|
2003-03-11 22:24:02 +00:00
|
|
|
}
|
|
|
|
|
2000-03-28 00:15:56 +00:00
|
|
|
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.
|
2003-06-24 21:09:57 +00:00
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
2001-07-25 07:54:28 +00:00
|
|
|
do_GetService("@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;
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
nsJSContext::TerminationFuncHolder holder(this);
|
1999-11-12 06:08:14 +00:00
|
|
|
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?).
|
2003-03-11 22:24:02 +00:00
|
|
|
|
2003-05-12 22:23:52 +00:00
|
|
|
rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
|
1999-11-12 06:08:14 +00:00
|
|
|
} else {
|
2003-03-11 22:24:02 +00:00
|
|
|
if (aIsUndefined) {
|
1999-11-12 06:08:14 +00:00
|
|
|
*aIsUndefined = PR_TRUE;
|
2003-03-11 22:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aRetValue) {
|
1999-11-12 06:08:14 +00:00
|
|
|
aRetValue->Truncate();
|
2003-03-11 22:24:02 +00:00
|
|
|
}
|
2003-11-21 19:48:35 +00:00
|
|
|
|
2003-12-02 22:14:48 +00:00
|
|
|
// Tell XPConnect about any pending exceptions. This is needed to
|
2003-11-21 19:48:35 +00:00
|
|
|
// avoid dropping JS exceptions in case we got here through nested
|
|
|
|
// calls through XPConnect.
|
2003-12-02 22:14:48 +00:00
|
|
|
|
|
|
|
NotifyXPCIfExceptionPending(mContext);
|
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
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
// ScriptEvaluated needs to come after we pop the stack
|
|
|
|
ScriptEvaluated(PR_TRUE);
|
|
|
|
|
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
|
|
|
|
2003-07-01 05:11:46 +00:00
|
|
|
static inline const char *
|
|
|
|
AtomToEventHandlerName(nsIAtom *aName)
|
1999-12-03 03:40:30 +00:00
|
|
|
{
|
2003-03-25 18:55:59 +00:00
|
|
|
const char *name;
|
1999-12-03 03:40:30 +00:00
|
|
|
|
2003-07-01 05:11:46 +00:00
|
|
|
aName->GetUTF8String(&name);
|
1999-12-03 03:40:30 +00:00
|
|
|
|
2003-07-01 05:11:46 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
const char *cp;
|
|
|
|
char c;
|
|
|
|
for (cp = name; *cp != '\0'; ++cp)
|
|
|
|
{
|
|
|
|
c = *cp;
|
|
|
|
NS_ASSERTION (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'),
|
|
|
|
"non-ASCII non-alphabetic event handler name");
|
|
|
|
}
|
|
|
|
#endif
|
1999-12-03 03:40:30 +00:00
|
|
|
|
2003-07-01 05:11:46 +00:00
|
|
|
return name;
|
1999-12-03 03:40:30 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName,
|
2004-07-22 16:38:05 +00:00
|
|
|
const char *aEventName,
|
2002-03-24 00:16:18 +00:00
|
|
|
const nsAString& aBody,
|
2003-07-11 22:54:36 +00:00
|
|
|
const char *aURL, PRUint32 aLineNo,
|
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
|
|
|
{
|
2003-04-17 20:21:00 +00:00
|
|
|
if (!sSecurityManager) {
|
|
|
|
NS_ERROR("Huh, we need a script security manager to compile "
|
|
|
|
"an event handler!");
|
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *target = (JSObject*)aTarget;
|
|
|
|
|
(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;
|
|
|
|
|
2003-04-17 20:21:00 +00:00
|
|
|
if (target) {
|
|
|
|
// Get the principal of the event target (the object principal),
|
|
|
|
// don't get the principal of the global object in this context
|
|
|
|
// since that opens up security exploits with delayed event
|
|
|
|
// handler compilation on stale DOM objects (objects that live in
|
|
|
|
// a document that has already been unloaded).
|
|
|
|
nsCOMPtr<nsIPrincipal> prin;
|
|
|
|
nsresult rv = sSecurityManager->GetObjectPrincipal(mContext, target,
|
|
|
|
getter_AddRefs(prin));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-11-03 04:26:55 +00:00
|
|
|
prin->GetJSPrincipals(mContext, &jsprin);
|
2003-04-17 20:21:00 +00:00
|
|
|
NS_ENSURE_TRUE(jsprin, NS_ERROR_NOT_AVAILABLE);
|
(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
|
|
|
}
|
|
|
|
|
2003-07-01 05:11:46 +00:00
|
|
|
const char *charName = AtomToEventHandlerName(aName);
|
(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
|
|
|
|
2004-07-22 16:38:05 +00:00
|
|
|
const char *argList[] = { aEventName };
|
|
|
|
|
1999-12-07 22:14:17 +00:00
|
|
|
JSFunction* fun =
|
2005-06-08 02:13:10 +00:00
|
|
|
::JS_CompileUCFunctionForPrincipals(mContext,
|
|
|
|
aShared ? nsnull : target, jsprin,
|
2004-07-22 16:38:05 +00:00
|
|
|
charName, 1, argList,
|
2005-04-26 01:23:53 +00:00
|
|
|
(jschar*)PromiseFlatString(aBody).get(),
|
2000-01-08 00:24:24 +00:00
|
|
|
aBody.Length(),
|
2003-07-11 22:54:36 +00:00
|
|
|
aURL, 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
|
|
|
|
2003-04-17 20:21:00 +00:00
|
|
|
if (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
|
|
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
2003-04-17 20:21:00 +00:00
|
|
|
}
|
|
|
|
if (!fun) {
|
1999-12-03 03:40:30 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-04-17 20:21:00 +00:00
|
|
|
}
|
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;
|
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
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
2000-03-29 01:18:21 +00:00
|
|
|
nsJSContext::CompileFunction(void* aTarget,
|
2003-06-24 01:20:40 +00:00
|
|
|
const nsACString& aName,
|
2000-03-29 01:18:21 +00:00
|
|
|
PRUint32 aArgCount,
|
|
|
|
const char** aArgArray,
|
2002-03-24 00:16:18 +00:00
|
|
|
const nsAString& aBody,
|
2000-03-29 01:18:21 +00:00
|
|
|
const char* aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
PRBool aShared,
|
|
|
|
void** aFunctionObject)
|
|
|
|
{
|
|
|
|
JSPrincipals *jsprin = nsnull;
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptGlobalObject *global = GetGlobalObject();
|
2000-03-29 01:18:21 +00:00
|
|
|
if (global) {
|
|
|
|
// XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func?
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);
|
|
|
|
if (globalData) {
|
2004-04-18 00:28:47 +00:00
|
|
|
nsIPrincipal *prin = globalData->GetPrincipal();
|
|
|
|
if (!prin)
|
2000-03-29 01:18:21 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-11-03 04:26:55 +00:00
|
|
|
prin->GetJSPrincipals(mContext, &jsprin);
|
2000-03-29 01:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *target = (JSObject*)aTarget;
|
|
|
|
JSFunction* fun =
|
2005-06-08 02:13:10 +00:00
|
|
|
::JS_CompileUCFunctionForPrincipals(mContext,
|
|
|
|
aShared ? nsnull : target, jsprin,
|
2003-06-24 01:20:40 +00:00
|
|
|
PromiseFlatCString(aName).get(),
|
|
|
|
aArgCount, aArgArray,
|
2005-04-26 01:23:53 +00:00
|
|
|
(jschar*)PromiseFlatString(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;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
2004-02-11 06:09:51 +00:00
|
|
|
nsJSContext::CallEventHandler(JSObject *aTarget, JSObject *aHandler,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
1999-09-17 20:13:52 +00:00
|
|
|
{
|
2004-02-11 06:09:51 +00:00
|
|
|
*rval = JSVAL_VOID;
|
2003-12-21 18:01:19 +00:00
|
|
|
|
2002-01-24 13:25:46 +00:00
|
|
|
if (!mScriptsEnabled) {
|
|
|
|
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
|
|
|
// 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
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
2003-12-21 18:01:19 +00:00
|
|
|
do_GetService("@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;
|
|
|
|
|
2000-06-21 00:21:50 +00:00
|
|
|
// check if the event handler can be run on the object in question
|
2004-02-09 22:48:53 +00:00
|
|
|
rv = sSecurityManager->CheckFunctionAccess(mContext, aHandler, aTarget);
|
2000-06-21 00:21:50 +00:00
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
nsJSContext::TerminationFuncHolder holder(this);
|
|
|
|
|
2003-12-21 18:01:19 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-04-14 03:14:53 +00:00
|
|
|
jsval funval = OBJECT_TO_JSVAL(aHandler);
|
2004-02-11 06:09:51 +00:00
|
|
|
PRBool ok = ::JS_CallFunctionValue(mContext, aTarget, funval, argc, argv,
|
|
|
|
rval);
|
2003-11-21 19:48:35 +00:00
|
|
|
|
2004-02-11 06:09:51 +00:00
|
|
|
if (!ok) {
|
2003-12-02 22:14:48 +00:00
|
|
|
// Tell XPConnect about any pending exceptions. This is needed
|
|
|
|
// to avoid dropping JS exceptions in case we got here through
|
|
|
|
// nested calls through XPConnect.
|
|
|
|
|
|
|
|
NotifyXPCIfExceptionPending(mContext);
|
2004-02-11 06:09:51 +00:00
|
|
|
|
|
|
|
// Don't pass back results from failed calls.
|
|
|
|
*rval = JSVAL_VOID;
|
2004-02-20 20:46:22 +00:00
|
|
|
|
|
|
|
// Tell the caller that the handler threw an error.
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2003-11-21 19:48:35 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
// Need to lock, since ScriptEvaluated can GC.
|
|
|
|
PRBool locked = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(rv) && JSVAL_IS_GCTHING(*rval)) {
|
|
|
|
locked = ::JS_LockGCThing(mContext, JSVAL_TO_GCTHING(*rval));
|
|
|
|
if (!locked) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScriptEvaluated needs to come after we pop the stack
|
|
|
|
ScriptEvaluated(PR_TRUE);
|
|
|
|
|
|
|
|
if (locked) {
|
|
|
|
::JS_UnlockGCThing(mContext, JSVAL_TO_GCTHING(*rval));
|
|
|
|
}
|
|
|
|
|
2004-02-20 20:46:22 +00:00
|
|
|
return rv;
|
1999-09-17 20:13:52 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
2003-12-02 22:14:48 +00:00
|
|
|
nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName,
|
|
|
|
void *aHandler)
|
1999-12-03 03:40:30 +00:00
|
|
|
{
|
2003-07-01 05:11:46 +00:00
|
|
|
const char *charName = AtomToEventHandlerName(aName);
|
1999-12-03 03:40:30 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
(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
|
|
|
nsJSContext::SetDefaultLanguageVersion(const char* aVersion)
|
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
::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
|
|
|
}
|
1999-09-17 20:13:52 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
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
|
|
|
|
2001-05-26 07:44:19 +00:00
|
|
|
if (!global) {
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_WARNING("Context has no global.");
|
2004-02-09 22:48:53 +00:00
|
|
|
return nsnull;
|
2001-05-26 07:44:19 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2001-05-26 07:44:19 +00:00
|
|
|
JSClass *c = JS_GET_CLASS(mContext, global);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2001-05-26 07:44:19 +00:00
|
|
|
if (!c || ((~c->flags) & (JSCLASS_HAS_PRIVATE |
|
|
|
|
JSCLASS_PRIVATE_IS_NSISUPPORTS))) {
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_WARNING("Global is not an nsISupports.");
|
2004-02-09 22:48:53 +00:00
|
|
|
return nsnull;
|
2001-05-26 07:44:19 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
nsISupports *priv =
|
2001-05-26 07:44:19 +00:00
|
|
|
(nsISupports *)::JS_GetPrivate(mContext, global);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2001-05-26 07:44:19 +00:00
|
|
|
nsCOMPtr<nsIXPConnectWrappedNative> wrapped_native =
|
2004-02-09 22:48:53 +00:00
|
|
|
do_QueryInterface(priv);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2001-05-26 07:44:19 +00:00
|
|
|
if (wrapped_native) {
|
|
|
|
// The global object is a XPConnect wrapped native, the native in
|
|
|
|
// the wrapper might be the nsIScriptGlobalObject
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2005-03-10 00:39:28 +00:00
|
|
|
sgo = do_QueryWrappedNative(wrapped_native);
|
2004-02-09 22:48:53 +00:00
|
|
|
} else {
|
|
|
|
sgo = do_QueryInterface(priv);
|
|
|
|
}
|
2001-06-20 03:27:48 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
// This'll return a pointer to something we're about to release, but
|
|
|
|
// that's ok, the JS object will hold it alive long enough.
|
|
|
|
return sgo;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void *
|
1998-12-21 16:51:10 +00:00
|
|
|
nsJSContext::GetNativeContext()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
return mContext;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
1998-12-21 16:51:10 +00:00
|
|
|
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;
|
|
|
|
|
2001-09-05 04:29:13 +00:00
|
|
|
InvalidateContextAndWrapperCache();
|
|
|
|
|
(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;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
|
|
|
if (!gNameSpaceManager) {
|
|
|
|
gNameSpaceManager = new nsScriptNameSpaceManager;
|
|
|
|
NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
rv = gNameSpaceManager->Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2001-05-18 07:25:56 +00:00
|
|
|
::JS_SetErrorReporter(mContext, NS_ScriptErrorReporter);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (!aGlobalObject) {
|
|
|
|
// If we don't get a global object then there's nothing more to do here.
|
|
|
|
|
|
|
|
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
|
|
|
mIsInitialized = PR_FALSE;
|
|
|
|
|
2004-09-01 16:50:12 +00:00
|
|
|
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
(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
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
JSObject *global = ::JS_GetGlobalObject(mContext);
|
2000-08-22 03:51:17 +00:00
|
|
|
|
2001-10-31 08:39:09 +00:00
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
// If there's already a global object in mContext we won't tell
|
|
|
|
// XPConnect to wrap aGlobalObject since it's already wrapped.
|
(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
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (!global) {
|
2005-05-20 03:12:22 +00:00
|
|
|
nsCOMPtr<nsIDOMChromeWindow> chromeWindow(do_QueryInterface(aGlobalObject));
|
|
|
|
|
|
|
|
PRUint32 flags = chromeWindow ? nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT : 0;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
rv = xpc->InitClassesWithNewWrappedGlobal(mContext, aGlobalObject,
|
|
|
|
NS_GET_IID(nsISupports),
|
2005-05-20 03:12:22 +00:00
|
|
|
flags,
|
2001-05-18 07:25:56 +00:00
|
|
|
getter_AddRefs(holder));
|
2001-07-11 09:09:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
} else {
|
|
|
|
// If there's already a global object in mContext we're called
|
2001-07-17 06:20:37 +00:00
|
|
|
// after ::JS_ClearScope() was called. We'll have to tell XPConnect
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
// to re-initialize the global object to do things like define the
|
|
|
|
// Components object on the global again.
|
|
|
|
rv = xpc->InitClasses(mContext, global);
|
2001-07-11 09:09:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, 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
|
|
|
|
2001-07-11 09:09:30 +00:00
|
|
|
nsCOMPtr<nsIClassInfo> ci(do_QueryInterface(aGlobalObject));
|
|
|
|
|
|
|
|
if (ci) {
|
2001-07-17 06:20:37 +00:00
|
|
|
rv = xpc->WrapNative(mContext, global, aGlobalObject,
|
|
|
|
NS_GET_IID(nsISupports),
|
|
|
|
getter_AddRefs(holder));
|
2001-07-11 09:09:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2001-07-17 06:20:37 +00:00
|
|
|
nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(holder));
|
|
|
|
NS_ENSURE_TRUE(wrapper, NS_ERROR_FAILURE);
|
2001-07-11 09:09:30 +00:00
|
|
|
|
2001-07-17 06:20:37 +00:00
|
|
|
rv = wrapper->RefreshPrototype();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-07-11 09:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2001-10-31 08:39:09 +00:00
|
|
|
// Hold a strong reference to the wrapper for the global to avoid
|
|
|
|
// rooting and unrooting the global object every time its AddRef()
|
|
|
|
// or Release() methods are called
|
|
|
|
mGlobalWrapperRef = holder;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
rv = InitClasses(); // this will complete global object initialization
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mIsInitialized = 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
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
1998-12-30 21:35:35 +00:00
|
|
|
nsresult
|
|
|
|
nsJSContext::InitializeExternalClasses()
|
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
return gNameSpaceManager->InitForContext(this);
|
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;
|
2001-05-26 07:44:19 +00:00
|
|
|
|
2003-03-25 06:54:52 +00:00
|
|
|
#ifdef OJI
|
2001-05-17 09:01:03 +00:00
|
|
|
nsCOMPtr<nsIJVMManager> jvmManager =
|
|
|
|
do_GetService(nsIJVMManager::GetCID(), &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && jvmManager) {
|
(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
|
|
|
PRBool javaEnabled = PR_FALSE;
|
2001-05-17 09:01:03 +00:00
|
|
|
|
|
|
|
rv = jvmManager->GetJavaEnabled(&javaEnabled);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && javaEnabled) {
|
|
|
|
nsCOMPtr<nsILiveConnectManager> liveConnectManager =
|
|
|
|
do_QueryInterface(jvmManager);
|
|
|
|
|
(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 (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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-25 06:54:52 +00:00
|
|
|
#endif /* OJI */
|
(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}
|
|
|
|
};
|
|
|
|
|
2001-03-19 21:46:25 +00:00
|
|
|
static JSBool JS_DLL_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;
|
|
|
|
}
|
|
|
|
|
2001-03-19 21:46:25 +00:00
|
|
|
static JSBool JS_DLL_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);
|
2001-08-07 05:27:42 +00:00
|
|
|
|
|
|
|
// Don't let options other than strict and werror be set -- it would be
|
|
|
|
// bad if web page script could clear JSOPTION_PRIVATE_IS_NSISUPPORTS!
|
2000-09-01 03:10:33 +00:00
|
|
|
if ((optbit & (optbit - 1)) == 0 && optbit <= JSOPTION_WERROR) {
|
|
|
|
JSBool optval;
|
2001-08-07 05:27:42 +00:00
|
|
|
if (! ::JS_ValueToBoolean(cx, *vp, &optval))
|
2000-09-01 03:10:33 +00:00
|
|
|
return JS_FALSE;
|
2001-08-07 05:27:42 +00:00
|
|
|
|
|
|
|
uint32 optset = ::JS_GetOptions(cx);
|
2000-09-01 03:10:33 +00:00
|
|
|
if (optval)
|
|
|
|
optset |= optbit;
|
|
|
|
else
|
|
|
|
optset &= ~optbit;
|
2001-08-07 05:27:42 +00:00
|
|
|
::JS_SetOptions(cx, optset);
|
2000-09-01 03:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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>
|
2001-01-25 22:54:05 +00:00
|
|
|
#ifdef XP_UNIX
|
2000-04-27 04:02:22 +00:00
|
|
|
#include <unistd.h>
|
2001-01-25 22:54:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2000-04-27 04:02:22 +00:00
|
|
|
#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)
|
|
|
|
{
|
2001-01-25 22:54:05 +00:00
|
|
|
int32 fd, oldfd;
|
2000-05-17 06:58:48 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2004-05-11 02:37:25 +00:00
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
IsJProfAction(struct sigaction *action)
|
|
|
|
{
|
|
|
|
return (action->sa_sigaction &&
|
|
|
|
action->sa_flags == SA_RESTART | SA_SIGINFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
JProfStartProfiling(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
// Figure out whether we're dealing with SIGPROF, SIGALRM, or
|
|
|
|
// SIGPOLL profiling (SIGALRM for JP_REALTIME, SIGPOLL for
|
|
|
|
// JP_RTC_HZ)
|
|
|
|
struct sigaction action;
|
|
|
|
|
|
|
|
sigaction(SIGALRM, nsnull, &action);
|
|
|
|
if (IsJProfAction(&action)) {
|
|
|
|
printf("Beginning real-time jprof profiling.\n");
|
|
|
|
raise(SIGALRM);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sigaction(SIGPROF, nsnull, &action);
|
|
|
|
if (IsJProfAction(&action)) {
|
|
|
|
printf("Beginning process-time jprof profiling.\n");
|
|
|
|
raise(SIGPROF);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sigaction(SIGPOLL, nsnull, &action);
|
|
|
|
if (IsJProfAction(&action)) {
|
|
|
|
printf("Beginning rtc-based jprof profiling.\n");
|
|
|
|
raise(SIGPOLL);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Could not start jprof-profiling since JPROF_FLAGS was not set.\n");
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
JProfStopProfiling(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
raise(SIGUSR1);
|
|
|
|
printf("Stopped jprof profiling.\n");
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSFunctionSpec JProfFunctions[] = {
|
|
|
|
{"JProfStartProfiling", JProfStartProfiling, 0, 0, 0},
|
|
|
|
{"JProfStopProfiling", JProfStopProfiling, 0, 0, 0},
|
|
|
|
{nsnull, nsnull, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* defined(MOZ_JPROF) */
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsresult
|
1998-12-21 16:51:10 +00:00
|
|
|
nsJSContext::InitClasses()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2000-09-02 01:58:51 +00:00
|
|
|
nsresult rv = NS_OK;
|
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
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
rv = InitializeExternalClasses();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-04-27 04:02:22 +00:00
|
|
|
|
2001-05-17 09:01:03 +00:00
|
|
|
rv = InitializeLiveConnectClasses();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-01-22 03:22:35 +00:00
|
|
|
rv = nsDOMClassInfo::InitDOMJSClass(mContext, globalObj);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-09-02 04:19:45 +00:00
|
|
|
// Initialize the options object and set default options in mContext
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
JSObject *optionsObj = ::JS_DefineObject(mContext, globalObj, "_options",
|
|
|
|
&OptionsClass, nsnull, 0);
|
|
|
|
if (optionsObj &&
|
|
|
|
::JS_DefineProperties(mContext, optionsObj, OptionsProperties)) {
|
|
|
|
::JS_SetOptions(mContext, mDefaultJSOptions);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2000-09-01 03:10:33 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2004-05-11 02:37:25 +00:00
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
// Attempt to initialize JProf functions
|
|
|
|
::JS_DefineFunctions(mContext, globalObj, JProfFunctions);
|
|
|
|
#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
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
PRBool
|
1998-12-30 02:46:36 +00:00
|
|
|
nsJSContext::IsContextInitialized()
|
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
return mIsInitialized;
|
1998-12-30 02:46:36 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
1998-10-26 23:22:21 +00:00
|
|
|
nsJSContext::GC()
|
|
|
|
{
|
2001-11-27 09:46:38 +00:00
|
|
|
FireGCTimer();
|
1998-10-26 23:22:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
2000-09-15 06:17:08 +00:00
|
|
|
nsJSContext::ScriptEvaluated(PRBool aTerminated)
|
1999-03-12 22:24:30 +00:00
|
|
|
{
|
2005-06-09 15:42:19 +00:00
|
|
|
if (aTerminated && mTerminations) {
|
|
|
|
// Make sure to null out mTerminations before doing anything that
|
|
|
|
// might cause new termination funcs to be added!
|
|
|
|
nsJSContext::TerminationFuncClosure* start = mTerminations;
|
|
|
|
mTerminations = nsnull;
|
|
|
|
|
|
|
|
for (nsJSContext::TerminationFuncClosure* cur = start;
|
|
|
|
cur;
|
|
|
|
cur = cur->mNext) {
|
|
|
|
(*(cur->mTerminationFunc))(cur->mTerminationFuncArg);
|
|
|
|
}
|
|
|
|
delete start;
|
1999-10-28 14:12:56 +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
|
|
|
mNumEvaluations++;
|
|
|
|
|
2005-06-08 02:13:10 +00:00
|
|
|
#ifdef WAY_TOO_MUCH_GC
|
|
|
|
::JS_MaybeGC(mContext);
|
|
|
|
#else
|
(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 (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
|
|
|
}
|
2005-06-08 02:13:10 +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
|
|
|
|
2000-06-24 16:18:41 +00:00
|
|
|
mBranchCallbackCount = 0;
|
2004-02-11 22:22:05 +00:00
|
|
|
mBranchCallbackTime = LL_ZERO;
|
1998-11-21 00:12:33 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptContextOwner *
|
|
|
|
nsJSContext::GetOwner()
|
1999-09-08 23:14:30 +00:00
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
return mOwner;
|
1999-09-08 23:14:30 +00:00
|
|
|
}
|
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
nsresult
|
1999-10-28 14:12:56 +00:00
|
|
|
nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc,
|
|
|
|
nsISupports* aRef)
|
|
|
|
{
|
2005-06-09 15:42:19 +00:00
|
|
|
nsJSContext::TerminationFuncClosure* newClosure =
|
|
|
|
new nsJSContext::TerminationFuncClosure(aFunc, aRef, mTerminations);
|
|
|
|
if (!newClosure) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTerminations = newClosure;
|
|
|
|
return NS_OK;
|
1999-10-28 14:12:56 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
PRBool
|
|
|
|
nsJSContext::GetScriptsEnabled()
|
2000-03-28 00:15:56 +00:00
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
return mScriptsEnabled;
|
2000-03-28 00:15:56 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
2002-02-05 05:53:56 +00:00
|
|
|
nsJSContext::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
|
2000-03-28 00:15:56 +00:00
|
|
|
{
|
|
|
|
mScriptsEnabled = aEnabled;
|
2001-11-27 09:18:28 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptGlobalObject *global = GetGlobalObject();
|
2001-11-27 09:18:28 +00:00
|
|
|
|
2002-02-09 02:48:31 +00:00
|
|
|
if (global) {
|
|
|
|
global->SetScriptsEnabled(aEnabled, aFireTimeouts);
|
2001-11-27 09:18:28 +00:00
|
|
|
}
|
2000-03-28 00:15:56 +00:00
|
|
|
}
|
|
|
|
|
2001-05-15 22:26:19 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
PRBool
|
|
|
|
nsJSContext::GetProcessingScriptTag()
|
2001-05-15 22:26:19 +00:00
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
return mProcessingScriptTag;
|
2001-05-15 22:26:19 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
2003-06-24 21:09:57 +00:00
|
|
|
nsJSContext::SetProcessingScriptTag(PRBool aFlag)
|
2001-05-15 22:26:19 +00:00
|
|
|
{
|
|
|
|
mProcessingScriptTag = aFlag;
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
void
|
2001-10-19 04:13:37 +00:00
|
|
|
nsJSContext::SetGCOnDestruction(PRBool aGCOnDestruction)
|
|
|
|
{
|
|
|
|
mGCOnDestruction = aGCOnDestruction;
|
|
|
|
}
|
|
|
|
|
2001-09-24 22:57:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSContext::ScriptExecuted()
|
|
|
|
{
|
2004-02-09 22:48:53 +00:00
|
|
|
ScriptEvaluated(PR_FALSE);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-09-24 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-27 09:46:38 +00:00
|
|
|
nsJSContext::Notify(nsITimer *timer)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mContext, "No context in nsJSContext::Notify()!");
|
|
|
|
|
|
|
|
::JS_GC(mContext);
|
|
|
|
|
|
|
|
sReadyForGC = PR_TRUE;
|
|
|
|
|
|
|
|
NS_RELEASE(sGCTimer);
|
2002-09-07 05:38:16 +00:00
|
|
|
return NS_OK;
|
2001-11-27 09:46:38 +00:00
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
void
|
|
|
|
nsJSContext::FireGCTimer()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2001-11-27 09:46:38 +00:00
|
|
|
if (sGCTimer) {
|
|
|
|
// There's already a timer for GC'ing, just clear newborn roots
|
|
|
|
// and return
|
|
|
|
|
|
|
|
::JS_ClearNewbornRoots(mContext);
|
|
|
|
|
|
|
|
return;
|
(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
|
|
|
}
|
2001-11-27 09:46:38 +00:00
|
|
|
|
2004-11-01 18:50:36 +00:00
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sGCTimer);
|
2001-11-27 09:46:38 +00:00
|
|
|
|
|
|
|
if (!sGCTimer) {
|
|
|
|
NS_WARNING("Failed to create timer");
|
|
|
|
|
|
|
|
::JS_GC(mContext);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool first = PR_TRUE;
|
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
sGCTimer->InitWithCallback(this,
|
2002-09-07 05:38:16 +00:00
|
|
|
first ? NS_FIRST_GC_DELAY : NS_GC_DELAY,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2001-11-27 09:46:38 +00:00
|
|
|
|
|
|
|
first = PR_FALSE;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2001-03-19 21:46:25 +00:00
|
|
|
static JSBool JS_DLL_CALLBACK
|
2000-05-15 04:21:04 +00:00
|
|
|
DOMGCCallback(JSContext *cx, JSGCStatus status)
|
|
|
|
{
|
2005-06-07 22:21:41 +00:00
|
|
|
JSBool result = gOldJSGCCallback ? gOldJSGCCallback(cx, status) : JS_TRUE;
|
|
|
|
|
2000-05-15 04:21:04 +00:00
|
|
|
if (status == JSGC_BEGIN && PR_GetCurrentThread() != gDOMThread)
|
|
|
|
return JS_FALSE;
|
2005-04-26 01:23:53 +00:00
|
|
|
|
|
|
|
// XPCJSRuntime::GCCallback does marking from the JSGC_MARK_END callback.
|
|
|
|
// we need to call EndGCMark *after* marking is finished.
|
|
|
|
// XXX This relies on our callback being registered after
|
|
|
|
// XPCJSRuntime's, although if they were registered the other way
|
|
|
|
// around the ordering there would be correct.
|
2005-03-29 23:26:56 +00:00
|
|
|
if (status == JSGC_MARK_END)
|
|
|
|
nsDOMClassInfo::EndGCMark();
|
2005-04-26 01:23:53 +00:00
|
|
|
|
|
|
|
return result;
|
2000-05-15 04:21:04 +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
|
|
|
|
2004-06-09 18:36:25 +00:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSEnvironment::Startup()
|
|
|
|
{
|
|
|
|
// initialize all our statics, so that we can restart XPCOM
|
|
|
|
sGCTimer = nsnull;
|
|
|
|
sReadyForGC = PR_FALSE;
|
|
|
|
gNameSpaceManager = nsnull;
|
|
|
|
sRuntimeService = nsnull;
|
|
|
|
sRuntime = nsnull;
|
|
|
|
gDOMThread = nsnull;
|
|
|
|
gOldJSGCCallback = nsnull;
|
|
|
|
sIsInitialized = PR_FALSE;
|
|
|
|
sDidShutdown = PR_FALSE;
|
|
|
|
sContextCount = 0;
|
|
|
|
sSecurityManager = nsnull;
|
|
|
|
gCollation = nsnull;
|
|
|
|
}
|
|
|
|
|
2005-05-04 06:28:36 +00:00
|
|
|
JS_STATIC_DLL_CALLBACK(JSPrincipals *)
|
|
|
|
ObjectPrincipalFinder(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsresult rv =
|
|
|
|
sSecurityManager->GetObjectPrincipal(cx, obj,
|
|
|
|
getter_AddRefs(principal));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !principal) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSPrincipals *jsPrincipals = nsnull;
|
|
|
|
principal->GetJSPrincipals(cx, &jsPrincipals);
|
|
|
|
|
|
|
|
// nsIPrincipal::GetJSPrincipals() returns a strong reference to the
|
|
|
|
// JS principals, but the caller of this function expects a weak
|
|
|
|
// reference. So we need to release here.
|
|
|
|
|
|
|
|
JSPRINCIPALS_DROP(cx, jsPrincipals);
|
|
|
|
|
|
|
|
return jsPrincipals;
|
|
|
|
}
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
// static
|
2004-02-09 22:48:53 +00:00
|
|
|
nsresult
|
|
|
|
nsJSEnvironment::Init()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2004-06-09 18:36:25 +00:00
|
|
|
if (sIsInitialized) {
|
2001-11-27 09:46:38 +00:00
|
|
|
return NS_OK;
|
2000-06-20 03:45:21 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 20:21:00 +00:00
|
|
|
nsresult rv = CallGetService(kJSRuntimeServiceContractID, &sRuntimeService);
|
1999-09-05 00:43:39 +00:00
|
|
|
// get the JSRuntime from the runtime svc, if possible
|
2001-11-27 09:46:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = sRuntimeService->GetRuntime(&sRuntime);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 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
|
|
|
|
2000-05-15 04:21:04 +00:00
|
|
|
gDOMThread = PR_GetCurrentThread();
|
2001-05-26 07:44:19 +00:00
|
|
|
|
2001-06-05 01:00:48 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Let's make sure that our main thread is the same as the xpcom main thread.
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> t;
|
|
|
|
PRThread* mainThread;
|
|
|
|
rv = nsIThread::GetMainThread(getter_AddRefs(t));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && t, "bad");
|
|
|
|
rv = t->GetPRThread(&mainThread);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && mainThread == gDOMThread, "bad");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
NS_ASSERTION(!gOldJSGCCallback,
|
|
|
|
"nsJSEnvironment initialized more than once");
|
|
|
|
|
2005-05-04 06:28:36 +00:00
|
|
|
// Save the old GC callback to chain to it, for GC-observing generality.
|
2001-11-27 09:46:38 +00:00
|
|
|
gOldJSGCCallback = ::JS_SetGCCallbackRT(sRuntime, DOMGCCallback);
|
2000-05-15 04:21:04 +00:00
|
|
|
|
2005-05-04 06:28:36 +00:00
|
|
|
// No chaining to a pre-existing callback here, we own this problem space.
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
JSObjectPrincipalsFinder oldfop =
|
|
|
|
#endif
|
|
|
|
::JS_SetObjectPrincipalsFinder(sRuntime, ObjectPrincipalFinder);
|
|
|
|
NS_ASSERTION(!oldfop, " fighting over the findObjectPrincipals callback!");
|
|
|
|
|
2001-06-05 01:00:48 +00:00
|
|
|
// Set these global xpconnect options...
|
2004-09-01 16:50:12 +00:00
|
|
|
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
|
|
|
xpc->SetCollectGarbageOnMainThreadOnly(PR_TRUE);
|
|
|
|
xpc->SetDeferReleasesUntilAfterGarbageCollection(PR_TRUE);
|
2001-06-05 01:00:48 +00:00
|
|
|
|
2003-03-25 06:54:52 +00:00
|
|
|
#ifdef OJI
|
2000-09-13 23:57:52 +00:00
|
|
|
// Initialize LiveConnect. XXXbe use contractid rather than GetCID
|
2001-11-27 20:32:26 +00:00
|
|
|
// NOTE: LiveConnect is optional so initialisation will still succeed
|
|
|
|
// even if the service is not present.
|
2003-06-24 21:09:57 +00:00
|
|
|
nsCOMPtr<nsILiveConnectManager> manager =
|
2001-11-27 20:32:26 +00:00
|
|
|
do_GetService(nsIJVMManager::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
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
// Should the JVM manager perhaps define methods for starting up
|
|
|
|
// LiveConnect?
|
2001-11-27 20:32:26 +00:00
|
|
|
if (manager) {
|
(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
|
|
|
PRBool started = PR_FALSE;
|
2001-11-27 09:46:38 +00:00
|
|
|
rv = manager->StartupLiveConnect(sRuntime, started);
|
2005-04-26 01:23:53 +00:00
|
|
|
// XXX Did somebody mean to check |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
|
|
|
}
|
2003-03-25 06:54:52 +00:00
|
|
|
#endif /* OJI */
|
2000-03-11 06:32:42 +00:00
|
|
|
|
2004-02-11 22:22:05 +00:00
|
|
|
// Initialize limit on script run time to 5 seconds
|
|
|
|
PRInt32 maxtime = 5;
|
2004-04-29 23:34:19 +00:00
|
|
|
PRInt32 time = nsContentUtils::GetIntPref("dom.max_script_run_time");
|
|
|
|
|
|
|
|
// Force the default for unreasonable values
|
|
|
|
if (time > 0)
|
|
|
|
maxtime = time;
|
2004-02-11 22:22:05 +00:00
|
|
|
|
|
|
|
PRTime usec_per_sec;
|
|
|
|
LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
|
|
|
|
LL_I2L(sMaxScriptRunTime, maxtime);
|
|
|
|
LL_MUL(sMaxScriptRunTime, sMaxScriptRunTime, usec_per_sec);
|
|
|
|
|
2003-06-24 21:09:57 +00:00
|
|
|
rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &sSecurityManager);
|
2003-04-17 20:21:00 +00:00
|
|
|
|
2004-06-09 18:36:25 +00:00
|
|
|
sIsInitialized = NS_SUCCEEDED(rv);
|
2001-11-27 09:46:38 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
// static
|
|
|
|
void nsJSEnvironment::ShutDown()
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2001-11-27 09:46:38 +00:00
|
|
|
if (sGCTimer) {
|
|
|
|
// We're being shut down, if we have a GC timer scheduled, cancel
|
|
|
|
// it. The DOM factory will do one final GC once it's shut down.
|
|
|
|
|
|
|
|
sGCTimer->Cancel();
|
|
|
|
|
|
|
|
NS_RELEASE(sGCTimer);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
}
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
delete gNameSpaceManager;
|
|
|
|
gNameSpaceManager = nsnull;
|
|
|
|
|
2002-05-03 03:02:07 +00:00
|
|
|
if (!sContextCount) {
|
|
|
|
// We're being shutdown, and there are no more contexts
|
2003-04-17 20:21:00 +00:00
|
|
|
// alive, release the JS runtime service and the security manager.
|
2002-05-03 03:02:07 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(sRuntimeService);
|
2003-04-17 20:21:00 +00:00
|
|
|
NS_IF_RELEASE(sSecurityManager);
|
2003-06-24 21:09:57 +00:00
|
|
|
NS_IF_RELEASE(gCollation);
|
2004-06-15 16:38:43 +00:00
|
|
|
NS_IF_RELEASE(gDecoder);
|
2001-11-27 09:46:38 +00:00
|
|
|
}
|
2002-05-03 03:02:07 +00:00
|
|
|
|
|
|
|
sDidShutdown = PR_TRUE;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
nsJSEnvironment::CreateNewContext(nsIScriptContext **aContext)
|
2000-06-20 03:45:21 +00:00
|
|
|
{
|
2001-11-27 09:46:38 +00:00
|
|
|
*aContext = new nsJSContext(sRuntime);
|
|
|
|
NS_ENSURE_TRUE(*aContext, NS_ERROR_OUT_OF_MEMORY);
|
2000-06-20 03:45:21 +00:00
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
NS_ADDREF(*aContext);
|
|
|
|
return NS_OK;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsresult
|
|
|
|
NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
|
|
|
|
nsIScriptContext **aContext)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
2001-11-27 09:46:38 +00:00
|
|
|
nsresult rv = nsJSEnvironment::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 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
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext;
|
|
|
|
rv = nsJSEnvironment::CreateNewContext(getter_AddRefs(scriptContext));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 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
|
|
|
|
|
|
|
// Bind the script context and the global object
|
2001-11-27 09:46:38 +00:00
|
|
|
rv = scriptContext->InitContext(aGlobal);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, 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
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (aGlobal) {
|
2004-02-09 22:48:53 +00:00
|
|
|
aGlobal->SetContext(scriptContext);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
}
|
|
|
|
|
2001-11-27 09:46:38 +00:00
|
|
|
*aContext = scriptContext;
|
|
|
|
|
|
|
|
NS_ADDREF(*aContext);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|