1998-07-16 01:16:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-07-16 01:16:47 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-07-16 01:16:47 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-07-16 01:16:47 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-07-16 01:16:47 +00:00
|
|
|
*/
|
|
|
|
#ifndef nsJSEnvironment_h___
|
|
|
|
#define nsJSEnvironment_h___
|
|
|
|
|
|
|
|
#include "nsIScriptContext.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 00:43:30 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-12-15 06:10:59 +00:00
|
|
|
#include "jsapi.h"
|
1999-10-28 14:12:56 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-06-20 03:45:21 +00:00
|
|
|
#include "nsIObserver.h"
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1998-11-21 00:12:33 +00:00
|
|
|
class nsIScriptSecurityManager;
|
1999-10-31 03:04:02 +00:00
|
|
|
// XXXbe vc5 sucks: must include nsIScriptNameSpaceManager.h to use nsCOMPtr with it
|
|
|
|
#if 0
|
1998-12-22 22:03:20 +00:00
|
|
|
class nsIScriptNameSpaceManager;
|
1999-10-31 03:04:02 +00:00
|
|
|
#else
|
|
|
|
#include "nsIScriptNameSpaceManager.h"
|
|
|
|
#endif
|
1999-09-15 20:58:41 +00:00
|
|
|
class nsIPrincipal;
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
class nsJSContext : public nsIScriptContext {
|
|
|
|
private:
|
|
|
|
JSContext *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
|
|
|
nsCOMPtr<nsIScriptNameSpaceManager> mNameSpaceManager;
|
1998-12-30 02:46:36 +00:00
|
|
|
PRBool mIsInitialized;
|
1999-03-12 22:24:30 +00:00
|
|
|
PRUint32 mNumEvaluations;
|
(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
|
|
|
nsIScriptSecurityManager* mSecurityManager; /* XXXbe nsCOMPtr to service */
|
|
|
|
nsIScriptContextOwner* mOwner; /* NB: weak reference, not ADDREF'd */
|
1999-10-28 14:12:56 +00:00
|
|
|
nsScriptTerminationFunc mTerminationFunc;
|
|
|
|
nsCOMPtr<nsISupports> mRef;
|
2000-03-28 00:15:56 +00:00
|
|
|
PRBool mScriptsEnabled;
|
2000-06-24 16:18:41 +00:00
|
|
|
PRUint32 mBranchCallbackCount;
|
2000-08-26 23:32:52 +00:00
|
|
|
void *mRootedScriptObject; // special case for the window script object
|
2000-09-02 01:58:51 +00:00
|
|
|
PRUint32 mDefaultJSOptions;
|
|
|
|
|
|
|
|
static int PR_CALLBACK JSOptionChangedCallback(const char *pref, void *data);
|
2000-06-24 16:18:41 +00:00
|
|
|
|
2001-03-19 21:46:25 +00:00
|
|
|
static JSBool JS_DLL_CALLBACK DOMBranchCallback(JSContext *cx, JSScript *script);
|
1999-10-28 14:12:56 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
public:
|
|
|
|
nsJSContext(JSRuntime *aRuntime);
|
1999-03-20 01:54:12 +00:00
|
|
|
virtual ~nsJSContext();
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_IMETHOD EvaluateString(const nsAReadableString& aScript,
|
1999-12-07 22:14:17 +00:00
|
|
|
void *aScopeObject,
|
1999-09-15 20:58:41 +00:00
|
|
|
nsIPrincipal *principal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
const char* aVersion,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsAWritableString& aRetValue,
|
1999-09-15 20:58:41 +00:00
|
|
|
PRBool* aIsUndefined);
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_IMETHOD EvaluateStringWithValue(const nsAReadableString& aScript,
|
2000-03-29 01:18:21 +00:00
|
|
|
void *aScopeObject,
|
|
|
|
nsIPrincipal *aPrincipal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
const char* aVersion,
|
|
|
|
void* aRetValue,
|
|
|
|
PRBool* aIsUndefined);
|
|
|
|
|
1999-11-12 06:08:14 +00:00
|
|
|
NS_IMETHOD CompileScript(const PRUnichar* aText,
|
|
|
|
PRInt32 aTextLength,
|
1999-12-07 22:14:17 +00:00
|
|
|
void *aScopeObject,
|
1999-11-12 06:08:14 +00:00
|
|
|
nsIPrincipal *principal,
|
|
|
|
const char *aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
const char* aVersion,
|
|
|
|
void** aScriptObject);
|
|
|
|
NS_IMETHOD ExecuteScript(void* aScriptObject,
|
|
|
|
void *aScopeObject,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsAWritableString* aRetValue,
|
1999-11-12 06:08:14 +00:00
|
|
|
PRBool* aIsUndefined);
|
1999-12-07 22:14:17 +00:00
|
|
|
NS_IMETHOD CompileEventHandler(void *aTarget,
|
1999-12-03 03:40:30 +00:00
|
|
|
nsIAtom *aName,
|
2000-08-23 17:27:06 +00:00
|
|
|
const nsAReadableString& aBody,
|
2000-01-08 00:24:24 +00:00
|
|
|
PRBool aShared,
|
1999-12-07 22:14:17 +00:00
|
|
|
void** aHandler);
|
|
|
|
NS_IMETHOD CallEventHandler(void *aTarget, void *aHandler,
|
|
|
|
PRUint32 argc, void *argv,
|
2000-04-24 04:41:27 +00:00
|
|
|
PRBool *aBoolResult, PRBool aReverseReturnResult);
|
1999-12-07 22:14:17 +00:00
|
|
|
NS_IMETHOD BindCompiledEventHandler(void *aTarget,
|
2000-01-08 00:24:24 +00:00
|
|
|
nsIAtom *aName,
|
|
|
|
void *aHandler);
|
2000-03-29 01:18:21 +00:00
|
|
|
NS_IMETHOD CompileFunction(void* aTarget,
|
|
|
|
const nsCString& aName,
|
|
|
|
PRUint32 aArgCount,
|
|
|
|
const char** aArgArray,
|
2000-08-23 17:27:06 +00:00
|
|
|
const nsAReadableString& aBody,
|
2000-03-29 01:18:21 +00:00
|
|
|
const char* aURL,
|
|
|
|
PRUint32 aLineNo,
|
|
|
|
PRBool aShared,
|
|
|
|
void** aFunctionObject);
|
|
|
|
|
1999-12-07 22:14:17 +00:00
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHOD SetDefaultLanguageVersion(const char* aVersion);
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHOD_(nsIScriptGlobalObject*) GetGlobalObject();
|
|
|
|
NS_IMETHOD_(void*) GetNativeContext();
|
|
|
|
NS_IMETHOD InitClasses();
|
|
|
|
NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject);
|
1998-12-30 02:46:36 +00:00
|
|
|
NS_IMETHOD IsContextInitialized();
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHOD AddNamedReference(void *aSlot, void *aScriptObject,
|
2000-01-08 00:24:24 +00:00
|
|
|
const char *aName);
|
1998-12-21 16:51:10 +00:00
|
|
|
NS_IMETHOD RemoveReference(void *aSlot, void *aScriptObject);
|
|
|
|
NS_IMETHOD GC();
|
|
|
|
NS_IMETHOD GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr);
|
1998-11-21 00:12:33 +00:00
|
|
|
NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr);
|
1998-12-30 21:35:35 +00:00
|
|
|
|
2000-09-15 06:17:08 +00:00
|
|
|
NS_IMETHOD ScriptEvaluated(PRBool aTerminated);
|
1999-09-08 23:14:30 +00:00
|
|
|
NS_IMETHOD SetOwner(nsIScriptContextOwner* owner);
|
|
|
|
NS_IMETHOD GetOwner(nsIScriptContextOwner** owner);
|
1999-10-28 14:12:56 +00:00
|
|
|
NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc,
|
|
|
|
nsISupports* aRef);
|
2000-08-26 23:32:52 +00:00
|
|
|
NS_IMETHOD SetRootedScriptObject(void *aObject);
|
2000-03-28 00:15:56 +00:00
|
|
|
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled);
|
|
|
|
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled);
|
1999-03-12 22:24:30 +00:00
|
|
|
|
1998-12-30 21:35:35 +00:00
|
|
|
nsresult InitializeExternalClasses();
|
1999-03-08 00:14:40 +00:00
|
|
|
nsresult InitializeLiveConnectClasses();
|
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
|
|
|
class nsIJSRuntimeService;
|
|
|
|
|
2000-09-13 13:50:30 +00:00
|
|
|
class nsJSEnvironment: public nsIObserver {
|
1998-07-16 01:16:47 +00:00
|
|
|
private:
|
|
|
|
JSRuntime *mRuntime;
|
(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
|
|
|
nsIJSRuntimeService* mRuntimeService; /* XXXbe nsCOMPtr to service */
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
public:
|
1998-09-01 19:13:36 +00:00
|
|
|
static nsJSEnvironment *sTheEnvironment;
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsJSEnvironment();
|
2000-06-20 03:45:21 +00:00
|
|
|
virtual ~nsJSEnvironment();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
nsIScriptContext* GetNewContext();
|
|
|
|
|
|
|
|
static nsJSEnvironment *GetScriptingEnvironment();
|
1998-08-12 04:56:40 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
};
|
|
|
|
|
1999-01-06 18:53:59 +00:00
|
|
|
/* prototypes */
|
2001-03-19 21:46:25 +00:00
|
|
|
void JS_DLL_CALLBACK NS_ScriptErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);
|
1999-01-06 18:53:59 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
#endif /* nsJSEnvironment_h___ */
|