From f3b8f66f2162aed404999e3e930ee04818774344 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 29 Apr 2013 11:16:22 -0700 Subject: [PATCH] Bug 865729 - Use XPConnect directly in C++ unit tests. r=gabor --- startupcache/test/TestStartupCache.cpp | 9 ++++----- xpcom/tests/TestSettingsAPI.cpp | 11 +++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/startupcache/test/TestStartupCache.cpp b/startupcache/test/TestStartupCache.cpp index 5ae67501faaa..73f7904f5a44 100644 --- a/startupcache/test/TestStartupCache.cpp +++ b/startupcache/test/TestStartupCache.cpp @@ -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 stack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1"); - if (stack) - cx = stack->GetSafeJSContext(); + nsCOMPtr xpc = do_GetService(nsIXPConnect::GetCID()); + if (xpc) + cx = xpc->GetSafeJSContext(); bool use_js = !!cx; JSAutoRequest req(cx); diff --git a/xpcom/tests/TestSettingsAPI.cpp b/xpcom/tests/TestSettingsAPI.cpp index 65967a1083eb..0cc3ac9c24ab 100644 --- a/xpcom/tests/TestSettingsAPI.cpp +++ b/xpcom/tests/TestSettingsAPI.cpp @@ -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 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 xpc = do_GetService(nsIXPConnect::GetCID()); + JSContext *cx = xpc->GetSafeJSContext(); if (!cx) { CHECK_MSG(false, "Failed to GetSafeJSContext"); return NS_OK;