From 63bfd2eb94591b5f8272ad5140502018c4da9e10 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 13 Aug 2014 15:36:44 -0700 Subject: [PATCH] Bug 1052042 - Move the pre-pop GC to AutoEntryScript. r=billm --- dom/base/ScriptSettings.cpp | 8 ++++++++ dom/base/ScriptSettings.h | 2 ++ js/xpconnect/src/nsCxPusher.cpp | 9 --------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index f0a1cd1427b..da27c09ad69 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -348,6 +348,14 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, MOZ_ASSERT_IF(aCx && aIsMainThread, aCx == FindJSContext(aGlobalObject)); } +AutoEntryScript::~AutoEntryScript() +{ + // GC when we pop a script entry point. This is a useful heuristic that helps + // us out on certain (flawed) benchmarks like sunspider, because it lets us + // avoid GCing during the timing loop. + JS_MaybeGC(cx()); +} + AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject) : ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ false) , mCallerOverride(nsContentUtils::GetCurrentJSContextForThread()) diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index 17b8360a11c..b17def8e40f 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -201,6 +201,8 @@ public: // Note: aCx is mandatory off-main-thread. JSContext* aCx = nullptr); + ~AutoEntryScript(); + void SetWebIDLCallerPrincipal(nsIPrincipal *aPrincipal) { mWebIDLCallerPrincipal = aPrincipal; } diff --git a/js/xpconnect/src/nsCxPusher.cpp b/js/xpconnect/src/nsCxPusher.cpp index 3c1d9827120..df0cbd72476 100644 --- a/js/xpconnect/src/nsCxPusher.cpp +++ b/js/xpconnect/src/nsCxPusher.cpp @@ -51,15 +51,6 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) AutoCxPusher::~AutoCxPusher() { - // GC when we pop a script entry point. This is a useful heuristic that helps - // us out on certain (flawed) benchmarks like sunspider, because it lets us - // avoid GCing during the timing loop. - // - // NB: We need to take care to only do this if we're in a compartment, - // otherwise JS_MaybeGC will segfault. - if (mScx && !mAutoCompartment.empty()) - JS_MaybeGC(nsXPConnect::XPConnect()->GetCurrentJSContext()); - // Leave the compartment and request before popping. mAutoCompartment.destroyIfConstructed(); mAutoRequest.destroyIfConstructed();