Bug 841312 - Remove the termination function API. r=bz

\o/
This commit is contained in:
Bobby Holley 2013-05-21 11:45:56 -06:00
parent 83b50e7905
commit 0bda6fb49c
5 changed files with 6 additions and 130 deletions

View File

@ -27,11 +27,9 @@ class nsIScriptObjectPrincipal;
class nsIDOMWindow;
class nsIURI;
typedef void (*nsScriptTerminationFunc)(nsISupports* aRef);
#define NS_ISCRIPTCONTEXT_IID \
{ 0x821c5be9, 0xbf9e, 0x4041, \
{ 0x9f, 0xf2, 0x1f, 0xca, 0x39, 0xf7, 0x89, 0xf3 } }
{ 0xef0c91ce, 0x14f6, 0x41c9, \
{ 0xa5, 0x77, 0xa6, 0xeb, 0xdc, 0x6d, 0x44, 0x7b } }
/* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
know what language we have is a little silly... */
@ -179,11 +177,10 @@ public:
* A GC may be done if "necessary."
* This call is necessary if script evaluation is done
* without using the EvaluateScript method.
* @param aTerminated If true then call termination function if it was
* previously set. Within DOM this will always be true, but outside
* callers (such as xpconnect) who may do script evaluations nested
* inside DOM script evaluations can pass false to avoid premature
* calls to the termination function.
* @param aTerminated If true then do script termination handling. Within DOM
* this will always be true, but outside callers (such as xpconnect) who
* may do script evaluations nested inside inside DOM script evaluations
* can pass false to avoid premature termination handling.
* @return NS_OK if the method is successful
*/
virtual void ScriptEvaluated(bool aTerminated) = 0;
@ -196,19 +193,6 @@ public:
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
JS::MutableHandle<JSScript*> aResult) = 0;
/**
* JS only - this function need not be implemented by languages other
* than JS (ie, this should be moved to a private interface!)
* Called to specify a function that should be called when the current
* script (if there is one) terminates. Generally used if breakdown
* of script state needs to happen, but should be deferred till
* the end of script evaluation.
*
* @throws NS_ERROR_OUT_OF_MEMORY if that happens
*/
virtual void SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsIDOMWindow* aRef) = 0;
/**
* Called to disable/enable script execution in this context.
*/

View File

@ -1141,7 +1141,6 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime, bool aGCOnDestruction,
::JS_SetOperationCallback(mContext, DOMOperationCallback);
}
mIsInitialized = false;
mTerminations = nullptr;
mScriptsEnabled = true;
mOperationCallbackTime = 0;
mModalStateTime = 0;
@ -1156,11 +1155,6 @@ nsJSContext::~nsJSContext()
mNext->mPrev = mPrev;
}
// We may still have pending termination functions if the context is destroyed
// before they could be executed. In this case, free the references to their
// parameters, but don't execute the functions (see bug 622326).
delete mTerminations;
mGlobalObjectRef = nullptr;
DestroyJSContext();
@ -1289,8 +1283,6 @@ nsJSContext::EvaluateString(const nsAString& aScript,
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(ok, NS_OK);
nsJSContext::TerminationFuncHolder holder(this);
// Scope the JSAutoCompartment so that it gets destroyed before we pop the
// cx and potentially call JS_RestoreFrameChain.
XPCAutoRequest ar(mContext);
@ -1414,7 +1406,6 @@ nsJSContext::ExecuteScript(JSScript* aScriptObject_,
nsCxPusher pusher;
pusher.Push(mContext);
nsJSContext::TerminationFuncHolder holder(this);
XPCAutoRequest ar(mContext);
// Scope the JSAutoCompartment so that it gets destroyed before we pop the
@ -2361,20 +2352,6 @@ nsJSContext::IsContextInitialized()
void
nsJSContext::ScriptEvaluated(bool aTerminated)
{
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 = nullptr;
for (nsJSContext::TerminationFuncClosure* cur = start;
cur;
cur = cur->mNext) {
(*(cur->mTerminationFunc))(cur->mTerminationFuncArg);
}
delete start;
}
JS_MaybeGC(mContext);
if (aTerminated) {
@ -2384,17 +2361,6 @@ nsJSContext::ScriptEvaluated(bool aTerminated)
}
}
void
nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsIDOMWindow* aRef)
{
NS_PRECONDITION(GetExecutingScript(), "should be executing script");
nsJSContext::TerminationFuncClosure* newClosure =
new nsJSContext::TerminationFuncClosure(aFunc, aRef, mTerminations);
mTerminations = newClosure;
}
bool
nsJSContext::GetScriptsEnabled()
{

View File

@ -75,8 +75,6 @@ public:
virtual bool IsContextInitialized();
virtual void ScriptEvaluated(bool aTerminated);
virtual void SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsIDOMWindow* aRef);
virtual bool GetScriptsEnabled();
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
@ -186,66 +184,6 @@ private:
JSContext *mContext;
bool mActive;
// Public so we can use it from CallbackFunction
public:
struct TerminationFuncHolder;
protected:
friend struct TerminationFuncHolder;
struct TerminationFuncClosure
{
TerminationFuncClosure(nsScriptTerminationFunc aFunc,
nsISupports* aArg,
TerminationFuncClosure* aNext) :
mTerminationFunc(aFunc),
mTerminationFuncArg(aArg),
mNext(aNext)
{
}
~TerminationFuncClosure()
{
delete mNext;
}
nsScriptTerminationFunc mTerminationFunc;
nsCOMPtr<nsISupports> mTerminationFuncArg;
TerminationFuncClosure* mNext;
};
// Public so we can use it from CallbackFunction
public:
struct TerminationFuncHolder
{
TerminationFuncHolder(nsJSContext* aContext)
: mContext(aContext),
mTerminations(aContext->mTerminations)
{
aContext->mTerminations = nullptr;
}
~TerminationFuncHolder()
{
// 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;
};
protected:
TerminationFuncClosure* mTerminations;
private:
bool mIsInitialized;
bool mScriptsEnabled;
bool mGCOnDestruction;

View File

@ -109,14 +109,6 @@ CallbackObject::CallSetup::CallSetup(JS::Handle<JSObject*> aCallback,
nsresult rv = nsContentUtils::GetSecurityManager()->
CheckFunctionAccess(cx, js::UncheckedUnwrap(aCallback), nullptr);
// Construct a termination func holder even if we're not planning to
// run any script. We need this because we're going to call
// ScriptEvaluated even if we don't run the script... See XXX
// comment above.
if (ctx) {
mTerminationFuncHolder.construct(static_cast<nsJSContext*>(ctx));
}
if (NS_FAILED(rv)) {
// Security check failed. We're done here.
return;

View File

@ -148,10 +148,6 @@ protected:
// this needs to be a Maybe.
Maybe<XPCAutoRequest> mAr;
// Can't construct a TerminationFuncHolder without an nsJSContext. But we
// generally want its destructor to come after the destructor of mCxPusher.
Maybe<nsJSContext::TerminationFuncHolder> mTerminationFuncHolder;
nsCxPusher mCxPusher;
// Can't construct a JSAutoCompartment without a JSContext either. Also,