mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
added memory cleanup tripwire.
This commit is contained in:
parent
2f81998407
commit
aa887814b4
@ -140,6 +140,15 @@ public:
|
||||
* @return NS_OK if the method is successful
|
||||
*/
|
||||
NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr) = 0;
|
||||
|
||||
/**
|
||||
* Inform the context that a script was evaluated.
|
||||
* A GC may be done if "necessary."
|
||||
* This call is necessary if script evaluation is done
|
||||
* without using the EvaluateScript method.
|
||||
* @return NS_OK if the method is successful
|
||||
*/
|
||||
NS_IMETHOD ScriptEvaluated(void) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1100,6 +1100,15 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
|
||||
|
||||
if (timeout->expr) {
|
||||
/* Evaluate the timeout expression. */
|
||||
#if 0
|
||||
// V says it would be nice if we could have a chokepoint
|
||||
// for calling scripts instead of making a bunch of
|
||||
// ScriptEvaluated() calls to clean things up. MMP
|
||||
PRBool isundefined;
|
||||
mContext->EvaluateString(nsAutoString(timeout->expr),
|
||||
timeout->filename,
|
||||
timeout->lineno, nsAutoString(""), &isundefined);
|
||||
#endif
|
||||
JS_EvaluateScript(cx, (JSObject *)mScriptObject,
|
||||
timeout->expr,
|
||||
PL_strlen(timeout->expr),
|
||||
@ -1121,6 +1130,8 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
|
||||
timeout->argc + 1, timeout->argv, &result);
|
||||
}
|
||||
|
||||
mContext->ScriptEvaluated();
|
||||
|
||||
mRunningTimeout = nsnull;
|
||||
|
||||
/* If we have a regular interval timer, we re-fire the
|
||||
|
@ -67,6 +67,7 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime)
|
||||
JS_SetContextPrivate(mContext, (void *)this);
|
||||
mNameSpaceManager = nsnull;
|
||||
mIsInitialized = PR_FALSE;
|
||||
mNumEvaluations = 0;
|
||||
}
|
||||
|
||||
nsJSContext::~nsJSContext()
|
||||
@ -104,6 +105,8 @@ nsJSContext::EvaluateString(const nsString& aScript,
|
||||
aRetValue.Truncate();
|
||||
}
|
||||
|
||||
ScriptEvaluated();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -268,6 +271,19 @@ nsJSContext::GC()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSContext::ScriptEvaluated(void)
|
||||
{
|
||||
mNumEvaluations++;
|
||||
|
||||
if (mNumEvaluations > 20) {
|
||||
mNumEvaluations = 0;
|
||||
GC();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSContext::GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr)
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ private:
|
||||
JSContext *mContext;
|
||||
nsIScriptNameSpaceManager* mNameSpaceManager;
|
||||
PRBool mIsInitialized;
|
||||
PRUint32 mNumEvaluations;
|
||||
|
||||
public:
|
||||
nsJSContext(JSRuntime *aRuntime);
|
||||
@ -53,6 +54,8 @@ public:
|
||||
NS_IMETHOD GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr);
|
||||
NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr);
|
||||
|
||||
NS_IMETHOD ScriptEvaluated(void);
|
||||
|
||||
nsresult InitializeExternalClasses();
|
||||
nsresult InitializeLiveConnectClasses();
|
||||
};
|
||||
|
@ -95,11 +95,13 @@ nsresult nsJSEventListener::ProcessEvent(nsIDOMEvent* aEvent)
|
||||
|
||||
argv[0] = OBJECT_TO_JSVAL(mEventObj);
|
||||
if (PR_TRUE == JS_CallFunctionValue(mContext, mJSObj, funval, 1, argv, &result)) {
|
||||
mScriptCX->ScriptEvaluated();
|
||||
if (JSVAL_IS_BOOLEAN(result) && JSVAL_TO_BOOLEAN(result) == JS_FALSE) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
mScriptCX->ScriptEvaluated();
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user