From e0bd7114ae02717f8f101e863c374c85b06d8f03 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 20 Jun 2019 21:44:03 +0000 Subject: [PATCH] Bug 1559468 part 1. Move JS_DefineProfilingFunctions into InitClassesWithNewWrappedGlobal. r=mccr8 All callers of InitClassesWithNewWrappedGlobal already call it. Differential Revision: https://phabricator.services.mozilla.com/D35457 --HG-- extra : moz-landing-system : lando --- ipc/testshell/XPCShellEnvironment.cpp | 3 +-- js/xpconnect/loader/mozJSComponentLoader.cpp | 3 +-- js/xpconnect/src/XPCShellImpl.cpp | 3 +-- js/xpconnect/src/nsXPConnect.cpp | 7 +++++++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index 895020acda35..081c1a017a40 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -397,8 +397,7 @@ bool XPCShellEnvironment::Init() { JS::Rooted privateVal(cx, PrivateValue(this)); if (!JS_DefineProperty(cx, globalObj, "__XPCShellEnvironment", privateVal, JSPROP_READONLY | JSPROP_PERMANENT) || - !JS_DefineFunctions(cx, globalObj, gGlobalFunctions) || - !JS_DefineProfilingFunctions(cx, globalObj)) { + !JS_DefineFunctions(cx, globalObj, gGlobalFunctions)) { NS_ERROR("JS_DefineFunctions failed!"); return false; } diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 72fde826bd64..b8cb88c0ef87 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -588,8 +588,7 @@ void mozJSComponentLoader::CreateLoaderGlobal(JSContext* aCx, backstagePass->SetGlobalObject(global); JSAutoRealm ar(aCx, global); - if (!JS_DefineFunctions(aCx, global, gGlobalFun) || - !JS_DefineProfilingFunctions(aCx, global)) { + if (!JS_DefineFunctions(aCx, global, gGlobalFun)) { return; } diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index fbd27e5a177d..b5e4cef8cdf7 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -1374,8 +1374,7 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp, return 1; } - if (!JS_DefineFunctions(cx, glob, glob_functions) || - !JS_DefineProfilingFunctions(cx, glob)) { + if (!JS_DefineFunctions(cx, glob, glob_functions)) { return 1; } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index a63c5caf89a6..b4bb8d1b4460 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -561,6 +561,13 @@ nsresult InitClassesWithNewWrappedGlobal(JSContext* aJSContext, return UnexpectedFailure(NS_ERROR_FAILURE); } + { // Scope for JSAutoRealm + JSAutoRealm ar(aJSContext, global); + if (!JS_DefineProfilingFunctions(aJSContext, global)) { + return UnexpectedFailure(NS_ERROR_OUT_OF_MEMORY); + } + } + aNewGlobal.set(global); return NS_OK; }