Bug 865729 - Use XPConnect directly in C++ unit tests. r=gabor

This commit is contained in:
Bobby Holley 2013-04-29 11:16:22 -07:00
parent 4afac12af4
commit e22d7d9f6e
2 changed files with 7 additions and 13 deletions

View File

@ -21,7 +21,7 @@
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsITelemetry.h"
#include "nsIJSContextStack.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "prio.h"
@ -505,10 +505,9 @@ int main(int argc, char** argv)
// using the cx here without triggering a cx stack assert, so just do that
// for now. Eventually, the whole notion of pushing and popping will just go
// away.
nsCOMPtr<nsIThreadJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (stack)
cx = stack->GetSafeJSContext();
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
if (xpc)
cx = xpc->GetSafeJSContext();
bool use_js = !!cx;
JSAutoRequest req(cx);

View File

@ -3,7 +3,7 @@
#include "nsISettingsService.h"
#include "nsCOMPtr.h"
#include "nsIJSContextStack.h"
#include "nsIXPConnect.h"
#include "nsIObserver.h"
#include "nsIThread.h"
#include "nsComponentManagerUtils.h"
@ -153,13 +153,8 @@ TestSettingsObserver::Observe(nsISupports *aSubject,
}
// Get the safe JS context.
nsCOMPtr<nsIThreadJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (!stack) {
CHECK_MSG(false, "Failed to get JSContextStack");
return NS_OK;
}
JSContext *cx = stack->GetSafeJSContext();
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
JSContext *cx = xpc->GetSafeJSContext();
if (!cx) {
CHECK_MSG(false, "Failed to GetSafeJSContext");
return NS_OK;