Bug 865745 - Remove mCx from nsFrameScriptExecutor. r=smaug

This commit is contained in:
Bobby Holley 2013-06-29 18:44:06 -06:00
Родитель f3b8b79a74
Коммит c628779566
6 изменённых файлов: 4 добавлений и 148 удалений

Просмотреть файл

@ -2219,8 +2219,6 @@ public:
static_cast<nsInProcessTabChildGlobal*>(mFrameLoader->mChildMessageManager.get()); static_cast<nsInProcessTabChildGlobal*>(mFrameLoader->mChildMessageManager.get());
if (tabChild && tabChild->GetInnerManager()) { if (tabChild && tabChild->GetInnerManager()) {
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(tabChild->GetGlobal()); nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(tabChild->GetGlobal());
nsFrameScriptCx cx(static_cast<EventTarget*>(tabChild), tabChild);
StructuredCloneData data; StructuredCloneData data;
data.mData = mData.data(); data.mData = mData.data();
data.mDataLength = mData.nbytes(); data.mDataLength = mData.nbytes();

Просмотреть файл

@ -840,81 +840,6 @@ NS_NewGlobalMessageManager(nsIMessageBroadcaster** aResult)
return CallQueryInterface(mm, aResult); return CallQueryInterface(mm, aResult);
} }
void
ContentScriptErrorReporter(JSContext* aCx,
const char* aMessage,
JSErrorReport* aReport)
{
nsresult rv;
nsCOMPtr<nsIScriptError> scriptError =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return;
}
nsAutoString message, filename, line;
uint32_t lineNumber, columnNumber, flags, errorNumber;
if (aReport) {
if (aReport->ucmessage) {
message.Assign(static_cast<const PRUnichar*>(aReport->ucmessage));
}
filename.AssignWithConversion(aReport->filename);
line.Assign(static_cast<const PRUnichar*>(aReport->uclinebuf));
lineNumber = aReport->lineno;
columnNumber = aReport->uctokenptr - aReport->uclinebuf;
flags = aReport->flags;
errorNumber = aReport->errorNumber;
} else {
lineNumber = columnNumber = errorNumber = 0;
flags = nsIScriptError::errorFlag | nsIScriptError::exceptionFlag;
}
if (message.IsEmpty()) {
message.AssignWithConversion(aMessage);
}
rv = scriptError->Init(message, filename, line,
lineNumber, columnNumber, flags,
"Message manager content script");
if (NS_FAILED(rv)) {
return;
}
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
if (consoleService) {
(void) consoleService->LogMessage(scriptError);
}
#ifdef DEBUG
// Print it to stderr as well, for the benefit of those invoking
// mozilla with -console.
nsAutoCString error;
error.Assign("JavaScript ");
if (JSREPORT_IS_STRICT(flags)) {
error.Append("strict ");
}
if (JSREPORT_IS_WARNING(flags)) {
error.Append("warning: ");
} else {
error.Append("error: ");
}
error.Append(aReport->filename);
error.Append(", line ");
error.AppendInt(lineNumber, 10);
error.Append(": ");
if (aReport->ucmessage) {
AppendUTF16toUTF8(static_cast<const PRUnichar*>(aReport->ucmessage),
error);
} else {
error.Append(aMessage);
}
fprintf(stderr, "%s\n", error.get());
fflush(stderr);
#endif
}
nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>* nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>*
nsFrameScriptExecutor::sCachedScripts = nullptr; nsFrameScriptExecutor::sCachedScripts = nullptr;
nsScriptCacheCleaner* nsFrameScriptExecutor::sScriptCacheCleaner = nullptr; nsScriptCacheCleaner* nsFrameScriptExecutor::sScriptCacheCleaner = nullptr;
@ -937,20 +862,6 @@ nsFrameScriptExecutor::DidCreateGlobal()
void void
nsFrameScriptExecutor::DestroyCx() nsFrameScriptExecutor::DestroyCx()
{ {
if (mCxStackRefCnt) {
mDelayedCxDestroy = true;
return;
}
mDelayedCxDestroy = false;
if (mCx) {
nsIXPConnect* xpc = nsContentUtils::XPConnect();
if (xpc) {
xpc->ReleaseJSContext(mCx, true);
} else {
JS_DestroyContext(mCx);
}
}
mCx = nullptr;
mGlobal = nullptr; mGlobal = nullptr;
} }
@ -1094,26 +1005,16 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope,
runtimeSvc->GetRuntime(&rt); runtimeSvc->GetRuntime(&rt);
NS_ENSURE_TRUE(rt, false); NS_ENSURE_TRUE(rt, false);
JSContext* cx_ = JS_NewContext(rt, 8192); AutoSafeJSContext cx;
NS_ENSURE_TRUE(cx_, false);
AutoPushJSContext cx(cx_);
mCx = cx;
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal)); nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS);
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
nsIXPConnect* xpc = nsContentUtils::XPConnect(); nsIXPConnect* xpc = nsContentUtils::XPConnect();
const uint32_t flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES; const uint32_t flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES;
JS_SetContextPrivate(cx, aScope);
JS::CompartmentOptions options; JS::CompartmentOptions options;
options.setZone(JS::SystemZone) options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST); .setVersion(JSVERSION_LATEST);
nsresult rv = nsresult rv =
xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal, xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal,
flags, options, getter_AddRefs(mGlobal)); flags, options, getter_AddRefs(mGlobal));
@ -1123,8 +1024,6 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope,
JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject()); JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject());
NS_ENSURE_TRUE(global, false); NS_ENSURE_TRUE(global, false);
JS_SetGlobalObject(cx, global);
// Set the location information for the new global, so that tools like // Set the location information for the new global, so that tools like
// about:memory may use that information. // about:memory may use that information.
xpc::SetLocationForGlobal(global, aID); xpc::SetLocationForGlobal(global, aID);
@ -1139,21 +1038,13 @@ nsFrameScriptExecutor::Traverse(nsFrameScriptExecutor *tmp,
nsCycleCollectionTraversalCallback &cb) nsCycleCollectionTraversalCallback &cb)
{ {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
nsIXPConnect* xpc = nsContentUtils::XPConnect();
if (xpc) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCx");
xpc->NoteJSContext(tmp->mCx, cb);
}
} }
// static // static
void void
nsFrameScriptExecutor::Unlink(nsFrameScriptExecutor* aTmp) nsFrameScriptExecutor::Unlink(nsFrameScriptExecutor* aTmp)
{ {
if (aTmp->mCx) { aTmp->mGlobal = nullptr;
JSAutoRequest ar(aTmp->mCx);
JS_SetGlobalObject(aTmp->mCx, nullptr);
}
} }
NS_IMPL_ISUPPORTS1(nsScriptCacheCleaner, nsIObserver) NS_IMPL_ISUPPORTS1(nsScriptCacheCleaner, nsIObserver)

Просмотреть файл

@ -257,11 +257,6 @@ private:
bool* aValid); bool* aValid);
}; };
void
ContentScriptErrorReporter(JSContext* aCx,
const char* aMessage,
JSErrorReport* aReport);
class nsScriptCacheCleaner; class nsScriptCacheCleaner;
struct nsFrameJSScriptExecutorHolder struct nsFrameJSScriptExecutorHolder
@ -284,8 +279,7 @@ public:
} }
protected: protected:
friend class nsFrameScriptCx; friend class nsFrameScriptCx;
nsFrameScriptExecutor() : mCx(nullptr), mCxStackRefCnt(0), nsFrameScriptExecutor()
mDelayedCxDestroy(false)
{ MOZ_COUNT_CTOR(nsFrameScriptExecutor); } { MOZ_COUNT_CTOR(nsFrameScriptExecutor); }
~nsFrameScriptExecutor() ~nsFrameScriptExecutor()
{ MOZ_COUNT_DTOR(nsFrameScriptExecutor); } { MOZ_COUNT_DTOR(nsFrameScriptExecutor); }
@ -301,33 +295,11 @@ protected:
nsCycleCollectionTraversalCallback &cb); nsCycleCollectionTraversalCallback &cb);
static void Unlink(nsFrameScriptExecutor* aTmp); static void Unlink(nsFrameScriptExecutor* aTmp);
nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal; nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
JSContext* mCx;
uint32_t mCxStackRefCnt;
bool mDelayedCxDestroy;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
static nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>* sCachedScripts; static nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>* sCachedScripts;
static nsScriptCacheCleaner* sScriptCacheCleaner; static nsScriptCacheCleaner* sScriptCacheCleaner;
}; };
class nsFrameScriptCx
{
public:
nsFrameScriptCx(nsISupports* aOwner, nsFrameScriptExecutor* aExec)
: mOwner(aOwner), mExec(aExec)
{
++(mExec->mCxStackRefCnt);
}
~nsFrameScriptCx()
{
if (--(mExec->mCxStackRefCnt) == 0 &&
mExec->mDelayedCxDestroy) {
mExec->DestroyCx();
}
}
nsCOMPtr<nsISupports> mOwner;
nsFrameScriptExecutor* mExec;
};
class nsScriptCacheCleaner MOZ_FINAL : public nsIObserver class nsScriptCacheCleaner MOZ_FINAL : public nsIObserver
{ {
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS

Просмотреть файл

@ -118,7 +118,6 @@ nsInProcessTabChildGlobal::nsInProcessTabChildGlobal(nsIDocShell* aShell,
nsInProcessTabChildGlobal::~nsInProcessTabChildGlobal() nsInProcessTabChildGlobal::~nsInProcessTabChildGlobal()
{ {
NS_ASSERTION(!mCx, "Couldn't release JSContext?!?");
} }
/* [notxpcom] boolean markForCC (); */ /* [notxpcom] boolean markForCC (); */

Просмотреть файл

@ -1446,7 +1446,6 @@ TabChild::DispatchMessageManagerMessage(const nsAString& aMessageName,
} }
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal()); nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal());
nsFrameScriptCx frameScriptCx(static_cast<nsIWebBrowserChrome*>(this), this);
// Let the BrowserElementScrolling helper (if it exists) for this // Let the BrowserElementScrolling helper (if it exists) for this
// content manipulate the frame state. // content manipulate the frame state.
nsRefPtr<nsFrameMessageManager> mm = nsRefPtr<nsFrameMessageManager> mm =
@ -2011,7 +2010,6 @@ TabChild::RecvAsyncMessage(const nsString& aMessage,
{ {
if (mTabChildGlobal) { if (mTabChildGlobal) {
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal()); nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal());
nsFrameScriptCx cx(static_cast<nsIWebBrowserChrome*>(this), this);
StructuredCloneData cloneData = UnpackClonedMessageDataForChild(aData); StructuredCloneData cloneData = UnpackClonedMessageDataForChild(aData);
nsRefPtr<nsFrameMessageManager> mm = nsRefPtr<nsFrameMessageManager> mm =
static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get()); static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());

Просмотреть файл

@ -282,8 +282,6 @@ public:
nsIWebNavigation* WebNavigation() { return mWebNav; } nsIWebNavigation* WebNavigation() { return mWebNav; }
JSContext* GetJSContext() { return mCx; }
nsIPrincipal* GetPrincipal() { return mPrincipal; } nsIPrincipal* GetPrincipal() { return mPrincipal; }
/** Return the DPI of the widget this TabChild draws to. */ /** Return the DPI of the widget this TabChild draws to. */