From 45bacdcb69756fa475865a150c4227e1169116c9 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Fri, 8 Aug 2014 13:30:54 +0100 Subject: [PATCH] Bug 1047509 - Part 6: Change mozJSComponentLoader::ObjectForLocation to use AutoJSAPI and SafeJSContext instead of JSCLContextHelper and its own JSContext. r=bholley --- js/xpconnect/loader/mozJSComponentLoader.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index c54d5b23da7b..8be952919d07 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -50,6 +50,7 @@ #include "mozilla/scache/StartupCacheUtils.h" #include "mozilla/MacroForEach.h" #include "mozilla/Preferences.h" +#include "mozilla/dom/ScriptSettings.h" #include "js/OldDebugAPI.h" @@ -767,8 +768,11 @@ mozJSComponentLoader::PrepareObjectForLocation(JSContext* aCx, return nullptr; if (createdNewGlobal) { - RootedObject global(aCx, holder->GetJSObject()); - JS_FireOnNewGlobalObject(aCx, global); + // AutoEntryScript required to invoke debugger hook, which is a + // Gecko-specific concept at present. + dom::AutoEntryScript aes(GetNativeForGlobal(holder->GetJSObject())); + RootedObject global(aes.cx(), holder->GetJSObject()); + JS_FireOnNewGlobalObject(aes.cx(), global); } return obj; @@ -783,11 +787,11 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo &aInfo, bool aPropagateExceptions, MutableHandleValue aException) { - JSCLContextHelper cx(mContext); + MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread."); - JS_AbortIfWrongThread(JS_GetRuntime(cx)); - - JSCLAutoErrorReporterSetter aers(cx, xpc::SystemErrorReporter); + dom::AutoJSAPI jsapi; + jsapi.Init(); + JSContext* cx = jsapi.cx(); bool realFile = false; nsresult rv = aInfo.EnsureURI(); @@ -1041,6 +1045,10 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo &aInfo, bool ok = false; { + // We're going to run script via JS_ExecuteScriptVersion or + // JS_CallFunction, so we need an AutoEntryScript. + // This is Gecko-specific and not in any spec. + dom::AutoEntryScript aes(GetNativeForGlobal(CurrentGlobalOrNull(cx))); AutoSaveContextOptions asco(cx); if (aPropagateExceptions) ContextOptionsRef(cx).setDontReportUncaught(true);