2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-07-16 05:16:47 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04: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/
|
1998-07-16 05:16:47 +04:00
|
|
|
*
|
2001-09-26 02:43:09 +04: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.
|
1998-07-16 05:16:47 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 02:43:09 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-26 02:43:09 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04: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-26 02:43:09 +04: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-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 02:43:09 +04: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-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 02:43:09 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-07-16 05:16:47 +04:00
|
|
|
#ifndef nsJSEnvironment_h___
|
|
|
|
#define nsJSEnvironment_h___
|
|
|
|
|
|
|
|
#include "nsIScriptContext.h"
|
2006-06-13 07:07:47 +04:00
|
|
|
#include "nsIScriptRuntime.h"
|
(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 03:43:30 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-12-15 09:10:59 +03:00
|
|
|
#include "jsapi.h"
|
2000-06-20 07:45:21 +04:00
|
|
|
#include "nsIObserver.h"
|
2001-09-25 02:57:47 +04:00
|
|
|
#include "nsIXPCScriptNotify.h"
|
2004-02-12 01:22:05 +03:00
|
|
|
#include "prtime.h"
|
2007-03-08 14:17:16 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2007-11-13 13:35:49 +03:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
2007-01-11 03:02:58 +03:00
|
|
|
|
2005-07-29 19:11:08 +04:00
|
|
|
class nsIXPConnectJSObjectHolder;
|
2010-01-25 19:48:07 +03:00
|
|
|
class nsAutoPoolRelease;
|
2010-03-30 09:51:52 +04:00
|
|
|
namespace js {
|
|
|
|
class AutoArrayRooter;
|
2011-04-29 02:48:52 +04:00
|
|
|
}
|
|
|
|
namespace mozilla {
|
2011-04-29 02:48:51 +04:00
|
|
|
template <class> class Maybe;
|
2010-03-30 09:51:52 +04:00
|
|
|
}
|
1998-07-16 05:16:47 +04:00
|
|
|
|
2001-11-27 12:46:38 +03:00
|
|
|
class nsJSContext : public nsIScriptContext,
|
2009-02-12 15:06:59 +03:00
|
|
|
public nsIXPCScriptNotify
|
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 21:42:36 +04:00
|
|
|
{
|
1998-07-16 05:16:47 +04:00
|
|
|
public:
|
|
|
|
nsJSContext(JSRuntime *aRuntime);
|
1999-03-20 04:54:12 +03:00
|
|
|
virtual ~nsJSContext();
|
1998-07-16 05:16:47 +04:00
|
|
|
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2009-05-07 22:19:36 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsJSContext,
|
|
|
|
nsIScriptContext)
|
1998-07-16 05:16:47 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
virtual nsIScriptObjectPrincipal* GetObjectPrincipal();
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual PRUint32 GetScriptTypeID()
|
|
|
|
{ return nsIProgrammingLanguage::JAVASCRIPT; }
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual nsresult EvaluateString(const nsAString& aScript,
|
1999-12-08 01:14:17 +03:00
|
|
|
void *aScopeObject,
|
1999-09-16 00:58:41 +04:00
|
|
|
nsIPrincipal *principal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
2006-06-13 07:07:47 +04:00
|
|
|
PRUint32 aVersion,
|
2004-06-11 04:48:00 +04:00
|
|
|
nsAString *aRetValue,
|
1999-09-16 00:58:41 +04:00
|
|
|
PRBool* aIsUndefined);
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
|
2000-03-29 05:18:21 +04:00
|
|
|
void *aScopeObject,
|
|
|
|
nsIPrincipal *aPrincipal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
2006-06-13 07:07:47 +04:00
|
|
|
PRUint32 aVersion,
|
2000-03-29 05:18:21 +04:00
|
|
|
void* aRetValue,
|
|
|
|
PRBool* aIsUndefined);
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual nsresult CompileScript(const PRUnichar* aText,
|
1999-11-12 09:08:14 +03:00
|
|
|
PRInt32 aTextLength,
|
1999-12-08 01:14:17 +03:00
|
|
|
void *aScopeObject,
|
1999-11-12 09:08:14 +03:00
|
|
|
nsIPrincipal *principal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
2006-06-13 07:07:47 +04:00
|
|
|
PRUint32 aVersion,
|
|
|
|
nsScriptObjectHolder &aScriptObject);
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual nsresult ExecuteScript(void* aScriptObject,
|
1999-11-12 09:08:14 +03:00
|
|
|
void *aScopeObject,
|
2002-03-24 03:16:18 +03:00
|
|
|
nsAString* aRetValue,
|
1999-11-12 09:08:14 +03:00
|
|
|
PRBool* aIsUndefined);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
virtual nsresult CompileEventHandler(nsIAtom *aName,
|
|
|
|
PRUint32 aArgCount,
|
|
|
|
const char** aArgNames,
|
2002-03-24 03:16:18 +03:00
|
|
|
const nsAString& aBody,
|
2006-06-13 07:07:47 +04:00
|
|
|
const char *aURL, PRUint32 aLineNo,
|
2008-02-16 08:13:16 +03:00
|
|
|
PRUint32 aVersion,
|
2006-06-13 07:07:47 +04:00
|
|
|
nsScriptObjectHolder &aHandler);
|
|
|
|
virtual nsresult CallEventHandler(nsISupports* aTarget, void *aScope,
|
|
|
|
void* aHandler,
|
|
|
|
nsIArray *argv, nsIVariant **rv);
|
|
|
|
virtual nsresult BindCompiledEventHandler(nsISupports *aTarget,
|
|
|
|
void *aScope,
|
2000-01-08 03:24:24 +03:00
|
|
|
nsIAtom *aName,
|
|
|
|
void *aHandler);
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual nsresult GetBoundEventHandler(nsISupports* aTarget, void *aScope,
|
|
|
|
nsIAtom* aName,
|
|
|
|
nsScriptObjectHolder &aHandler);
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual nsresult CompileFunction(void* aTarget,
|
2003-06-24 05:20:40 +04:00
|
|
|
const nsACString& aName,
|
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 21:42:36 +04:00
|
|
|
PRUint32 aArgCount,
|
|
|
|
const char** aArgArray,
|
2002-03-24 03:16:18 +03:00
|
|
|
const nsAString& aBody,
|
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 21:42:36 +04:00
|
|
|
const char* aURL,
|
|
|
|
PRUint32 aLineNo,
|
2008-02-16 08:13:16 +03:00
|
|
|
PRUint32 aVersion,
|
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 21:42:36 +04:00
|
|
|
PRBool aShared,
|
|
|
|
void** aFunctionObject);
|
1999-12-08 01:14:17 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual void SetDefaultLanguageVersion(PRUint32 aVersion);
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual nsIScriptGlobalObject *GetGlobalObject();
|
|
|
|
virtual void *GetNativeContext();
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual void *GetNativeGlobal();
|
|
|
|
virtual nsresult CreateNativeGlobalForInner(
|
|
|
|
nsIScriptGlobalObject *aGlobal,
|
|
|
|
PRBool aIsChrome,
|
2010-07-20 00:36:49 +04:00
|
|
|
nsIPrincipal *aPrincipal,
|
2006-06-13 07:07:47 +04:00
|
|
|
void **aNativeGlobal,
|
|
|
|
nsISupports **aHolder);
|
|
|
|
virtual nsresult ConnectToInner(nsIScriptGlobalObject *aNewInner,
|
|
|
|
void *aOuterGlobal);
|
2010-07-16 02:16:29 +04:00
|
|
|
virtual nsresult InitContext();
|
2010-07-20 00:36:49 +04:00
|
|
|
virtual nsresult CreateOuterObject(nsIScriptGlobalObject *aGlobalObject,
|
2010-08-11 02:00:26 +04:00
|
|
|
nsIScriptGlobalObject *aCurrentInner);
|
2010-09-18 01:54:40 +04:00
|
|
|
virtual nsresult SetOuterObject(void *aOuterObject);
|
2010-07-16 02:16:29 +04:00
|
|
|
virtual nsresult InitOuterWindow();
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual PRBool IsContextInitialized();
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual void FinalizeContext();
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual void ScriptEvaluated(PRBool aTerminated);
|
2005-06-09 19:42:19 +04:00
|
|
|
virtual nsresult SetTerminationFunction(nsScriptTerminationFunc aFunc,
|
|
|
|
nsISupports* aRef);
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual PRBool GetScriptsEnabled();
|
|
|
|
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual nsresult SetProperty(void *aTarget, const char *aPropName, nsISupports *aVal);
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual PRBool GetProcessingScriptTag();
|
|
|
|
virtual void SetProcessingScriptTag(PRBool aResult);
|
|
|
|
|
2009-11-20 02:11:44 +03:00
|
|
|
virtual PRBool GetExecutingScript();
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
virtual void SetGCOnDestruction(PRBool aGCOnDestruction);
|
2001-10-19 08:13:37 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual nsresult InitClasses(void *aGlobalObj);
|
|
|
|
virtual void ClearScope(void* aGlobalObj, PRBool bClearPolluters);
|
2005-07-31 00:57:07 +04:00
|
|
|
|
|
|
|
virtual void WillInitializeContext();
|
|
|
|
virtual void DidInitializeContext();
|
2006-07-19 08:15:50 +04:00
|
|
|
virtual void DidSetDocument(nsISupports *aDocdoc, void *aGlobal) {;}
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
virtual nsresult Serialize(nsIObjectOutputStream* aStream, void *aScriptObject);
|
|
|
|
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
|
|
|
|
nsScriptObjectHolder &aResult);
|
|
|
|
|
|
|
|
virtual nsresult DropScriptObject(void *object);
|
|
|
|
virtual nsresult HoldScriptObject(void *object);
|
2005-07-31 00:57:07 +04:00
|
|
|
|
2009-06-12 04:52:47 +04:00
|
|
|
virtual void EnterModalState();
|
|
|
|
virtual void LeaveModalState();
|
|
|
|
|
2001-09-25 02:57:47 +04:00
|
|
|
NS_DECL_NSIXPCSCRIPTNOTIFY
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2007-01-11 03:02:58 +03:00
|
|
|
static void LoadStart();
|
2007-10-21 20:46:54 +04:00
|
|
|
static void LoadEnd();
|
2007-01-11 03:02:58 +03:00
|
|
|
|
2011-02-17 02:47:12 +03:00
|
|
|
static void GarbageCollectNow();
|
|
|
|
static void CycleCollectNow(nsICycleCollectorListener *aListener = nsnull);
|
|
|
|
|
|
|
|
static void PokeGC();
|
|
|
|
static void KillGCTimer();
|
|
|
|
|
|
|
|
static void PokeCC();
|
|
|
|
static void MaybePokeCC();
|
|
|
|
static void KillCCTimer();
|
|
|
|
|
|
|
|
virtual void GC();
|
2009-02-12 15:06:59 +03: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 21:42:36 +04:00
|
|
|
protected:
|
1998-12-31 00:35:35 +03:00
|
|
|
nsresult 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 21:42:36 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// Helper to convert xpcom datatypes to jsvals.
|
2010-01-25 19:48:07 +03:00
|
|
|
nsresult ConvertSupportsTojsvals(nsISupports *aArgs,
|
|
|
|
void *aScope,
|
|
|
|
PRUint32 *aArgc,
|
|
|
|
jsval **aArgv,
|
2011-04-29 02:48:52 +04:00
|
|
|
mozilla::Maybe<nsAutoPoolRelease> &aPoolRelease,
|
|
|
|
mozilla::Maybe<js::AutoArrayRooter> &aRooter);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
nsresult AddSupportsPrimitiveTojsvals(nsISupports *aArg, jsval *aArgv);
|
|
|
|
|
|
|
|
// given an nsISupports object (presumably an event target or some other
|
|
|
|
// DOM object), get (or create) the JSObject wrapping it.
|
2008-11-27 01:54:40 +03:00
|
|
|
nsresult JSObjectFromInterface(nsISupports *aSup, void *aScript,
|
2006-06-13 07:07:47 +04:00
|
|
|
JSObject **aRet);
|
|
|
|
|
2009-05-20 06:11:01 +04:00
|
|
|
// Report the pending exception on our mContext, if any. This
|
|
|
|
// function will set aside the frame chain on mContext before
|
|
|
|
// reporting.
|
|
|
|
void ReportPendingException();
|
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 21:42:36 +04:00
|
|
|
private:
|
2009-05-07 22:19:36 +04:00
|
|
|
void DestroyJSContext();
|
|
|
|
|
|
|
|
nsrefcnt GetCCRefcnt();
|
2007-11-02 01:51:57 +03: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 21:42:36 +04:00
|
|
|
JSContext *mContext;
|
2011-01-25 01:56:40 +03:00
|
|
|
PRUint32 mNumEvaluations;
|
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 21:42:36 +04:00
|
|
|
|
2005-06-09 19:42:19 +04:00
|
|
|
protected:
|
2005-06-09 20:29:26 +04:00
|
|
|
struct TerminationFuncHolder;
|
|
|
|
friend struct TerminationFuncHolder;
|
2008-11-27 01:54:40 +03:00
|
|
|
|
2005-07-31 00:57:07 +04:00
|
|
|
struct TerminationFuncClosure
|
|
|
|
{
|
2005-06-09 19:42:19 +04:00
|
|
|
TerminationFuncClosure(nsScriptTerminationFunc aFunc,
|
|
|
|
nsISupports* aArg,
|
|
|
|
TerminationFuncClosure* aNext) :
|
|
|
|
mTerminationFunc(aFunc),
|
|
|
|
mTerminationFuncArg(aArg),
|
|
|
|
mNext(aNext)
|
2005-07-31 00:57:07 +04:00
|
|
|
{
|
|
|
|
}
|
2005-06-09 19:42:19 +04:00
|
|
|
~TerminationFuncClosure()
|
|
|
|
{
|
|
|
|
delete mNext;
|
|
|
|
}
|
2008-11-27 01:54:40 +03:00
|
|
|
|
2005-06-09 19:42:19 +04:00
|
|
|
nsScriptTerminationFunc mTerminationFunc;
|
|
|
|
nsCOMPtr<nsISupports> mTerminationFuncArg;
|
|
|
|
TerminationFuncClosure* mNext;
|
|
|
|
};
|
|
|
|
|
2005-07-31 00:57:07 +04:00
|
|
|
struct TerminationFuncHolder
|
|
|
|
{
|
|
|
|
TerminationFuncHolder(nsJSContext* aContext)
|
|
|
|
: mContext(aContext),
|
|
|
|
mTerminations(aContext->mTerminations)
|
2005-06-09 19:42:19 +04:00
|
|
|
{
|
|
|
|
aContext->mTerminations = nsnull;
|
|
|
|
}
|
2005-07-31 00:57:07 +04:00
|
|
|
~TerminationFuncHolder()
|
|
|
|
{
|
2005-06-09 19:42:19 +04:00
|
|
|
// Have to be careful here. mContext might have picked up new
|
|
|
|
// termination funcs while the script was evaluating. Prepend whatever
|
|
|
|
// we have to the current termination funcs on the context (since our
|
|
|
|
// termination funcs were posted first).
|
|
|
|
if (mTerminations) {
|
|
|
|
TerminationFuncClosure* cur = mTerminations;
|
|
|
|
while (cur->mNext) {
|
|
|
|
cur = cur->mNext;
|
|
|
|
}
|
|
|
|
cur->mNext = mContext->mTerminations;
|
|
|
|
mContext->mTerminations = mTerminations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSContext* mContext;
|
|
|
|
TerminationFuncClosure* mTerminations;
|
|
|
|
};
|
2008-11-27 01:54:40 +03:00
|
|
|
|
2005-06-09 19:42:19 +04:00
|
|
|
TerminationFuncClosure* mTerminations;
|
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 21:42:36 +04:00
|
|
|
|
2005-06-09 19:42:19 +04:00
|
|
|
private:
|
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 21:42:36 +04:00
|
|
|
PRPackedBool mIsInitialized;
|
|
|
|
PRPackedBool mScriptsEnabled;
|
2001-10-19 08:13:37 +04:00
|
|
|
PRPackedBool mGCOnDestruction;
|
2001-10-31 11:39:09 +03:00
|
|
|
PRPackedBool mProcessingScriptTag;
|
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 21:42:36 +04:00
|
|
|
|
2009-11-20 02:11:44 +03:00
|
|
|
PRUint32 mExecuteDepth;
|
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 21:42:36 +04:00
|
|
|
PRUint32 mDefaultJSOptions;
|
2008-01-19 00:28:42 +03:00
|
|
|
PRTime mOperationCallbackTime;
|
2001-10-31 11:39:09 +03:00
|
|
|
|
2009-06-12 04:52:47 +04:00
|
|
|
PRTime mModalStateTime;
|
|
|
|
PRUint32 mModalStateDepth;
|
|
|
|
|
2010-09-04 01:15:50 +04:00
|
|
|
// mGlobalObjectRef ensures that the outer window stays alive as long as the
|
|
|
|
// context does. It is eventually collected by the cycle collector.
|
2011-04-29 00:28:54 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> mGlobalObjectRef;
|
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 21:42:36 +04:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static int JSOptionChangedCallback(const char *pref, void *data);
|
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 21:42:36 +04:00
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
static JSBool DOMOperationCallback(JSContext *cx);
|
1998-07-16 05:16:47 +04: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 03:43:30 +03:00
|
|
|
class nsIJSRuntimeService;
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
class nsJSRuntime : public nsIScriptRuntime
|
2001-11-27 12:46:38 +03:00
|
|
|
{
|
2006-06-13 07:07:47 +04:00
|
|
|
public:
|
|
|
|
// let people who can see us use our runtime for convenience.
|
2001-11-27 12:46:38 +03:00
|
|
|
static JSRuntime *sRuntime;
|
1998-07-16 05:16:47 +04:00
|
|
|
|
|
|
|
public:
|
2006-06-13 07:07:47 +04:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
virtual PRUint32 GetScriptTypeID() {
|
|
|
|
return nsIProgrammingLanguage::JAVASCRIPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult CreateContext(nsIScriptContext **ret);
|
|
|
|
|
|
|
|
virtual nsresult ParseVersion(const nsString &aVersionStr, PRUint32 *flags);
|
2004-06-09 22:36:25 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
virtual nsresult DropScriptObject(void *object);
|
|
|
|
virtual nsresult HoldScriptObject(void *object);
|
2008-11-27 01:54:40 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
static void Startup();
|
2008-09-11 17:20:56 +04:00
|
|
|
static void Shutdown();
|
2006-06-13 07:07:47 +04:00
|
|
|
// Setup all the statics etc - safe to call multiple times after Startup()
|
2001-11-27 12:46:38 +03:00
|
|
|
static nsresult Init();
|
2007-11-13 13:35:49 +03:00
|
|
|
// Get the NameSpaceManager, creating if necessary
|
|
|
|
static nsScriptNameSpaceManager* GetNameSpaceManager();
|
2006-06-13 07:07:47 +04:00
|
|
|
};
|
1998-07-16 05:16:47 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// An interface for fast and native conversion to/from nsIArray. If an object
|
|
|
|
// supports this interface, JS can reach directly in for the argv, and avoid
|
|
|
|
// nsISupports conversion. If this interface is not supported, the object will
|
|
|
|
// be queried for nsIArray, and everything converted via xpcom objects.
|
|
|
|
#define NS_IJSARGARRAY_IID \
|
|
|
|
{ /*{E96FB2AE-CB4F-44a0-81F8-D91C80AFE9A3} */ \
|
|
|
|
0xe96fb2ae, 0xcb4f, 0x44a0, \
|
|
|
|
{ 0x81, 0xf8, 0xd9, 0x1c, 0x80, 0xaf, 0xe9, 0xa3 } }
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
class nsIJSArgArray: public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IJSARGARRAY_IID)
|
|
|
|
// Bug 312003 describes why this must be "void **", but after calling argv
|
|
|
|
// may be cast to jsval* and the args found at:
|
|
|
|
// ((jsval*)argv)[0], ..., ((jsval*)argv)[argc - 1]
|
|
|
|
virtual nsresult GetArgs(PRUint32 *argc, void **argv) = 0;
|
1998-07-16 05:16:47 +04:00
|
|
|
};
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIJSArgArray, NS_IJSARGARRAY_IID)
|
|
|
|
|
|
|
|
/* factory functions */
|
|
|
|
nsresult NS_CreateJSRuntime(nsIScriptRuntime **aRuntime);
|
2004-02-24 06:22:35 +03:00
|
|
|
|
1999-01-06 21:53:59 +03:00
|
|
|
/* prototypes */
|
2008-09-07 02:21:43 +04:00
|
|
|
void NS_ScriptErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);
|
1999-01-06 21:53:59 +03:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
JSObject* NS_DOMReadStructuredClone(JSContext* cx,
|
|
|
|
JSStructuredCloneReader* reader, uint32 tag,
|
|
|
|
uint32 data, void* closure);
|
|
|
|
|
|
|
|
JSBool NS_DOMWriteStructuredClone(JSContext* cx,
|
|
|
|
JSStructuredCloneWriter* writer,
|
|
|
|
JSObject* obj, void *closure);
|
|
|
|
|
|
|
|
void NS_DOMStructuredCloneError(JSContext* cx, uint32 errorid);
|
|
|
|
|
1998-07-16 05:16:47 +04:00
|
|
|
#endif /* nsJSEnvironment_h___ */
|