From 09d5c94190091729599687c36449f6df147c32b7 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Wed, 14 Sep 2016 15:48:17 +0200 Subject: [PATCH] Bug 1302448 part 2 - Rename XPCJSRuntime to XPCJSContext. r=mrbkap --- dom/base/nsDOMClassInfo.cpp | 4 +- dom/base/nsGlobalWindow.cpp | 4 +- dom/base/nsInProcessTabChildGlobal.cpp | 2 +- js/src/shell/js.cpp | 2 +- js/xpconnect/idl/xpccomponents.idl | 2 +- js/xpconnect/loader/mozJSSubScriptLoader.cpp | 2 +- js/xpconnect/src/ExportHelpers.cpp | 2 +- js/xpconnect/src/Sandbox.cpp | 2 +- js/xpconnect/src/XPCCallContext.cpp | 16 +- js/xpconnect/src/XPCComponents.cpp | 12 +- js/xpconnect/src/XPCForwards.h | 2 +- js/xpconnect/src/XPCInlines.h | 36 +-- .../{XPCJSRuntime.cpp => XPCJSContext.cpp} | 208 +++++++++--------- js/xpconnect/src/XPCJSID.cpp | 6 +- js/xpconnect/src/XPCMaps.cpp | 2 +- js/xpconnect/src/XPCMaps.h | 4 +- js/xpconnect/src/XPCThrower.cpp | 4 +- js/xpconnect/src/XPCWrappedJS.cpp | 32 +-- js/xpconnect/src/XPCWrappedJSClass.cpp | 56 ++--- js/xpconnect/src/XPCWrappedNative.cpp | 24 +- js/xpconnect/src/XPCWrappedNativeInfo.cpp | 28 +-- js/xpconnect/src/XPCWrappedNativeJSOps.cpp | 36 +-- js/xpconnect/src/XPCWrappedNativeProto.cpp | 4 +- js/xpconnect/src/XPCWrappedNativeScope.cpp | 8 +- js/xpconnect/src/moz.build | 2 +- js/xpconnect/src/nsXPConnect.cpp | 54 ++--- js/xpconnect/src/xpcprivate.h | 78 +++---- js/xpconnect/tests/chrome/test_bug732665.xul | 4 +- .../tests/unit/test_watchdog_hibernate.js | 2 +- js/xpconnect/wrappers/AccessCheck.cpp | 4 +- js/xpconnect/wrappers/XrayWrapper.cpp | 52 ++--- toolkit/components/perfmonitoring/README.md | 2 +- tools/memory-profiler/MemoryProfiler.cpp | 8 +- xpcom/build/XPCOMInit.cpp | 6 +- 34 files changed, 355 insertions(+), 355 deletions(-) rename js/xpconnect/src/{XPCJSRuntime.cpp => XPCJSContext.cpp} (96%) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 3b7220ac505c0..fa324674e4acf 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -1717,7 +1717,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, JS::Handle obj, JS::Handle id, JS::MutableHandle desc) { - if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)) { + if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) { return LookupComponentsShim(cx, obj, aWin->AsInner(), desc); } @@ -1725,7 +1725,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, // Note: We use |obj| rather than |aWin| to get the principal here, because // this is called during Window setup when the Document isn't necessarily // hooked up yet. - if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_CONTROLLERS) && + if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) && !xpc::IsXrayWrapper(obj) && !nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj))) { diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 1424359954afa..b85e3c2b1e45a 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -4475,11 +4475,11 @@ nsGlobalWindow::MayResolve(jsid aId) return false; } - if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)) { + if (aId == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) { return true; } - if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_CONTROLLERS)) { + if (aId == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) { // We only resolve .controllers in release builds and on non-chrome windows, // but let's not worry about any of that stuff. return true; diff --git a/dom/base/nsInProcessTabChildGlobal.cpp b/dom/base/nsInProcessTabChildGlobal.cpp index d650d48ed9d1a..10ccf4aec3b2c 100644 --- a/dom/base/nsInProcessTabChildGlobal.cpp +++ b/dom/base/nsInProcessTabChildGlobal.cpp @@ -291,7 +291,7 @@ nsInProcessTabChildGlobal::PreHandleEvent(EventChainPreVisitor& aVisitor) nsresult nsInProcessTabChildGlobal::InitTabChildGlobal() { - // If you change this, please change GetCompartmentName() in XPCJSRuntime.cpp + // If you change this, please change GetCompartmentName() in XPCJSContext.cpp // accordingly. nsAutoCString id; id.AssignLiteral("inProcessTabChildGlobal"); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 23454e4346092..c618cd174bdca 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -127,7 +127,7 @@ static const size_t gStackChunkSize = 8192; /* * Note: This limit should match the stack limit set by the browser in - * js/xpconnect/src/XPCJSRuntime.cpp + * js/xpconnect/src/XPCJSContext.cpp */ #if defined(MOZ_ASAN) || (defined(DEBUG) && !defined(XP_WIN)) static const size_t gMaxStackSize = 2 * 128 * sizeof(size_t) * 1024; diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index 9b40234f5fce2..711ea4c64238e 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -612,7 +612,7 @@ interface nsIXPCComponents_Utils : nsISupports * watchdog-related event occured. * * Valid categories: - * "RuntimeStateChange" - Runtime switching between active and inactive states + * "ContextStateChange" - Context switching between active and inactive states * "WatchdogWakeup" - Watchdog waking up from sleeping * "WatchdogHibernateStart" - Watchdog begins hibernating * "WatchdogHibernateStop" - Watchdog stops hibernating diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index b283b3f8f5c00..38c5951889034 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -776,7 +776,7 @@ NotifyPrecompilationCompleteRunnable::Run(void) AutoSendObserverNotification notifier(mPrecompiler); if (mToken) { - JSContext* cx = XPCJSRuntime::Get()->Context(); + JSContext* cx = XPCJSContext::Get()->Context(); NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); JS::CancelOffThreadScript(cx, mToken); } diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index e38d1baab6371..d1e9b33780d57 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -365,7 +365,7 @@ NewFunctionForwarder(JSContext* cx, HandleId idArg, HandleObject callable, { RootedId id(cx, idArg); if (id == JSID_VOIDHANDLE) - id = GetRTIdByIndex(cx, XPCJSRuntime::IDX_EMPTYSTRING); + id = GetJSIDByIndex(cx, XPCJSContext::IDX_EMPTYSTRING); // We have no way of knowing whether the underlying function wants to be a // constructor or not, so we just mark all forwarders as constructors, and diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 0809a87f5e546..013a5bcdc94bc 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -482,7 +482,7 @@ sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v) // Whenever JS_EnumerateStandardClasses is called, it defines the // "undefined" property, even if it's already defined. We don't want to do // anything in that case. - if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_UNDEFINED)) + if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_UNDEFINED)) return true; // Avoid recursively triggering sandbox_addProperty in the diff --git a/js/xpconnect/src/XPCCallContext.cpp b/js/xpconnect/src/XPCCallContext.cpp index 1b9ac459d16bd..b7bc4bc3072a2 100644 --- a/js/xpconnect/src/XPCCallContext.cpp +++ b/js/xpconnect/src/XPCCallContext.cpp @@ -27,7 +27,7 @@ XPCCallContext::XPCCallContext(JSContext* cx, : mAr(cx), mState(INIT_FAILED), mXPC(nsXPConnect::XPConnect()), - mXPCJSRuntime(nullptr), + mXPCJSContext(nullptr), mJSContext(cx), mWrapper(nullptr), mTearOff(nullptr), @@ -39,12 +39,12 @@ XPCCallContext::XPCCallContext(JSContext* cx, if (!mXPC) return; - mXPCJSRuntime = XPCJSRuntime::Get(); + mXPCJSContext = XPCJSContext::Get(); // hook into call context chain. - mPrevCallContext = mXPCJSRuntime->SetCallContext(this); + mPrevCallContext = mXPCJSContext->SetCallContext(this); - mState = HAVE_RUNTIME; + mState = HAVE_CONTEXT; if (!obj) return; @@ -125,7 +125,7 @@ void XPCCallContext::SetCallInfo(XPCNativeInterface* iface, XPCNativeMember* member, bool isSetter) { - CHECK_STATE(HAVE_RUNTIME); + CHECK_STATE(HAVE_CONTEXT); // We are going straight to the method info and need not do a lookup // by id. @@ -197,7 +197,7 @@ XPCCallContext::SystemIsBeingShutDown() // can be making this call on one thread for call contexts on another // thread. NS_WARNING("Shutting Down XPConnect even through there is a live XPCCallContext"); - mXPCJSRuntime = nullptr; + mXPCJSContext = nullptr; mState = SYSTEM_SHUTDOWN; mInterface = nullptr; @@ -207,8 +207,8 @@ XPCCallContext::SystemIsBeingShutDown() XPCCallContext::~XPCCallContext() { - if (mXPCJSRuntime) { - DebugOnly old = mXPCJSRuntime->SetCallContext(mPrevCallContext); + if (mXPCJSContext) { + DebugOnly old = mXPCJSContext->SetCallContext(mPrevCallContext); MOZ_ASSERT(old == this, "bad pop from per thread data"); } } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index ad6bdadb15fa0..8ce4d79a0626e 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2569,7 +2569,7 @@ nsXPCComponents_Utils::GetWeakReference(HandleValue object, JSContext* cx, NS_IMETHODIMP nsXPCComponents_Utils::ForceGC() { - JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context(); + JSContext* cx = nsXPConnect::GetContextInstance()->Context(); PrepareForFullGC(cx); GCForReason(cx, GC_NORMAL, gcreason::COMPONENT_UTILS); return NS_OK; @@ -3187,8 +3187,8 @@ NS_IMETHODIMP nsXPCComponents_Utils::GetWatchdogTimestamp(const nsAString& aCategory, PRTime* aOut) { WatchdogTimestampCategory category; - if (aCategory.EqualsLiteral("RuntimeStateChange")) - category = TimestampRuntimeStateChange; + if (aCategory.EqualsLiteral("ContextStateChange")) + category = TimestampContextStateChange; else if (aCategory.EqualsLiteral("WatchdogWakeup")) category = TimestampWatchdogWakeup; else if (aCategory.EqualsLiteral("WatchdogHibernateStart")) @@ -3197,7 +3197,7 @@ nsXPCComponents_Utils::GetWatchdogTimestamp(const nsAString& aCategory, PRTime* category = TimestampWatchdogHibernateStop; else return NS_ERROR_INVALID_ARG; - *aOut = XPCJSRuntime::Get()->GetWatchdogTimestamp(category); + *aOut = XPCJSContext::Get()->GetWatchdogTimestamp(category); return NS_OK; } @@ -3458,7 +3458,7 @@ nsXPCComponents::GetManager(nsIComponentManager * *aManager) NS_IMETHODIMP nsXPCComponents::GetReturnCode(JSContext* aCx, MutableHandleValue aOut) { - nsresult res = XPCJSRuntime::Get()->GetPendingResult(); + nsresult res = XPCJSContext::Get()->GetPendingResult(); aOut.setNumber(static_cast(res)); return NS_OK; } @@ -3469,7 +3469,7 @@ nsXPCComponents::SetReturnCode(JSContext* aCx, HandleValue aCode) nsresult rv; if (!ToUint32(aCx, aCode, (uint32_t*)&rv)) return NS_ERROR_FAILURE; - XPCJSRuntime::Get()->SetPendingResult(rv); + XPCJSContext::Get()->SetPendingResult(rv); return NS_OK; } diff --git a/js/xpconnect/src/XPCForwards.h b/js/xpconnect/src/XPCForwards.h index dbed42073ea61..7ef0ddb75772f 100644 --- a/js/xpconnect/src/XPCForwards.h +++ b/js/xpconnect/src/XPCForwards.h @@ -12,7 +12,7 @@ // forward declarations of interally used classes... class nsXPConnect; -class XPCJSRuntime; +class XPCJSContext; class XPCContext; class XPCCallContext; diff --git a/js/xpconnect/src/XPCInlines.h b/js/xpconnect/src/XPCInlines.h index 19fc5d124e701..a060e2e83eea1 100644 --- a/js/xpconnect/src/XPCInlines.h +++ b/js/xpconnect/src/XPCInlines.h @@ -14,19 +14,19 @@ /***************************************************************************/ inline void -XPCJSRuntime::AddVariantRoot(XPCTraceableVariant* variant) +XPCJSContext::AddVariantRoot(XPCTraceableVariant* variant) { variant->AddToRootSet(&mVariantRoots); } inline void -XPCJSRuntime::AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS) +XPCJSContext::AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS) { wrappedJS->AddToRootSet(&mWrappedJSRoots); } inline void -XPCJSRuntime::AddObjectHolderRoot(XPCJSObjectHolder* holder) +XPCJSContext::AddObjectHolderRoot(XPCJSObjectHolder* holder) { holder->AddToRootSet(&mObjectHolderRoots); } @@ -39,24 +39,24 @@ XPCCallContext::IsValid() const return mState != INIT_FAILED; } -inline XPCJSRuntime* -XPCCallContext::GetRuntime() const +inline XPCJSContext* +XPCCallContext::GetContext() const { - CHECK_STATE(HAVE_RUNTIME); - return mXPCJSRuntime; + CHECK_STATE(HAVE_CONTEXT); + return mXPCJSContext; } inline JSContext* XPCCallContext::GetJSContext() const { - CHECK_STATE(HAVE_RUNTIME); + CHECK_STATE(HAVE_CONTEXT); return mJSContext; } inline XPCCallContext* XPCCallContext::GetPrevCallContext() const { - CHECK_STATE(HAVE_RUNTIME); + CHECK_STATE(HAVE_CONTEXT); return mPrevCallContext; } @@ -185,29 +185,29 @@ XPCCallContext::SetRetVal(JS::Value val) inline jsid XPCCallContext::GetResolveName() const { - CHECK_STATE(HAVE_RUNTIME); - return XPCJSRuntime::Get()->GetResolveName(); + CHECK_STATE(HAVE_CONTEXT); + return XPCJSContext::Get()->GetResolveName(); } inline jsid XPCCallContext::SetResolveName(JS::HandleId name) { - CHECK_STATE(HAVE_RUNTIME); - return XPCJSRuntime::Get()->SetResolveName(name); + CHECK_STATE(HAVE_CONTEXT); + return XPCJSContext::Get()->SetResolveName(name); } inline XPCWrappedNative* XPCCallContext::GetResolvingWrapper() const { CHECK_STATE(HAVE_OBJECT); - return XPCJSRuntime::Get()->GetResolvingWrapper(); + return XPCJSContext::Get()->GetResolvingWrapper(); } inline XPCWrappedNative* XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w) { CHECK_STATE(HAVE_OBJECT); - return XPCJSRuntime::Get()->SetResolvingWrapper(w); + return XPCJSContext::Get()->SetResolvingWrapper(w); } inline uint16_t @@ -536,10 +536,10 @@ xpc_ForcePropertyResolve(JSContext* cx, JS::HandleObject obj, jsid idArg) } inline jsid -GetRTIdByIndex(JSContext* cx, unsigned index) +GetJSIDByIndex(JSContext* cx, unsigned index) { - XPCJSRuntime* rt = nsXPConnect::XPConnect()->GetRuntime(); - return rt->GetStringID(index); + XPCJSContext* xpcx = nsXPConnect::XPConnect()->GetContext(); + return xpcx->GetStringID(index); } inline diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSContext.cpp similarity index 96% rename from js/xpconnect/src/XPCJSRuntime.cpp rename to js/xpconnect/src/XPCJSContext.cpp index 38f72a765bfb1..9abe3502aa476 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* Per JSRuntime object */ +/* Per JSContext object */ #include "mozilla/MemoryReporting.h" #include "mozilla/UniquePtr.h" @@ -77,7 +77,7 @@ using mozilla::dom::AutoEntryScript; /***************************************************************************/ -const char* const XPCJSRuntime::mStrings[] = { +const char* const XPCJSContext::mStrings[] = { "constructor", // IDX_CONSTRUCTOR "toString", // IDX_TO_STRING "toSource", // IDX_TO_SOURCE @@ -501,19 +501,19 @@ EnableUniversalXPConnect(JSContext* cx) JSObject* UnprivilegedJunkScope() { - return XPCJSRuntime::Get()->UnprivilegedJunkScope(); + return XPCJSContext::Get()->UnprivilegedJunkScope(); } JSObject* PrivilegedJunkScope() { - return XPCJSRuntime::Get()->PrivilegedJunkScope(); + return XPCJSContext::Get()->PrivilegedJunkScope(); } JSObject* CompilationScope() { - return XPCJSRuntime::Get()->CompilationScope(); + return XPCJSContext::Get()->CompilationScope(); } nsGlobalWindow* @@ -568,8 +568,8 @@ CurrentWindowOrNull(JSContext* cx) static void CompartmentDestroyedCallback(JSFreeOp* fop, JSCompartment* compartment) { - // NB - This callback may be called in JS_DestroyRuntime, which happens - // after the XPCJSRuntime has been torn down. + // NB - This callback may be called in JS_DestroyContext, which happens + // after the XPCJSContext has been torn down. // Get the current compartment private into an AutoPtr (which will do the // cleanup for us), and null out the private (which may already be null). @@ -589,7 +589,7 @@ CompartmentSizeOfIncludingThisCallback(MallocSizeOf mallocSizeOf, JSCompartment* * inner window and whose reflector is gray. We don't merge system * compartments, so we don't use them to trigger merging CCs. */ -bool XPCJSRuntime::UsefulToMergeZones() const +bool XPCJSContext::UsefulToMergeZones() const { MOZ_ASSERT(NS_IsMainThread()); @@ -600,7 +600,7 @@ bool XPCJSRuntime::UsefulToMergeZones() const return false; } -void XPCJSRuntime::TraceNativeBlackRoots(JSTracer* trc) +void XPCJSContext::TraceNativeBlackRoots(JSTracer* trc) { // Skip this part if XPConnect is shutting down. We get into // bad locking problems with the thread iteration otherwise. @@ -620,7 +620,7 @@ void XPCJSRuntime::TraceNativeBlackRoots(JSTracer* trc) nsXPConnect::XPConnect()->IsShuttingDown()); } -void XPCJSRuntime::TraceAdditionalNativeGrayRoots(JSTracer* trc) +void XPCJSContext::TraceAdditionalNativeGrayRoots(JSTracer* trc) { XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(trc, this); @@ -632,7 +632,7 @@ void XPCJSRuntime::TraceAdditionalNativeGrayRoots(JSTracer* trc) } void -XPCJSRuntime::TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb) +XPCJSContext::TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb) { XPCWrappedNativeScope::SuspectAllWrappers(this, cb); @@ -653,13 +653,13 @@ XPCJSRuntime::TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& c } void -XPCJSRuntime::UnmarkSkippableJSHolders() +XPCJSContext::UnmarkSkippableJSHolders() { CycleCollectedJSContext::UnmarkSkippableJSHolders(); } void -XPCJSRuntime::PrepareForForgetSkippable() +XPCJSContext::PrepareForForgetSkippable() { nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { @@ -668,7 +668,7 @@ XPCJSRuntime::PrepareForForgetSkippable() } void -XPCJSRuntime::BeginCycleCollectionCallback() +XPCJSContext::BeginCycleCollectionCallback() { nsJSContext::BeginCycleCollectionCallback(); @@ -679,7 +679,7 @@ XPCJSRuntime::BeginCycleCollectionCallback() } void -XPCJSRuntime::EndCycleCollectionCallback(CycleCollectorResults& aResults) +XPCJSContext::EndCycleCollectionCallback(CycleCollectorResults& aResults) { nsJSContext::EndCycleCollectionCallback(aResults); @@ -690,7 +690,7 @@ XPCJSRuntime::EndCycleCollectionCallback(CycleCollectorResults& aResults) } void -XPCJSRuntime::DispatchDeferredDeletion(bool aContinuation, bool aPurge) +XPCJSContext::DispatchDeferredDeletion(bool aContinuation, bool aPurge) { mAsyncSnowWhiteFreer->Dispatch(aContinuation, aPurge); } @@ -698,17 +698,17 @@ XPCJSRuntime::DispatchDeferredDeletion(bool aContinuation, bool aPurge) void xpc_UnmarkSkippableJSHolders() { - if (nsXPConnect::XPConnect()->GetRuntime()) { - nsXPConnect::XPConnect()->GetRuntime()->UnmarkSkippableJSHolders(); + if (nsXPConnect::XPConnect()->GetContext()) { + nsXPConnect::XPConnect()->GetContext()->UnmarkSkippableJSHolders(); } } /* static */ void -XPCJSRuntime::GCSliceCallback(JSContext* cx, +XPCJSContext::GCSliceCallback(JSContext* cx, JS::GCProgress progress, const JS::GCDescription& desc) { - XPCJSRuntime* self = nsXPConnect::GetRuntimeInstance(); + XPCJSContext* self = nsXPConnect::GetContextInstance(); if (!self) return; @@ -722,14 +722,14 @@ XPCJSRuntime::GCSliceCallback(JSContext* cx, } /* static */ void -XPCJSRuntime::DoCycleCollectionCallback(JSContext* cx) +XPCJSContext::DoCycleCollectionCallback(JSContext* cx) { // The GC has detected that a CC at this point would collect a tremendous // amount of garbage that is being revivified unnecessarily. NS_DispatchToCurrentThread( NS_NewRunnableFunction([](){nsJSContext::CycleCollectNow(nullptr);})); - XPCJSRuntime* self = nsXPConnect::GetRuntimeInstance(); + XPCJSContext* self = nsXPConnect::GetContextInstance(); if (!self) return; @@ -738,7 +738,7 @@ XPCJSRuntime::DoCycleCollectionCallback(JSContext* cx) } void -XPCJSRuntime::CustomGCCallback(JSGCStatus status) +XPCJSContext::CustomGCCallback(JSGCStatus status) { nsTArray callbacks(extraGCCallbacks); for (uint32_t i = 0; i < callbacks.Length(); ++i) @@ -746,12 +746,12 @@ XPCJSRuntime::CustomGCCallback(JSGCStatus status) } /* static */ void -XPCJSRuntime::FinalizeCallback(JSFreeOp* fop, +XPCJSContext::FinalizeCallback(JSFreeOp* fop, JSFinalizeStatus status, bool isZoneGC, void* data) { - XPCJSRuntime* self = nsXPConnect::GetRuntimeInstance(); + XPCJSContext* self = nsXPConnect::GetContextInstance(); if (!self) return; @@ -810,7 +810,7 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp* fop, if (AutoMarkingPtr* roots = Get()->mAutoRoots) roots->MarkAfterJSFinalizeAll(); - XPCCallContext* ccxp = XPCJSRuntime::Get()->GetCallContext(); + XPCCallContext* ccxp = XPCJSContext::Get()->GetCallContext(); while (ccxp) { // Deal with the strictness of callcontext that // complains if you ask for a set when @@ -877,7 +877,7 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp* fop, if (!nsXPConnect::XPConnect()->IsShuttingDown()) { // Do the marking... - XPCCallContext* ccxp = XPCJSRuntime::Get()->GetCallContext(); + XPCCallContext* ccxp = XPCJSContext::Get()->GetCallContext(); while (ccxp) { // Deal with the strictness of callcontext that // complains if you ask for a tearoff when @@ -925,12 +925,12 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp* fop, } /* static */ void -XPCJSRuntime::WeakPointerZoneGroupCallback(JSContext* cx, void* data) +XPCJSContext::WeakPointerZoneGroupCallback(JSContext* cx, void* data) { // Called before each sweeping slice -- after processing any final marking // triggered by barriers -- to clear out any references to things that are // about to be finalized and update any pointers to moved GC things. - XPCJSRuntime* self = static_cast(data); + XPCJSContext* self = static_cast(data); self->mWrappedJSMap->UpdateWeakPointersAfterGC(self); @@ -938,20 +938,20 @@ XPCJSRuntime::WeakPointerZoneGroupCallback(JSContext* cx, void* data) } /* static */ void -XPCJSRuntime::WeakPointerCompartmentCallback(JSContext* cx, JSCompartment* comp, void* data) +XPCJSContext::WeakPointerCompartmentCallback(JSContext* cx, JSCompartment* comp, void* data) { // Called immediately after the ZoneGroup weak pointer callback, but only // once for each compartment that is being swept. - XPCJSRuntime* self = static_cast(data); + XPCJSContext* self = static_cast(data); CompartmentPrivate* xpcComp = CompartmentPrivate::Get(comp); if (xpcComp) xpcComp->UpdateWeakPointersAfterGC(self); } void -CompartmentPrivate::UpdateWeakPointersAfterGC(XPCJSRuntime* runtime) +CompartmentPrivate::UpdateWeakPointersAfterGC(XPCJSContext* context) { - mWrappedJSMap->UpdateWeakPointersAfterGC(runtime); + mWrappedJSMap->UpdateWeakPointersAfterGC(context); } static void WatchdogMain(void* arg); @@ -1104,12 +1104,12 @@ class WatchdogManager : public nsIObserver public: NS_DECL_ISUPPORTS - explicit WatchdogManager(XPCJSRuntime* aRuntime) : mRuntime(aRuntime) - , mRuntimeState(RUNTIME_INACTIVE) + explicit WatchdogManager(XPCJSContext* aContext) : mContext(aContext) + , mContextState(CONTEXT_INACTIVE) { - // All the timestamps start at zero except for runtime state change. + // All the timestamps start at zero except for context state change. PodArrayZero(mTimestamps); - mTimestamps[TimestampRuntimeStateChange] = PR_Now(); + mTimestamps[TimestampContextStateChange] = PR_Now(); // Enable the watchdog, if appropriate. RefreshWatchdog(); @@ -1142,11 +1142,11 @@ class WatchdogManager : public nsIObserver return NS_OK; } - // Runtime statistics. These live on the watchdog manager, are written + // Context statistics. These live on the watchdog manager, are written // from the main thread, and are read from the watchdog thread (holding // the lock in each case). void - RecordRuntimeActivity(bool active) + RecordContextActivity(bool active) { // The watchdog reads this state, so acquire the lock before writing it. MOZ_ASSERT(NS_IsMainThread()); @@ -1155,21 +1155,21 @@ class WatchdogManager : public nsIObserver lock.emplace(mWatchdog); // Write state. - mTimestamps[TimestampRuntimeStateChange] = PR_Now(); - mRuntimeState = active ? RUNTIME_ACTIVE : RUNTIME_INACTIVE; + mTimestamps[TimestampContextStateChange] = PR_Now(); + mContextState = active ? CONTEXT_ACTIVE : CONTEXT_INACTIVE; - // The watchdog may be hibernating, waiting for the runtime to go + // The watchdog may be hibernating, waiting for the context to go // active. Wake it up if necessary. if (active && mWatchdog && mWatchdog->Hibernating()) mWatchdog->WakeUp(); } - bool IsRuntimeActive() { return mRuntimeState == RUNTIME_ACTIVE; } - PRTime TimeSinceLastRuntimeStateChange() + bool IsContextActive() { return mContextState == CONTEXT_ACTIVE; } + PRTime TimeSinceLastContextStateChange() { - return PR_Now() - GetTimestamp(TimestampRuntimeStateChange); + return PR_Now() - GetTimestamp(TimestampContextStateChange); } - // Note - Because of the runtime activity timestamp, these are read and + // Note - Because of the context activity timestamp, these are read and // written from both threads. void RecordTimestamp(WatchdogTimestampCategory aCategory) { @@ -1188,7 +1188,7 @@ class WatchdogManager : public nsIObserver return mTimestamps[aCategory]; } - XPCJSRuntime* Runtime() { return mRuntime; } + XPCJSContext* Context() { return mContext; } Watchdog* GetWatchdog() { return mWatchdog; } void RefreshWatchdog() @@ -1227,10 +1227,10 @@ class WatchdogManager : public nsIObserver } private: - XPCJSRuntime* mRuntime; + XPCJSContext* mContext; nsAutoPtr mWatchdog; - enum { RUNTIME_ACTIVE, RUNTIME_INACTIVE } mRuntimeState; + enum { CONTEXT_ACTIVE, CONTEXT_INACTIVE } mContextState; PRTime mTimestamps[TimestampCount]; }; @@ -1261,8 +1261,8 @@ WatchdogMain(void* arg) MOZ_ASSERT(!self->ShuttingDown()); while (!self->ShuttingDown()) { // Sleep only 1 second if recently (or currently) active; otherwise, hibernate - if (manager->IsRuntimeActive() || - manager->TimeSinceLastRuntimeStateChange() <= PRTime(2*PR_USEC_PER_SEC)) + if (manager->IsContextActive() || + manager->TimeSinceLastContextStateChange() <= PRTime(2*PR_USEC_PER_SEC)) { self->Sleep(PR_TicksPerSecond()); } else { @@ -1289,15 +1289,15 @@ WatchdogMain(void* arg) // periods, the script still has the other (timeout/2) seconds to // finish. PRTime usecs = self->MinScriptRunTimeSeconds() * PR_USEC_PER_SEC / 2; - if (manager->IsRuntimeActive() && - manager->TimeSinceLastRuntimeStateChange() >= usecs) + if (manager->IsContextActive() && + manager->TimeSinceLastContextStateChange() >= usecs) { bool debuggerAttached = false; nsCOMPtr dbg = do_GetService("@mozilla.org/xpcom/debug;1"); if (dbg) dbg->GetIsDebuggerAttached(&debuggerAttached); if (!debuggerAttached) - JS_RequestInterruptCallback(manager->Runtime()->Context()); + JS_RequestInterruptCallback(manager->Context()->Context()); } } @@ -1306,7 +1306,7 @@ WatchdogMain(void* arg) } PRTime -XPCJSRuntime::GetWatchdogTimestamp(WatchdogTimestampCategory aCategory) +XPCJSContext::GetWatchdogTimestamp(WatchdogTimestampCategory aCategory) { return mWatchdogManager->GetTimestamp(aCategory); } @@ -1314,26 +1314,26 @@ XPCJSRuntime::GetWatchdogTimestamp(WatchdogTimestampCategory aCategory) void xpc::SimulateActivityCallback(bool aActive) { - XPCJSRuntime::ActivityCallback(XPCJSRuntime::Get(), aActive); + XPCJSContext::ActivityCallback(XPCJSContext::Get(), aActive); } // static void -XPCJSRuntime::ActivityCallback(void* arg, bool active) +XPCJSContext::ActivityCallback(void* arg, bool active) { if (!active) { ProcessHangMonitor::ClearHang(); } - XPCJSRuntime* self = static_cast(arg); - self->mWatchdogManager->RecordRuntimeActivity(active); + XPCJSContext* self = static_cast(arg); + self->mWatchdogManager->RecordContextActivity(active); } // static bool -XPCJSRuntime::InterruptCallback(JSContext* cx) +XPCJSContext::InterruptCallback(JSContext* cx) { - XPCJSRuntime* self = XPCJSRuntime::Get(); + XPCJSContext* self = XPCJSContext::Get(); // Normally we record mSlowScriptCheckpoint when we start to process an // event. However, we can run JS outside of event handlers. This code takes @@ -1438,7 +1438,7 @@ XPCJSRuntime::InterruptCallback(JSContext* cx) } void -XPCJSRuntime::CustomOutOfMemoryCallback() +XPCJSContext::CustomOutOfMemoryCallback() { if (!Preferences::GetBool("memory.dump_reports_on_oom")) { return; @@ -1457,7 +1457,7 @@ XPCJSRuntime::CustomOutOfMemoryCallback() } void -XPCJSRuntime::CustomLargeAllocationFailureCallback() +XPCJSContext::CustomLargeAllocationFailureCallback() { nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { @@ -1466,7 +1466,7 @@ XPCJSRuntime::CustomLargeAllocationFailureCallback() } size_t -XPCJSRuntime::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) +XPCJSContext::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) { size_t n = 0; n += mallocSizeOf(this); @@ -1477,7 +1477,7 @@ XPCJSRuntime::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) n += CycleCollectedJSContext::SizeOfExcludingThis(mallocSizeOf); - // There are other XPCJSRuntime members that could be measured; the above + // There are other XPCJSContext members that could be measured; the above // ones have been seen by DMD to be worth measuring. More stuff may be // added later. @@ -1495,7 +1495,7 @@ CompartmentPrivate::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) /***************************************************************************/ -void XPCJSRuntime::SystemIsBeingShutDown() +void XPCJSContext::SystemIsBeingShutDown() { for (auto i = mDetachedWrappedNativeProtoMap->Iter(); !i.Done(); i.Next()) { auto entry = static_cast(i.Get()); @@ -1509,8 +1509,8 @@ void XPCJSRuntime::SystemIsBeingShutDown() static void ReloadPrefsCallback(const char* pref, void* data) { - XPCJSRuntime* runtime = reinterpret_cast(data); - JSContext* cx = runtime->Context(); + XPCJSContext* xpccx = reinterpret_cast(data); + JSContext* cx = xpccx->Context(); bool safeMode = false; nsCOMPtr xr = do_GetService("@mozilla.org/xre/runtime;1"); @@ -1585,9 +1585,9 @@ ReloadPrefsCallback(const char* pref, void* data) useIonEager ? 0 : -1); } -XPCJSRuntime::~XPCJSRuntime() +XPCJSContext::~XPCJSContext() { - // Elsewhere we abort immediately if XPCJSRuntime initialization fails. + // Elsewhere we abort immediately if XPCJSContext initialization fails. // Therefore the context must be non-null. MOZ_ASSERT(MaybeContext()); @@ -1648,7 +1648,7 @@ XPCJSRuntime::~XPCJSRuntime() mDetachedWrappedNativeProtoMap = nullptr; #ifdef MOZ_ENABLE_PROFILER_SPS - // Tell the profiler that the runtime is gone + // Tell the profiler that the context is gone if (PseudoStack* stack = mozilla_get_pseudo_stack()) stack->sampleContext(nullptr); #endif @@ -1756,13 +1756,13 @@ xpc::GetCurrentCompartmentName(JSContext* cx, nsCString& name) void xpc::AddGCCallback(xpcGCCallback cb) { - XPCJSRuntime::Get()->AddGCCallback(cb); + XPCJSContext::Get()->AddGCCallback(cb); } void xpc::RemoveGCCallback(xpcGCCallback cb) { - XPCJSRuntime::Get()->RemoveGCCallback(cb); + XPCJSContext::Get()->RemoveGCCallback(cb); } static int64_t @@ -1790,7 +1790,7 @@ JSMainRuntimeCompartmentsSystemDistinguishedAmount() static int64_t JSMainRuntimeCompartmentsUserDistinguishedAmount() { - JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context(); + JSContext* cx = nsXPConnect::GetContextInstance()->Context(); return JS::UserCompartmentCount(cx); } @@ -2645,7 +2645,7 @@ class JSMainRuntimeCompartmentsReporter final : public nsIMemoryReporter Data d; d.anonymizeID = anonymize ? 1 : 0; - JS_IterateCompartments(nsXPConnect::GetRuntimeInstance()->Context(), + JS_IterateCompartments(nsXPConnect::GetContextInstance()->Context(), &d, CompartmentCallback); for (size_t i = 0; i < d.paths.length(); i++) @@ -2718,7 +2718,7 @@ StartsWithExplicit(nsACString& s) } #endif -class XPCJSRuntimeStats : public JS::RuntimeStats +class XPCJSContextStats : public JS::RuntimeStats { WindowPaths* mWindowPaths; WindowPaths* mTopWindowPaths; @@ -2726,7 +2726,7 @@ class XPCJSRuntimeStats : public JS::RuntimeStats int mAnonymizeID; public: - XPCJSRuntimeStats(WindowPaths* windowPaths, WindowPaths* topWindowPaths, + XPCJSContextStats(WindowPaths* windowPaths, WindowPaths* topWindowPaths, bool getLocations, bool anonymize) : JS::RuntimeStats(JSMallocSizeOf), mWindowPaths(windowPaths), @@ -2735,7 +2735,7 @@ class XPCJSRuntimeStats : public JS::RuntimeStats mAnonymizeID(anonymize ? 1 : 0) {} - ~XPCJSRuntimeStats() { + ~XPCJSContextStats() { for (size_t i = 0; i != compartmentStatsVector.length(); ++i) delete static_cast(compartmentStatsVector[i].extra); @@ -2853,7 +2853,7 @@ JSReporter::CollectReports(WindowPaths* windowPaths, nsISupports* data, bool anonymize) { - XPCJSRuntime* xpcrt = nsXPConnect::GetRuntimeInstance(); + XPCJSContext* xpccx = nsXPConnect::GetContextInstance(); // In the first step we get all the stats and stash them in a local // data structure. In the second step we pass all the stashed stats to @@ -2867,18 +2867,18 @@ JSReporter::CollectReports(WindowPaths* windowPaths, addonManager = do_GetService("@mozilla.org/addons/integration;1"); } bool getLocations = !!addonManager; - XPCJSRuntimeStats rtStats(windowPaths, topWindowPaths, getLocations, + XPCJSContextStats rtStats(windowPaths, topWindowPaths, getLocations, anonymize); OrphanReporter orphanReporter(XPCConvert::GetISupportsFromJSObject); - if (!JS::CollectRuntimeStats(xpcrt->Context(), &rtStats, &orphanReporter, + if (!JS::CollectRuntimeStats(xpccx->Context(), &rtStats, &orphanReporter, anonymize)) { return; } - size_t xpcJSRuntimeSize = xpcrt->SizeOfIncludingThis(JSMallocSizeOf); + size_t xpcJSRuntimeSize = xpccx->SizeOfIncludingThis(JSMallocSizeOf); - size_t wrappedJSSize = xpcrt->GetMultiCompartmentWrappedJSMap()->SizeOfWrappedJS(JSMallocSizeOf); + size_t wrappedJSSize = xpccx->GetMultiCompartmentWrappedJSMap()->SizeOfWrappedJS(JSMallocSizeOf); XPCWrappedNativeScope::ScopeSizeInfo sizeInfo(JSMallocSizeOf); XPCWrappedNativeScope::AddSizeOfAllScopesIncludingThis(&sizeInfo); @@ -3056,7 +3056,7 @@ static nsresult JSSizeOfTab(JSObject* objArg, size_t* jsObjectsSize, size_t* jsStringsSize, size_t* jsPrivateSize, size_t* jsOtherSize) { - JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context(); + JSContext* cx = nsXPConnect::GetContextInstance()->Context(); JS::RootedObject obj(cx, objArg); TabSizes sizes; @@ -3277,7 +3277,7 @@ ReadSourceFromFilename(JSContext* cx, const char* filename, char16_t** src, size } // The JS engine calls this object's 'load' member function when it needs -// the source for a chrome JS function. See the comment in the XPCJSRuntime +// the source for a chrome JS function. See the comment in the XPCJSContext // constructor. class XPCJSSourceHook: public js::SourceHook { bool load(JSContext* cx, const char* filename, char16_t** src, size_t* length) { @@ -3305,7 +3305,7 @@ static const JSWrapObjectCallbacks WrapObjectCallbacks = { xpc::WrapperFactory::PrepareForWrapping }; -XPCJSRuntime::XPCJSRuntime() +XPCJSContext::XPCJSContext() : mCallContext(nullptr), mAutoRoots(nullptr), mResolveName(JSID_VOID), @@ -3369,7 +3369,7 @@ GetWindowsStackSize() #endif nsresult -XPCJSRuntime::Initialize() +XPCJSContext::Initialize() { nsresult rv = CycleCollectedJSContext::Initialize(nullptr, JS::DefaultHeapMaxBytes, @@ -3539,13 +3539,13 @@ XPCJSRuntime::Initialize() } // static -XPCJSRuntime* -XPCJSRuntime::newXPCJSRuntime() +XPCJSContext* +XPCJSContext::newXPCJSContext() { - XPCJSRuntime* self = new XPCJSRuntime(); + XPCJSContext* self = new XPCJSContext(); nsresult rv = self->Initialize(); if (NS_FAILED(rv)) { - NS_RUNTIMEABORT("new XPCJSRuntime failed to initialize."); + NS_RUNTIMEABORT("new XPCJSContext failed to initialize."); delete self; return nullptr; } @@ -3563,14 +3563,14 @@ XPCJSRuntime::newXPCJSRuntime() return self; } - NS_RUNTIMEABORT("new XPCJSRuntime failed to initialize."); + NS_RUNTIMEABORT("new XPCJSContext failed to initialize."); delete self; return nullptr; } bool -XPCJSRuntime::JSContextInitialized(JSContext* cx) +XPCJSContext::JSContextInitialized(JSContext* cx) { JSAutoRequest ar(cx); @@ -3596,7 +3596,7 @@ XPCJSRuntime::JSContextInitialized(JSContext* cx) } bool -XPCJSRuntime::DescribeCustomObjects(JSObject* obj, const js::Class* clasp, +XPCJSContext::DescribeCustomObjects(JSObject* obj, const js::Class* clasp, char (&name)[72]) const { XPCNativeScriptableInfo* si = nullptr; @@ -3618,7 +3618,7 @@ XPCJSRuntime::DescribeCustomObjects(JSObject* obj, const js::Class* clasp, } bool -XPCJSRuntime::NoteCustomGCThingXPCOMChildren(const js::Class* clasp, JSObject* obj, +XPCJSContext::NoteCustomGCThingXPCOMChildren(const js::Class* clasp, JSObject* obj, nsCycleCollectionTraversalCallback& cb) const { if (clasp != &XPC_WN_Tearoff_JSClass) { @@ -3636,7 +3636,7 @@ XPCJSRuntime::NoteCustomGCThingXPCOMChildren(const js::Class* clasp, JSObject* o } void -XPCJSRuntime::BeforeProcessTask(bool aMightBlock) +XPCJSContext::BeforeProcessTask(bool aMightBlock) { MOZ_ASSERT(NS_IsMainThread()); @@ -3669,7 +3669,7 @@ XPCJSRuntime::BeforeProcessTask(bool aMightBlock) } void -XPCJSRuntime::AfterProcessTask(uint32_t aNewRecursionDepth) +XPCJSContext::AfterProcessTask(uint32_t aNewRecursionDepth) { // Now that we're back to the event loop, reset the slow script checkpoint. mSlowScriptCheckpoint = mozilla::TimeStamp(); @@ -3689,11 +3689,11 @@ XPCJSRuntime::AfterProcessTask(uint32_t aNewRecursionDepth) /***************************************************************************/ void -XPCJSRuntime::DebugDump(int16_t depth) +XPCJSContext::DebugDump(int16_t depth) { #ifdef DEBUG depth--; - XPC_LOG_ALWAYS(("XPCJSRuntime @ %x", this)); + XPC_LOG_ALWAYS(("XPCJSContext @ %x", this)); XPC_LOG_INDENT(); XPC_LOG_ALWAYS(("mJSContext @ %x", Context())); @@ -3768,7 +3768,7 @@ void XPCRootSetElem::RemoveFromRootSet() { nsXPConnect* xpc = nsXPConnect::XPConnect(); - JS::PokeGC(xpc->GetRuntime()->Context()); + JS::PokeGC(xpc->GetContext()->Context()); MOZ_ASSERT(mSelfp, "Must be linked"); @@ -3783,14 +3783,14 @@ XPCRootSetElem::RemoveFromRootSet() } void -XPCJSRuntime::AddGCCallback(xpcGCCallback cb) +XPCJSContext::AddGCCallback(xpcGCCallback cb) { MOZ_ASSERT(cb, "null callback"); extraGCCallbacks.AppendElement(cb); } void -XPCJSRuntime::RemoveGCCallback(xpcGCCallback cb) +XPCJSContext::RemoveGCCallback(xpcGCCallback cb) { MOZ_ASSERT(cb, "null callback"); bool found = extraGCCallbacks.RemoveElement(cb); @@ -3800,7 +3800,7 @@ XPCJSRuntime::RemoveGCCallback(xpcGCCallback cb) } void -XPCJSRuntime::InitSingletonScopes() +XPCJSContext::InitSingletonScopes() { // This all happens very early, so we don't bother with cx pushing. JSContext* cx = Context(); @@ -3836,7 +3836,7 @@ XPCJSRuntime::InitSingletonScopes() } void -XPCJSRuntime::DeleteSingletonScopes() +XPCJSContext::DeleteSingletonScopes() { mUnprivilegedJunkScope = nullptr; mPrivilegedJunkScope = nullptr; diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index e4252f7a804fa..2b2a7c1d3dd7c 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -710,12 +710,12 @@ nsJSCID::Construct(nsIXPConnectWrappedNative* wrapper, const CallArgs& args, bool* _retval) { RootedObject obj(cx, objArg); - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - if (!rt) + XPCJSContext* xpccx = nsXPConnect::GetContextInstance(); + if (!xpccx) return NS_ERROR_FAILURE; // 'push' a call context and call on it - RootedId name(cx, rt->GetStringID(XPCJSRuntime::IDX_CREATE_INSTANCE)); + RootedId name(cx, xpccx->GetStringID(XPCJSContext::IDX_CREATE_INSTANCE)); XPCCallContext ccx(cx, obj, nullptr, name, args.length(), args.array(), args.rval().address()); diff --git a/js/xpconnect/src/XPCMaps.cpp b/js/xpconnect/src/XPCMaps.cpp index 626784f810cfa..7f44648f0f9bb 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -43,7 +43,7 @@ HashNativeKey(const void* data) // implement JSObject2WrappedJSMap... void -JSObject2WrappedJSMap::UpdateWeakPointersAfterGC(XPCJSRuntime* runtime) +JSObject2WrappedJSMap::UpdateWeakPointersAfterGC(XPCJSContext* context) { // Check all wrappers and update their JSObject pointer if it has been // moved. Release any wrappers whose weakly held JSObject has died. diff --git a/js/xpconnect/src/XPCMaps.h b/js/xpconnect/src/XPCMaps.h index c25a8876f8c3c..41f2fc8a73bd4 100644 --- a/js/xpconnect/src/XPCMaps.h +++ b/js/xpconnect/src/XPCMaps.h @@ -83,7 +83,7 @@ class JSObject2WrappedJSMap r.front().value()->DebugDump(depth); } - void UpdateWeakPointersAfterGC(XPCJSRuntime* runtime); + void UpdateWeakPointersAfterGC(XPCJSContext* context); void ShutdownMarker(); @@ -314,7 +314,7 @@ class ClassInfo2NativeSetMap // ClassInfo2NativeSetMap holds pointers to *some* XPCNativeSets. // So we don't want to count those XPCNativeSets, because they are better - // counted elsewhere (i.e. in XPCJSRuntime::mNativeSetMap, which holds + // counted elsewhere (i.e. in XPCJSContext::mNativeSetMap, which holds // pointers to *all* XPCNativeSets). Hence the "Shallow". size_t ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf); diff --git a/js/xpconnect/src/XPCThrower.cpp b/js/xpconnect/src/XPCThrower.cpp index d67c8dab9ea61..ad479b4e3eb81 100644 --- a/js/xpconnect/src/XPCThrower.cpp +++ b/js/xpconnect/src/XPCThrower.cpp @@ -50,10 +50,10 @@ Throw(JSContext* cx, nsresult rv) bool XPCThrower::CheckForPendingException(nsresult result, JSContext* cx) { - nsCOMPtr e = XPCJSRuntime::Get()->GetPendingException(); + nsCOMPtr e = XPCJSContext::Get()->GetPendingException(); if (!e) return false; - XPCJSRuntime::Get()->SetPendingException(nullptr); + XPCJSContext::Get()->SetPendingException(nullptr); nsresult e_result; if (NS_FAILED(e->GetResult(&e_result)) || e_result != result) diff --git a/js/xpconnect/src/XPCWrappedJS.cpp b/js/xpconnect/src/XPCWrappedJS.cpp index 302068c771563..dbcb3e9d2c9ea 100644 --- a/js/xpconnect/src/XPCWrappedJS.cpp +++ b/js/xpconnect/src/XPCWrappedJS.cpp @@ -41,7 +41,7 @@ using namespace mozilla; // now owned exclusively by its JS object. Either a weak reference will be turned into // a strong ref which will bring its refcount up to 2 and change the wrapper back to // the rooting state, or it will stay alive until the JS object dies. If the JS object -// dies, then when XPCJSRuntime::FinalizeCallback calls FindDyingJSObjects +// dies, then when XPCJSContext::FinalizeCallback calls FindDyingJSObjects // it will find the wrapper and call Release() in it, destroying the wrapper. // Otherwise, the wrapper will stay alive, even if it no longer has a weak reference // to it. @@ -143,7 +143,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXPCWrappedJS) tmp->Unlink(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END -// XPCJSRuntime keeps a table of WJS, so we can remove them from +// XPCJSContext keeps a table of WJS, so we can remove them from // the purple buffer in between CCs. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsXPCWrappedJS) return true; @@ -249,7 +249,7 @@ nsXPCWrappedJS::AddRef(void) if (2 == cnt && IsValid()) { GetJSObject(); // Unmark gray JSObject. - mClass->GetRuntime()->AddWrappedJSRoot(this); + mClass->GetContext()->AddWrappedJSRoot(this); } return cnt; @@ -350,10 +350,10 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj, // Find any existing wrapper. RefPtr root = rootComp->GetWrappedJSMap()->Find(rootJSObj); - MOZ_ASSERT_IF(root, !nsXPConnect::GetRuntimeInstance()->GetMultiCompartmentWrappedJSMap()-> + MOZ_ASSERT_IF(root, !nsXPConnect::GetContextInstance()->GetMultiCompartmentWrappedJSMap()-> Find(rootJSObj)); if (!root) { - root = nsXPConnect::GetRuntimeInstance()->GetMultiCompartmentWrappedJSMap()-> + root = nsXPConnect::GetContextInstance()->GetMultiCompartmentWrappedJSMap()-> Find(rootJSObj); } @@ -417,10 +417,10 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx, // We always start wrappers in the per-compartment table. If adding // this wrapper to the chain causes it to cross compartments, we need - // to migrate the chain to the global table on the XPCJSRuntime. + // to migrate the chain to the global table on the XPCJSContext. if (mRoot->IsMultiCompartment()) { xpc::CompartmentPrivate::Get(mRoot->mJSObj)->GetWrappedJSMap()->Remove(mRoot); - MOZ_RELEASE_ASSERT(nsXPConnect::GetRuntimeInstance()-> + MOZ_RELEASE_ASSERT(nsXPConnect::GetContextInstance()-> GetMultiCompartmentWrappedJSMap()->Add(cx, mRoot)); } } @@ -432,7 +432,7 @@ nsXPCWrappedJS::~nsXPCWrappedJS() } void -XPCJSRuntime::RemoveWrappedJS(nsXPCWrappedJS* wrapper) +XPCJSContext::RemoveWrappedJS(nsXPCWrappedJS* wrapper) { AssertInvalidWrappedJSNotInTable(wrapper); if (!wrapper->IsValid()) @@ -465,7 +465,7 @@ NotHasWrapperAssertionCallback(JSContext* cx, void* data, JSCompartment* comp) #endif void -XPCJSRuntime::AssertInvalidWrappedJSNotInTable(nsXPCWrappedJS* wrapper) const +XPCJSContext::AssertInvalidWrappedJSNotInTable(nsXPCWrappedJS* wrapper) const { #ifdef DEBUG if (!wrapper->IsValid()) { @@ -482,20 +482,20 @@ nsXPCWrappedJS::Destroy() MOZ_ASSERT(1 == int32_t(mRefCnt), "should be stabilized for deletion"); if (IsRootWrapper()) - nsXPConnect::GetRuntimeInstance()->RemoveWrappedJS(this); + nsXPConnect::GetContextInstance()->RemoveWrappedJS(this); Unlink(); } void nsXPCWrappedJS::Unlink() { - nsXPConnect::GetRuntimeInstance()->AssertInvalidWrappedJSNotInTable(this); + nsXPConnect::GetContextInstance()->AssertInvalidWrappedJSNotInTable(this); if (IsValid()) { - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - if (rt) { + XPCJSContext* cx = nsXPConnect::GetContextInstance(); + if (cx) { if (IsRootWrapper()) - rt->RemoveWrappedJS(this); + cx->RemoveWrappedJS(this); if (mRefCnt > 1) RemoveFromRootSet(); @@ -530,8 +530,8 @@ nsXPCWrappedJS::Unlink() mClass = nullptr; if (mOuter) { - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - if (rt->GCIsRunning()) { + XPCJSContext* cx = nsXPConnect::GetContextInstance(); + if (cx->GCIsRunning()) { DeferredFinalize(mOuter.forget().take()); } else { mOuter = nullptr; diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index e19c195539e6d..3fe8524d99526 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -82,22 +82,22 @@ bool xpc_IsReportableErrorCode(nsresult code) } } -// A little stack-based RAII class to help management of the XPCJSRuntime +// A little stack-based RAII class to help management of the XPCJSContext // PendingResult. class MOZ_STACK_CLASS AutoSavePendingResult { public: - explicit AutoSavePendingResult(XPCJSRuntime* xpcrt) : - mXPCRuntime(xpcrt) + explicit AutoSavePendingResult(XPCJSContext* xpccx) : + mXPCContext(xpccx) { // Save any existing pending result and reset to NS_OK for this invocation. - mSavedResult = xpcrt->GetPendingResult(); - xpcrt->SetPendingResult(NS_OK); + mSavedResult = xpccx->GetPendingResult(); + xpccx->SetPendingResult(NS_OK); } ~AutoSavePendingResult() { - mXPCRuntime->SetPendingResult(mSavedResult); + mXPCContext->SetPendingResult(mSavedResult); } private: - XPCJSRuntime* mXPCRuntime; + XPCJSContext* mXPCContext; nsresult mSavedResult; }; @@ -105,8 +105,8 @@ class MOZ_STACK_CLASS AutoSavePendingResult { already_AddRefed nsXPCWrappedJSClass::GetNewOrUsed(JSContext* cx, REFNSIID aIID, bool allowNonScriptable) { - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - IID2WrappedJSClassMap* map = rt->GetWrappedJSClassMap(); + XPCJSContext* xpccx = nsXPConnect::GetContextInstance(); + IID2WrappedJSClassMap* map = xpccx->GetWrappedJSClassMap(); RefPtr clasp = map->Find(aIID); if (!clasp) { @@ -129,13 +129,13 @@ nsXPCWrappedJSClass::GetNewOrUsed(JSContext* cx, REFNSIID aIID, bool allowNonScr nsXPCWrappedJSClass::nsXPCWrappedJSClass(JSContext* cx, REFNSIID aIID, nsIInterfaceInfo* aInfo) - : mRuntime(nsXPConnect::GetRuntimeInstance()), + : mContext(nsXPConnect::GetContextInstance()), mInfo(aInfo), mName(nullptr), mIID(aIID), mDescriptors(nullptr) { - mRuntime->GetWrappedJSClassMap()->Add(this); + mContext->GetWrappedJSClassMap()->Add(this); uint16_t methodCount; if (NS_SUCCEEDED(mInfo->GetMethodCount(&methodCount))) { @@ -168,8 +168,8 @@ nsXPCWrappedJSClass::~nsXPCWrappedJSClass() { if (mDescriptors && mDescriptors != &zero_methods_descriptor) delete [] mDescriptors; - if (mRuntime) - mRuntime->GetWrappedJSClassMap()->Remove(this); + if (mContext) + mContext->GetWrappedJSClassMap()->Remove(this); if (mName) free(mName); @@ -209,7 +209,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx, return nullptr; // check upfront for the existence of the function property - HandleId funid = mRuntime->GetStringID(XPCJSRuntime::IDX_QUERY_INTERFACE); + HandleId funid = mContext->GetStringID(XPCJSContext::IDX_QUERY_INTERFACE); if (!JS_GetPropertyById(cx, jsobj, funid, &fun) || fun.isPrimitive()) return nullptr; @@ -778,11 +778,11 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx, nsCOMPtr xpc_exception = aSyntheticException; /* this one would be set by our error reporter */ - XPCJSRuntime* xpcrt = XPCJSRuntime::Get(); + XPCJSContext* xpccx = XPCJSContext::Get(); // Get this right away in case we do something below to cause JS code // to run. - nsresult pending_result = xpcrt->GetPendingResult(); + nsresult pending_result = xpccx->GetPendingResult(); RootedValue js_exception(cx); bool is_js_exception = JS_GetPendingException(cx, &js_exception); @@ -796,7 +796,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx, /* cleanup and set failed even if we can't build an exception */ if (!xpc_exception) { - xpcrt->SetPendingException(nullptr); // XXX necessary? + xpccx->SetPendingException(nullptr); // XXX necessary? } } @@ -915,7 +915,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx, // Whether or not it passes the 'reportable' test, it might // still be an error and we have to do the right thing here... if (NS_FAILED(e_result)) { - xpcrt->SetPendingException(xpc_exception); + xpccx->SetPendingException(xpc_exception); return e_result; } } @@ -985,8 +985,8 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, AutoValueVector args(cx); AutoScriptEvaluate scriptEval(cx); - XPCJSRuntime* xpcrt = XPCJSRuntime::Get(); - AutoSavePendingResult apr(xpcrt); + XPCJSContext* xpccx = XPCJSContext::Get(); + AutoSavePendingResult apr(xpccx); // XXX ASSUMES that retval is last arg. The xpidl compiler ensures this. uint8_t paramCount = info->num_args; @@ -996,7 +996,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, if (!scriptEval.StartEvaluating(obj)) goto pre_call_clean_up; - xpcrt->SetPendingException(nullptr); + xpccx->SetPendingException(nullptr); // We use js_Invoke so that the gcthings we use as args will be rooted by // the engine as we do conversions and prepare to do the function call. @@ -1042,7 +1042,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, nsIXPCFunctionThisTranslator* translator; IID2ThisTranslatorMap* map = - mRuntime->GetThisTranslatorMap(); + mContext->GetThisTranslatorMap(); translator = map->Find(mIID); @@ -1173,7 +1173,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, if (param.IsIn()) { if (!JS_SetPropertyById(cx, out_obj, - mRuntime->GetStringID(XPCJSRuntime::IDX_VALUE), + mContext->GetStringID(XPCJSContext::IDX_VALUE), val)) { goto pre_call_clean_up; } @@ -1235,7 +1235,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, return CheckForException(ccx, aes, name, GetInterfaceName(), syntheticException); - XPCJSRuntime::Get()->SetPendingException(nullptr); // XXX necessary? + XPCJSContext::Get()->SetPendingException(nullptr); // XXX necessary? // convert out args and result // NOTE: this is the total number of native params, not just the args @@ -1273,7 +1273,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, else { RootedObject obj(cx, &argv[i].toObject()); if (!JS_GetPropertyById(cx, obj, - mRuntime->GetStringID(XPCJSRuntime::IDX_VALUE), + mContext->GetStringID(XPCJSContext::IDX_VALUE), &val)) break; } @@ -1320,7 +1320,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, else { RootedObject obj(cx, &argv[i].toObject()); if (!JS_GetPropertyById(cx, obj, - mRuntime->GetStringID(XPCJSRuntime::IDX_VALUE), + mContext->GetStringID(XPCJSContext::IDX_VALUE), &val)) break; } @@ -1373,7 +1373,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, CleanupOutparams(cx, methodIndex, info, nativeParams, /* inOutOnly = */ false, i); } else { // set to whatever the JS code might have set as the result - retval = xpcrt->GetPendingResult(); + retval = xpccx->GetPendingResult(); } return retval; @@ -1436,7 +1436,7 @@ nsXPCWrappedJSClass::DebugDump(int16_t depth) XPC_LOG_ALWAYS(("ConstantCount = %d", i)); XPC_LOG_OUTDENT(); } - XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime)); + XPC_LOG_ALWAYS(("mContext @ %x", mContext)); XPC_LOG_ALWAYS(("mDescriptors @ %x count = %d", mDescriptors, methodCount)); if (depth && mDescriptors && methodCount) { depth--; diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 94262ba66aeb5..7cdb128625d64 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -300,7 +300,7 @@ XPCWrappedNative::GetNewOrUsed(xpcObjectHelper& helper, nsresult rv; - MOZ_ASSERT(!Scope->GetRuntime()->GCIsRunning(), + MOZ_ASSERT(!Scope->GetContext()->GCIsRunning(), "XPCWrappedNative::GetNewOrUsed called during GC"); nsISupports* identity = helper.GetCanonical(); @@ -608,8 +608,8 @@ XPCWrappedNative::Destroy() } if (mIdentity) { - XPCJSRuntime* rt = GetRuntime(); - if (rt && rt->GetDoingFinalization()) { + XPCJSContext* cx = GetContext(); + if (cx && cx->GetDoingFinalization()) { DeferredFinalize(mIdentity.forget().take()); } else { mIdentity = nullptr; @@ -634,7 +634,7 @@ XPCWrappedNative::SetProto(XPCWrappedNativeProto* p) MOZ_ASSERT(HasProto()); // Write barrier for incremental GC. - JSContext* cx = GetRuntime()->Context(); + JSContext* cx = GetContext()->Context(); GetProto()->WriteBarrierPre(cx); mMaybeProto = p; @@ -903,7 +903,7 @@ XPCWrappedNative::FlatJSObjectFinalized() // We also need to release any native pointers held... RefPtr native = to->TakeNative(); - if (native && GetRuntime()) { + if (native && GetContext()) { DeferredFinalize(native.forget().take()); } @@ -1321,7 +1321,7 @@ class MOZ_STACK_CLASS CallMethodHelper , mMethodInfo(nullptr) , mCallee(ccx.GetTearOff()->GetNative()) , mVTableIndex(ccx.GetMethodIndex()) - , mIdxValueId(ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_VALUE)) + , mIdxValueId(ccx.GetContext()->GetStringID(XPCJSContext::IDX_VALUE)) , mJSContextIndex(UINT8_MAX) , mOptArgcIndex(UINT8_MAX) , mArgv(ccx.GetArgv()) @@ -1356,7 +1356,7 @@ CallMethodHelper::Call() { mCallContext.SetRetVal(JS::UndefinedValue()); - XPCJSRuntime::Get()->SetPendingException(nullptr); + XPCJSContext::Get()->SetPendingException(nullptr); if (mVTableIndex == 0) { return QueryInterfaceFastPath(); @@ -2010,11 +2010,11 @@ CallMethodHelper::CleanupParam(nsXPTCMiniVariant& param, nsXPTType& type) break; case nsXPTType::T_ASTRING: case nsXPTType::T_DOMSTRING: - nsXPConnect::GetRuntimeInstance()->mScratchStrings.Destroy((nsString*)param.val.p); + nsXPConnect::GetContextInstance()->mScratchStrings.Destroy((nsString*)param.val.p); break; case nsXPTType::T_UTF8STRING: case nsXPTType::T_CSTRING: - nsXPConnect::GetRuntimeInstance()->mScratchCStrings.Destroy((nsCString*)param.val.p); + nsXPConnect::GetContextInstance()->mScratchCStrings.Destroy((nsCString*)param.val.p); break; default: MOZ_ASSERT(!type.IsArithmetic(), "Cleanup requested on unexpected type."); @@ -2040,9 +2040,9 @@ CallMethodHelper::AllocateStringClass(nsXPTCVariant* dp, // ASTRING and DOMSTRING are very similar, and both use nsString. // UTF8_STRING and CSTRING are also quite similar, and both use nsCString. if (type_tag == nsXPTType::T_ASTRING || type_tag == nsXPTType::T_DOMSTRING) - dp->val.p = nsXPConnect::GetRuntimeInstance()->mScratchStrings.Create(); + dp->val.p = nsXPConnect::GetContextInstance()->mScratchStrings.Create(); else - dp->val.p = nsXPConnect::GetRuntimeInstance()->mScratchCStrings.Create(); + dp->val.p = nsXPConnect::GetContextInstance()->mScratchCStrings.Create(); // Check for OOM, in either case. if (!dp->val.p) { @@ -2317,7 +2317,7 @@ XPCJSObjectHolder::XPCJSObjectHolder(JSObject* obj) : mJSObj(obj) { MOZ_ASSERT(obj); - XPCJSRuntime::Get()->AddObjectHolderRoot(this); + XPCJSContext::Get()->AddObjectHolderRoot(this); } XPCJSObjectHolder::~XPCJSObjectHolder() diff --git a/js/xpconnect/src/XPCWrappedNativeInfo.cpp b/js/xpconnect/src/XPCWrappedNativeInfo.cpp index 3ea5f1969babf..2e08f3d04a772 100644 --- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp +++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp @@ -109,7 +109,7 @@ XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface, XPCNativeInterface::~XPCNativeInterface() { - XPCJSRuntime::Get()->GetIID2NativeInterfaceMap()->Remove(this); + XPCJSContext::Get()->GetIID2NativeInterfaceMap()->Remove(this); } // static @@ -117,9 +117,9 @@ already_AddRefed XPCNativeInterface::GetNewOrUsed(const nsIID* iid) { RefPtr iface; - XPCJSRuntime* rt = XPCJSRuntime::Get(); + XPCJSContext* cx = XPCJSContext::Get(); - IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap(); + IID2NativeInterfaceMap* map = cx->GetIID2NativeInterfaceMap(); if (!map) return nullptr; @@ -158,9 +158,9 @@ XPCNativeInterface::GetNewOrUsed(nsIInterfaceInfo* info) if (NS_FAILED(info->GetIIDShared(&iid)) || !iid) return nullptr; - XPCJSRuntime* rt = XPCJSRuntime::Get(); + XPCJSContext* cx = XPCJSContext::Get(); - IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap(); + IID2NativeInterfaceMap* map = cx->GetIID2NativeInterfaceMap(); if (!map) return nullptr; @@ -476,8 +476,8 @@ XPCNativeSet::GetNewOrUsed(const nsIID* iid) XPCNativeSetKey key(iface); - XPCJSRuntime* rt = XPCJSRuntime::Get(); - NativeSetMap* map = rt->GetNativeSetMap(); + XPCJSContext* xpccx = XPCJSContext::Get(); + NativeSetMap* map = xpccx->GetNativeSetMap(); if (!map) return nullptr; @@ -505,9 +505,9 @@ XPCNativeSet::GetNewOrUsed(nsIClassInfo* classInfo) { AutoJSContext cx; AutoMarkingNativeSetPtr set(cx); - XPCJSRuntime* rt = XPCJSRuntime::Get(); + XPCJSContext* xpccx = XPCJSContext::Get(); - ClassInfo2NativeSetMap* map = rt->GetClassInfo2NativeSetMap(); + ClassInfo2NativeSetMap* map = xpccx->GetClassInfo2NativeSetMap(); if (!map) return nullptr; @@ -558,7 +558,7 @@ XPCNativeSet::GetNewOrUsed(nsIClassInfo* classInfo) if (interfaceArray.Length() > 0) { set = NewInstance(Move(interfaceArray)); if (set) { - NativeSetMap* map2 = rt->GetNativeSetMap(); + NativeSetMap* map2 = xpccx->GetNativeSetMap(); if (!map2) goto out; @@ -603,8 +603,8 @@ XPCNativeSet::GetNewOrUsed(nsIClassInfo* classInfo) void XPCNativeSet::ClearCacheEntryForClassInfo(nsIClassInfo* classInfo) { - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - ClassInfo2NativeSetMap* map = rt->GetClassInfo2NativeSetMap(); + XPCJSContext* xpccx = nsXPConnect::GetContextInstance(); + ClassInfo2NativeSetMap* map = xpccx->GetClassInfo2NativeSetMap(); if (map) map->Remove(classInfo); } @@ -615,8 +615,8 @@ XPCNativeSet::GetNewOrUsed(XPCNativeSetKey* key) { AutoJSContext cx; AutoMarkingNativeSetPtr set(cx); - XPCJSRuntime* rt = XPCJSRuntime::Get(); - NativeSetMap* map = rt->GetNativeSetMap(); + XPCJSContext* xpccx = XPCJSContext::Get(); + NativeSetMap* map = xpccx->GetNativeSetMap(); if (!map) return nullptr; diff --git a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp index 42fe43f0d07ca..c7f37f6f134ef 100644 --- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp +++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp @@ -78,7 +78,7 @@ XPC_WN_Shared_ToString(JSContext* cx, unsigned argc, Value* vp) XPCCallContext ccx(cx, obj); if (!ccx.IsValid()) return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx); - ccx.SetName(ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_TO_STRING)); + ccx.SetName(ccx.GetContext()->GetStringID(XPCJSContext::IDX_TO_STRING)); ccx.SetArgsAndResultPtr(args.length(), args.array(), vp); return ToStringGuts(ccx); } @@ -118,7 +118,7 @@ XPC_WN_Shared_toPrimitive(JSContext* cx, unsigned argc, Value* vp) } MOZ_ASSERT(hint == JSTYPE_STRING || hint == JSTYPE_VOID); - ccx.SetName(ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_TO_STRING)); + ccx.SetName(ccx.GetContext()->GetStringID(XPCJSContext::IDX_TO_STRING)); ccx.SetArgsAndResultPtr(0, nullptr, args.rval().address()); XPCNativeMember* member = ccx.GetMember(); @@ -155,8 +155,8 @@ GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper) if (underware) { RootedObject mainObj(ccx, underware->GetJSObject()); if (mainObj) { - RootedId id(ccx, ccx.GetRuntime()-> - GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT)); + RootedId id(ccx, ccx.GetContext()-> + GetStringID(XPCJSContext::IDX_WRAPPED_JSOBJECT)); JSAutoCompartment ac(ccx, mainObj); @@ -234,7 +234,7 @@ DefinePropertyIfFound(XPCCallContext& ccx, { RootedId id(ccx, idArg); RefPtr iface = ifaceArg; - XPCJSRuntime* rt = ccx.GetRuntime(); + XPCJSContext* xpccx = ccx.GetContext(); bool found; const char* name; @@ -267,14 +267,14 @@ DefinePropertyIfFound(XPCCallContext& ccx, bool overwriteToString = !(flags & nsIClassInfo::DOM_OBJECT) || Preferences::GetBool("dom.XPCToStringForDOMClasses", false); - if(id == rt->GetStringID(XPCJSRuntime::IDX_TO_STRING) + if(id == xpccx->GetStringID(XPCJSContext::IDX_TO_STRING) && overwriteToString) { call = XPC_WN_Shared_ToString; - name = rt->GetStringName(XPCJSRuntime::IDX_TO_STRING); - } else if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_SOURCE)) { + name = xpccx->GetStringName(XPCJSContext::IDX_TO_STRING); + } else if (id == xpccx->GetStringID(XPCJSContext::IDX_TO_SOURCE)) { call = XPC_WN_Shared_ToSource; - name = rt->GetStringName(XPCJSRuntime::IDX_TO_SOURCE); + name = xpccx->GetStringName(XPCJSContext::IDX_TO_SOURCE); } else if (id == SYMBOL_TO_JSID( JS::GetWellKnownSymbol(ccx, JS::SymbolCode::toPrimitive))) { @@ -331,15 +331,15 @@ DefinePropertyIfFound(XPCCallContext& ccx, // This *might* be a double wrapped JSObject if (wrapperToReflectDoubleWrap && - id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT) && + id == xpccx->GetStringID(XPCJSContext::IDX_WRAPPED_JSOBJECT) && GetDoubleWrappedJSObject(ccx, wrapperToReflectDoubleWrap)) { // We build and add a getter function. // A security check is done on a per-get basis. JSFunction* fun; - id = rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT); - name = rt->GetStringName(XPCJSRuntime::IDX_WRAPPED_JSOBJECT); + id = xpccx->GetStringID(XPCJSContext::IDX_WRAPPED_JSOBJECT); + name = xpccx->GetStringName(XPCJSContext::IDX_WRAPPED_JSOBJECT); fun = JS_NewFunction(ccx, XPC_WN_DoubleWrappedGetter, 0, 0, name); @@ -412,11 +412,11 @@ DefinePropertyIfFound(XPCCallContext& ccx, } } - if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_STRING) || - id == rt->GetStringID(XPCJSRuntime::IDX_TO_SOURCE) || + if (id == xpccx->GetStringID(XPCJSContext::IDX_TO_STRING) || + id == xpccx->GetStringID(XPCJSContext::IDX_TO_SOURCE) || (scriptableInfo && scriptableInfo->GetFlags().DontEnumQueryInterface() && - id == rt->GetStringID(XPCJSRuntime::IDX_QUERY_INTERFACE))) + id == xpccx->GetStringID(XPCJSContext::IDX_QUERY_INTERFACE))) propFlags &= ~JSPROP_ENUMERATE; RootedValue funval(ccx); @@ -932,8 +932,8 @@ XPCNativeScriptableInfo::Construct(const XPCNativeScriptableCreateInfo* sci) bool success; - XPCJSRuntime* rt = XPCJSRuntime::Get(); - XPCNativeScriptableSharedMap* map = rt->GetNativeScriptableSharedMap(); + XPCJSContext* cx = XPCJSContext::Get(); + XPCNativeScriptableSharedMap* map = cx->GetNativeScriptableSharedMap(); success = map->GetNewOrUsed(sci->GetFlags(), name, newObj); if (!success) { @@ -1067,7 +1067,7 @@ XPCNativeScriptableShared::~XPCNativeScriptableShared() // removed. if (mJSClass.cOps) { - XPCJSRuntime::Get()->GetNativeScriptableSharedMap()->Remove(this); + XPCJSContext::Get()->GetNativeScriptableSharedMap()->Remove(this); free((void*)mJSClass.cOps); } diff --git a/js/xpconnect/src/XPCWrappedNativeProto.cpp b/js/xpconnect/src/XPCWrappedNativeProto.cpp index ff3cb5da9479c..a1ef0b4053a1c 100644 --- a/js/xpconnect/src/XPCWrappedNativeProto.cpp +++ b/js/xpconnect/src/XPCWrappedNativeProto.cpp @@ -122,8 +122,8 @@ XPCWrappedNativeProto::JSProtoObjectFinalized(js::FreeOp* fop, JSObject* obj) if (map->Find(mClassInfo) == this) map->Remove(mClassInfo); - GetRuntime()->GetDetachedWrappedNativeProtoMap()->Remove(this); - GetRuntime()->GetDyingWrappedNativeProtoMap()->Add(this); + GetContext()->GetDetachedWrappedNativeProtoMap()->Remove(this); + GetContext()->GetDyingWrappedNativeProtoMap()->Add(this); mJSProtoObject.finalize(js::CastToJSFreeOp(fop)->runtime()); } diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 9632c9ca57406..6b82c27477f95 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -237,7 +237,7 @@ XPCWrappedNativeScope::AttachComponentsObject(JSContext* aCx) if (c) attrs |= JSPROP_PERMANENT; - RootedId id(aCx, XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)); + RootedId id(aCx, XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)); return JS_DefinePropertyById(aCx, global, id, components, attrs); } @@ -483,7 +483,7 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope() // static void -XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(JSTracer* trc, XPCJSRuntime* rt) +XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(JSTracer* trc, XPCJSContext* cx) { // Do JS::TraceEdge for all wrapped natives with external references, as // well as any DOM expando objects. @@ -512,7 +512,7 @@ SuspectDOMExpandos(JSObject* obj, nsCycleCollectionNoteRootCallback& cb) // static void -XPCWrappedNativeScope::SuspectAllWrappers(XPCJSRuntime* rt, +XPCWrappedNativeScope::SuspectAllWrappers(XPCJSContext* cx, nsCycleCollectionNoteRootCallback& cb) { for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) { @@ -529,7 +529,7 @@ XPCWrappedNativeScope::SuspectAllWrappers(XPCJSRuntime* rt, // static void -XPCWrappedNativeScope::UpdateWeakPointersAfterGC(XPCJSRuntime* rt) +XPCWrappedNativeScope::UpdateWeakPointersAfterGC(XPCJSContext* cx) { // If this is called from the finalization callback in JSGC_MARK_END then // JSGC_FINALIZE_END must always follow it calling diff --git a/js/xpconnect/src/moz.build b/js/xpconnect/src/moz.build index 4017ee073d79d..9108fd66aca2d 100644 --- a/js/xpconnect/src/moz.build +++ b/js/xpconnect/src/moz.build @@ -22,8 +22,8 @@ UNIFIED_SOURCES += [ 'XPCConvert.cpp', 'XPCDebug.cpp', 'XPCException.cpp', + 'XPCJSContext.cpp', 'XPCJSID.cpp', - 'XPCJSRuntime.cpp', 'XPCJSWeakReference.cpp', 'XPCLocale.cpp', 'XPCLog.cpp', diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 2c9db126b3be5..7f60fcf759542 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -60,18 +60,18 @@ const char XPC_XPCONNECT_CONTRACTID[] = "@mozilla.org/js/xpc/XPConnect;1"; /***************************************************************************/ nsXPConnect::nsXPConnect() - : mRuntime(nullptr), + : mContext(nullptr), mShuttingDown(false) { - mRuntime = XPCJSRuntime::newXPCJSRuntime(); - if (!mRuntime) { - NS_RUNTIMEABORT("Couldn't create XPCJSRuntime."); + mContext = XPCJSContext::newXPCJSContext(); + if (!mContext) { + NS_RUNTIMEABORT("Couldn't create XPCJSContext."); } } nsXPConnect::~nsXPConnect() { - mRuntime->DeleteSingletonScopes(); + mContext->DeleteSingletonScopes(); // In order to clean up everything properly, we need to GC twice: once now, // to clean anything that can go away on its own (like the Junk Scope, which @@ -79,17 +79,17 @@ nsXPConnect::~nsXPConnect() // XPConnect, to clean the stuff we forcibly disconnected. The forced // shutdown code defaults to leaking in a number of situations, so we can't // get by with only the second GC. :-( - mRuntime->GarbageCollect(JS::gcreason::XPCONNECT_SHUTDOWN); + mContext->GarbageCollect(JS::gcreason::XPCONNECT_SHUTDOWN); mShuttingDown = true; XPCWrappedNativeScope::SystemIsBeingShutDown(); - mRuntime->SystemIsBeingShutDown(); + mContext->SystemIsBeingShutDown(); // The above causes us to clean up a bunch of XPConnect data structures, // after which point we need to GC to clean everything up. We need to do - // this before deleting the XPCJSRuntime, because doing so destroys the + // this before deleting the XPCJSContext, because doing so destroys the // maps that our finalize callback depends on. - mRuntime->GarbageCollect(JS::gcreason::XPCONNECT_SHUTDOWN); + mContext->GarbageCollect(JS::gcreason::XPCONNECT_SHUTDOWN); NS_RELEASE(gSystemPrincipal); gScriptSecurityManager = nullptr; @@ -97,7 +97,7 @@ nsXPConnect::~nsXPConnect() // shutdown the logging system XPC_LOG_FINISH(); - delete mRuntime; + delete mContext; gSelf = nullptr; gOnceAliveNowDead = true; @@ -109,8 +109,8 @@ nsXPConnect::InitStatics() { gSelf = new nsXPConnect(); gOnceAliveNowDead = false; - if (!gSelf->mRuntime) { - NS_RUNTIMEABORT("Couldn't create XPCJSRuntime."); + if (!gSelf->mContext) { + NS_RUNTIMEABORT("Couldn't create XPCJSContext."); } // Initial extra ref to keep the singleton alive @@ -123,13 +123,13 @@ nsXPConnect::InitStatics() gScriptSecurityManager->GetSystemPrincipal(&gSystemPrincipal); MOZ_RELEASE_ASSERT(gSystemPrincipal); - if (!JS::InitSelfHostedCode(gSelf->mRuntime->Context())) + if (!JS::InitSelfHostedCode(gSelf->mContext->Context())) MOZ_CRASH("InitSelfHostedCode failed"); - if (!gSelf->mRuntime->JSContextInitialized(gSelf->mRuntime->Context())) + if (!gSelf->mContext->JSContextInitialized(gSelf->mContext->Context())) MOZ_CRASH("JSContextInitialized failed"); // Initialize our singleton scopes. - gSelf->mRuntime->InitSingletonScopes(); + gSelf->mContext->InitSingletonScopes(); } nsXPConnect* @@ -152,11 +152,11 @@ nsXPConnect::ReleaseXPConnectSingleton() } // static -XPCJSRuntime* -nsXPConnect::GetRuntimeInstance() +XPCJSContext* +nsXPConnect::GetContextInstance() { nsXPConnect* xpc = XPConnect(); - return xpc->GetRuntime(); + return xpc->GetContext(); } // static @@ -321,7 +321,7 @@ nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info) NS_IMETHODIMP nsXPConnect::GarbageCollect(uint32_t reason) { - GetRuntime()->GarbageCollect(reason); + GetContext()->GarbageCollect(reason); return NS_OK; } @@ -762,7 +762,7 @@ nsXPConnect::GetCurrentNativeCallContext(nsAXPCNativeCallContext * *aCurrentNati { MOZ_ASSERT(aCurrentNativeCallContext, "bad param"); - *aCurrentNativeCallContext = XPCJSRuntime::Get()->GetCallContext(); + *aCurrentNativeCallContext = XPCJSContext::Get()->GetCallContext(); return NS_OK; } @@ -770,8 +770,8 @@ NS_IMETHODIMP nsXPConnect::SetFunctionThisTranslator(const nsIID & aIID, nsIXPCFunctionThisTranslator* aTranslator) { - XPCJSRuntime* rt = GetRuntime(); - IID2ThisTranslatorMap* map = rt->GetThisTranslatorMap(); + XPCJSContext* cx = GetContext(); + IID2ThisTranslatorMap* map = cx->GetThisTranslatorMap(); map->Add(aIID, aTranslator); return NS_OK; } @@ -860,13 +860,13 @@ nsXPConnect::DebugDump(int16_t depth) XPC_LOG_INDENT(); XPC_LOG_ALWAYS(("gSelf @ %x", gSelf)); XPC_LOG_ALWAYS(("gOnceAliveNowDead is %d", (int)gOnceAliveNowDead)); - if (mRuntime) { + if (mContext) { if (depth) - mRuntime->DebugDump(depth); + mContext->DebugDump(depth); else - XPC_LOG_ALWAYS(("XPCJSRuntime @ %x", mRuntime)); + XPC_LOG_ALWAYS(("XPCJSContext @ %x", mContext)); } else - XPC_LOG_ALWAYS(("mRuntime is null")); + XPC_LOG_ALWAYS(("mContext is null")); XPCWrappedNativeScope::DebugDumpAllScopes(depth); XPC_LOG_OUTDENT(); #endif @@ -1068,7 +1068,7 @@ SetLocationForGlobal(JSObject* global, nsIURI* locationURI) NS_IMETHODIMP nsXPConnect::NotifyDidPaint() { - JS::NotifyDidPaint(GetRuntime()->Context()); + JS::NotifyDidPaint(GetContext()->Context()); return NS_OK; } diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index b008f64b2559f..b3070cd78cae0 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -257,8 +257,8 @@ class nsXPConnect final : public nsIXPConnect return gSelf; } - static XPCJSRuntime* GetRuntimeInstance(); - XPCJSRuntime* GetRuntime() {return mRuntime;} + static XPCJSContext* GetContextInstance(); + XPCJSContext* GetContext() {return mContext;} static bool IsISupportsDescendant(nsIInterfaceInfo* info); @@ -309,7 +309,7 @@ class nsXPConnect final : public nsIXPConnect static nsXPConnect* gSelf; static bool gOnceAliveNowDead; - XPCJSRuntime* mRuntime; + XPCJSContext* mContext; bool mShuttingDown; public: @@ -347,14 +347,14 @@ class XPCRootSetElem /***************************************************************************/ -// In the current xpconnect system there can only be one XPCJSRuntime. -// So, xpconnect can only be used on one JSRuntime within the process. +// In the current xpconnect system there can only be one XPCJSContext. +// So, xpconnect can only be used on one JSContext within the process. class WatchdogManager; enum WatchdogTimestampCategory { - TimestampRuntimeStateChange = 0, + TimestampContextStateChange = 0, TimestampWatchdogWakeup, TimestampWatchdogHibernateStart, TimestampWatchdogHibernateStop, @@ -409,11 +409,11 @@ class ShortLivedStringBuffer mozilla::Maybe mStrings[2]; }; -class XPCJSRuntime final : public mozilla::CycleCollectedJSContext +class XPCJSContext final : public mozilla::CycleCollectedJSContext { public: - static XPCJSRuntime* newXPCJSRuntime(); - static XPCJSRuntime* Get() { return nsXPConnect::XPConnect()->GetRuntime(); } + static XPCJSContext* newXPCJSContext(); + static XPCJSContext* Get() { return nsXPConnect::XPConnect()->GetContext(); } void RemoveWrappedJS(nsXPCWrappedJS* wrapper); void AssertInvalidWrappedJSNotInTable(nsXPCWrappedJS* wrapper) const; @@ -481,8 +481,8 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSContext // Mapping of often used strings to jsid atoms that live 'forever'. // - // To add a new string: add to this list and to XPCJSRuntime::mStrings - // at the top of XPCJSRuntime.cpp + // To add a new string: add to this list and to XPCJSContext::mStrings + // at the top of XPCJSContext.cpp enum { IDX_CONSTRUCTOR = 0 , IDX_TO_STRING , @@ -569,7 +569,7 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSContext bool GCIsRunning() const {return mGCIsRunning;} - ~XPCJSRuntime(); + ~XPCJSContext(); ShortLivedStringBuffer mScratchStrings; ShortLivedStringBuffer mScratchCStrings; @@ -597,7 +597,7 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSContext void SetPendingResult(nsresult rv) { mPendingResult = rv; } private: - XPCJSRuntime(); + XPCJSContext(); nsresult Initialize(); @@ -709,7 +709,7 @@ class MOZ_STACK_CLASS XPCCallContext final : public nsAXPCNativeCallContext inline bool IsValid() const ; - inline XPCJSRuntime* GetRuntime() const ; + inline XPCJSContext* GetContext() const ; inline JSContext* GetJSContext() const ; inline bool GetContextPopRequired() const ; inline XPCCallContext* GetPrevCallContext() const ; @@ -768,7 +768,7 @@ class MOZ_STACK_CLASS XPCCallContext final : public nsAXPCNativeCallContext enum State { INIT_FAILED, SYSTEM_SHUTDOWN, - HAVE_RUNTIME, + HAVE_CONTEXT, HAVE_OBJECT, HAVE_NAME, HAVE_ARGS, @@ -788,7 +788,7 @@ inline void CHECK_STATE(int s) const {MOZ_ASSERT(mState >= s, "bad state");} RefPtr mXPC; - XPCJSRuntime* mXPCJSRuntime; + XPCJSContext* mXPCJSContext; JSContext* mJSContext; // ctor does not necessarily init the following. BEWARE! @@ -868,8 +868,8 @@ class XPCWrappedNativeScope final : public PRCList { public: - XPCJSRuntime* - GetRuntime() const {return XPCJSRuntime::Get();} + XPCJSContext* + GetContext() const {return XPCJSContext::Get();} Native2WrappedNativeMap* GetWrappedNativeMap() const {return mWrappedNativeMap;} @@ -916,7 +916,7 @@ class XPCWrappedNativeScope final : public PRCList SystemIsBeingShutDown(); static void - TraceWrappedNativesInAllScopes(JSTracer* trc, XPCJSRuntime* rt); + TraceWrappedNativesInAllScopes(JSTracer* trc, XPCJSContext* cx); void TraceSelf(JSTracer* trc) { MOZ_ASSERT(mGlobalJSObject); @@ -933,7 +933,7 @@ class XPCWrappedNativeScope final : public PRCList } static void - SuspectAllWrappers(XPCJSRuntime* rt, nsCycleCollectionNoteRootCallback& cb); + SuspectAllWrappers(XPCJSContext* cx, nsCycleCollectionNoteRootCallback& cb); static void MarkAllWrappedNativesAndProtos(); @@ -947,7 +947,7 @@ class XPCWrappedNativeScope final : public PRCList SweepAllWrappedNativeTearOffs(); static void - UpdateWeakPointersAfterGC(XPCJSRuntime* rt); + UpdateWeakPointersAfterGC(XPCJSContext* cx); static void KillDyingScopes(); @@ -977,7 +977,7 @@ class XPCWrappedNativeScope final : public PRCList AddSizeOfIncludingThis(ScopeSizeInfo* scopeSizeInfo); bool - IsValid() const {return mRuntime != nullptr;} + IsValid() const {return mContext != nullptr;} static bool IsDyingScope(XPCWrappedNativeScope* scope); @@ -1070,7 +1070,7 @@ class XPCWrappedNativeScope final : public PRCList static InterpositionWhitelistArray* gInterpositionWhitelists; - XPCJSRuntime* mRuntime; + XPCJSContext* mContext; Native2WrappedNativeMap* mWrappedNativeMap; ClassInfo2WrappedNativeProtoMap* mWrappedNativeProtoMap; RefPtr mComponents; @@ -1496,7 +1496,7 @@ class XPCNativeScriptableFlags final // XPCNativeScriptableShared is used to hold the JSClass and the // associated scriptable flags for XPCWrappedNatives. These are shared across -// the runtime and are garbage collected by xpconnect. We *used* to just store +// the context and are garbage collected by xpconnect. We *used* to just store // this inside the XPCNativeScriptableInfo (usually owned by instances of // XPCWrappedNativeProto. This had two problems... It was wasteful, and it // was a big problem when wrappers are reparented to different scopes (and @@ -1628,8 +1628,8 @@ class XPCWrappedNativeProto final XPCWrappedNativeScope* GetScope() const {return mScope;} - XPCJSRuntime* - GetRuntime() const {return mScope->GetRuntime();} + XPCJSContext* + GetContext() const {return mScope->GetContext();} JSObject* GetJSProtoObject() const { @@ -1893,9 +1893,9 @@ class XPCWrappedNative final : public nsIXPConnectWrappedNative (!HasProto() || GetSet() != GetProto()->GetSet());} - XPCJSRuntime* - GetRuntime() const {XPCWrappedNativeScope* scope = GetScope(); - return scope ? scope->GetRuntime() : nullptr;} + XPCJSContext* + GetContext() const {XPCWrappedNativeScope* scope = GetScope(); + return scope ? scope->GetContext() : nullptr;} static nsresult WrapNewGlobal(xpcObjectHelper& nativeHelper, @@ -2089,7 +2089,7 @@ class nsXPCWrappedJSClass final : public nsIXPCWrappedJSClass bool allowNonScriptable = false); REFNSIID GetIID() const {return mIID;} - XPCJSRuntime* GetRuntime() const {return mRuntime;} + XPCJSContext* GetContext() const {return mContext;} nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;} const char* GetInterfaceName(); @@ -2164,7 +2164,7 @@ class nsXPCWrappedJSClass final : public nsIXPCWrappedJSClass nsXPTCMiniVariant* nativeParams, bool inOutOnly, uint8_t n) const; private: - XPCJSRuntime* mRuntime; + XPCJSContext* mContext; nsCOMPtr mInfo; char* mName; nsIID mIID; @@ -2221,7 +2221,7 @@ class nsXPCWrappedJS final : protected nsAutoXPTCStub, // Returns true if the wrapper chain contains references to multiple // compartments. If the wrapper chain contains references to multiple - // compartments, then it must be registered on the XPCJSRuntime. Otherwise, + // compartments, then it must be registered on the XPCJSContext. Otherwise, // it should be registered in the CompartmentPrivate for the compartment of // the root's JS object. This will only return correct results when called // on the root wrapper and will assert if not called on a root wrapper. @@ -2790,7 +2790,7 @@ class MOZ_RAII AutoResolveName public: AutoResolveName(XPCCallContext& ccx, JS::HandleId name MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : - mOld(ccx, XPCJSRuntime::Get()->SetResolveName(name)) + mOld(ccx, XPCJSContext::Get()->SetResolveName(name)) #ifdef DEBUG ,mCheck(ccx, name) #endif @@ -2802,7 +2802,7 @@ class MOZ_RAII AutoResolveName #ifdef DEBUG jsid old = #endif - XPCJSRuntime::Get()->SetResolveName(mOld); + XPCJSContext::Get()->SetResolveName(mOld); MOZ_ASSERT(old == mCheck, "Bad Nesting!"); } @@ -2825,7 +2825,7 @@ class AutoMarkingPtr { public: explicit AutoMarkingPtr(JSContext* cx) { - mRoot = XPCJSRuntime::Get()->GetAutoRootsAdr(); + mRoot = XPCJSContext::Get()->GetAutoRootsAdr(); mNext = *mRoot; *mRoot = this; } @@ -3007,7 +3007,7 @@ class XPCTraceableVariant: public XPCVariant, XPCTraceableVariant(JSContext* cx, JS::Value aJSVal) : XPCVariant(cx, aJSVal) { - nsXPConnect::GetRuntimeInstance()->AddVariantRoot(this); + nsXPConnect::GetContextInstance()->AddVariantRoot(this); } virtual ~XPCTraceableVariant(); @@ -3027,7 +3027,7 @@ xpc_GetJSPrivate(JSObject* obj) inline JSContext* xpc_GetSafeJSContext() { - return XPCJSRuntime::Get()->Context(); + return XPCJSContext::Get()->Context(); } namespace xpc { @@ -3338,7 +3338,7 @@ inline bool xpc_ForcePropertyResolve(JSContext* cx, JS::HandleObject obj, jsid id); inline jsid -GetRTIdByIndex(JSContext* cx, unsigned index); +GetJSIDByIndex(JSContext* cx, unsigned index); namespace xpc { @@ -3482,7 +3482,7 @@ class CompartmentPrivate } JSObject2WrappedJSMap* GetWrappedJSMap() const { return mWrappedJSMap; } - void UpdateWeakPointersAfterGC(XPCJSRuntime* runtime); + void UpdateWeakPointersAfterGC(XPCJSContext* context); size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf); diff --git a/js/xpconnect/tests/chrome/test_bug732665.xul b/js/xpconnect/tests/chrome/test_bug732665.xul index f295ac6e1f11f..e373c5a0f1dd9 100644 --- a/js/xpconnect/tests/chrome/test_bug732665.xul +++ b/js/xpconnect/tests/chrome/test_bug732665.xul @@ -20,7 +20,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=732665 // // Important! If this test starts failing after a tricky platform-y change, - // the stack quota numbers in XPCJSRuntime probably need twiddling. We want + // the stack quota numbers in XPCJSContext probably need twiddling. We want // to maintain the invariants in this test (at least to some approximation) // for security reasons. // @@ -71,7 +71,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=732665 // If this assertion fails, the current work-around so far is to measure // again the worst frame size, by using the JS Shell to run // test_bug732665_meta.js . This script will output numbers to update - // XPCJSRuntime.cpp comment, as well as the kTrustedScriptBuffer constant. + // XPCJSContext.cpp comment, as well as the kTrustedScriptBuffer constant. contentSb.nnslChrome = chromeSb.nearNativeStackLimit; var nestedLimit = Cu.evalInSandbox("nearNativeStackLimit(1, function() { nestedLimit = nnslChrome(0);}); nestedLimit;", contentSb); ok(nestedLimit >= 11, "Chrome should be invokable from content script with an exhausted stack: " + nestedLimit); diff --git a/js/xpconnect/tests/unit/test_watchdog_hibernate.js b/js/xpconnect/tests/unit/test_watchdog_hibernate.js index bc0878721bdb7..ce36429632f90 100644 --- a/js/xpconnect/tests/unit/test_watchdog_hibernate.js +++ b/js/xpconnect/tests/unit/test_watchdog_hibernate.js @@ -30,7 +30,7 @@ function testBody() { simulateActivityCallback(true); busyWait(1000); // Give the watchdog time to wake up on the condvar. - var stateChange = Cu.getWatchdogTimestamp("RuntimeStateChange"); + var stateChange = Cu.getWatchdogTimestamp("ContextStateChange"); startHibernation = Cu.getWatchdogTimestamp("WatchdogHibernateStart"); stopHibernation = Cu.getWatchdogTimestamp("WatchdogHibernateStop"); do_log_info("Post-hibernation statistics:"); diff --git a/js/xpconnect/wrappers/AccessCheck.cpp b/js/xpconnect/wrappers/AccessCheck.cpp index ff31e800f6fac..9b799a9c03c44 100644 --- a/js/xpconnect/wrappers/AccessCheck.cpp +++ b/js/xpconnect/wrappers/AccessCheck.cpp @@ -239,7 +239,7 @@ AccessCheck::checkPassToPrivilegedCode(JSContext* cx, HandleObject wrapper, Hand if (AccessCheck::isChrome(js::UncheckedUnwrap(wrapper)) && WrapperFactory::IsCOW(obj)) { RootedObject target(cx, js::UncheckedUnwrap(obj)); JSAutoCompartment ac(cx, target); - RootedId id(cx, GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS)); + RootedId id(cx, GetJSIDByIndex(cx, XPCJSContext::IDX_EXPOSEDPROPS)); bool found = false; if (!JS_HasPropertyById(cx, target, id, &found)) return false; @@ -292,7 +292,7 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W check(cx, wrapper, id, Wrapper::SET); } - RootedId exposedPropsId(cx, GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS)); + RootedId exposedPropsId(cx, GetJSIDByIndex(cx, XPCJSContext::IDX_EXPOSEDPROPS)); // We need to enter the wrappee's compartment to look at __exposedProps__, // but we want to be in the wrapper's compartment if we call Deny(). diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 4c0fedbe5b4d8..348b6a2d5f48d 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -548,11 +548,11 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, } } } else if (key == JSProto_Function) { - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_LENGTH)) { + if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_LENGTH)) { FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY, NumberValue(JS_GetFunctionArity(JS_GetObjectFunction(target)))); return true; - } else if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_NAME)) { + } else if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) { RootedString fname(cx, JS_GetFunctionId(JS_GetObjectFunction(target))); FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY, fname ? StringValue(fname) : JS_GetEmptyStringValue(cx)); @@ -563,7 +563,7 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, if (standardConstructor != JSProto_Null) { // Handle the 'prototype' property to make // xrayedGlobal.StandardClass.prototype work. - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_PROTOTYPE)) { + if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_PROTOTYPE)) { RootedObject standardProto(cx); { JSAutoCompartment ac(cx, target); @@ -606,11 +606,11 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, // type. This limits the ability of content to do anything all that // confusing. bool isErrorIntProperty = - id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_LINENUMBER) || - id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_COLUMNNUMBER); + id == GetJSIDByIndex(cx, XPCJSContext::IDX_LINENUMBER) || + id == GetJSIDByIndex(cx, XPCJSContext::IDX_COLUMNNUMBER); bool isErrorStringProperty = - id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_FILENAME) || - id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_MESSAGE); + id == GetJSIDByIndex(cx, XPCJSContext::IDX_FILENAME) || + id == GetJSIDByIndex(cx, XPCJSContext::IDX_MESSAGE); if (isErrorIntProperty || isErrorStringProperty) { RootedObject waiver(cx, wrapper); if (!WrapperFactory::WaiveXrayAndWrap(cx, &waiver)) @@ -624,7 +624,7 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, return true; } } else if (key == JSProto_RegExp) { - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_LASTINDEX)) + if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX)) return getOwnPropertyFromWrapperIfSafe(cx, wrapper, id, desc); } @@ -633,7 +633,7 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, } // Handle the 'constructor' property. - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_CONSTRUCTOR)) { + if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_CONSTRUCTOR)) { RootedObject constructor(cx); { JSAutoCompartment ac(cx, target); @@ -651,7 +651,7 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, } // Handle the 'name' property for error prototypes. - if (IsErrorObjectKey(key) && id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_NAME)) { + if (IsErrorObjectKey(key) && id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) { RootedId className(cx); ProtoKeyToId(cx, key, &className); FillPropertyDescriptor(desc, wrapper, 0, UndefinedValue()); @@ -659,7 +659,7 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, } // Handle the 'lastIndex' property for RegExp prototypes. - if (key == JSProto_RegExp && id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_LASTINDEX)) + if (key == JSProto_RegExp && id == GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX)) return getOwnPropertyFromWrapperIfSafe(cx, wrapper, id, desc); // Grab the JSClass. We require all Xrayable classes to have a ClassSpec. @@ -859,15 +859,15 @@ JSXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper, unsigned flags for (int32_t i = 0; i <= int32_t(length - 1); ++i) props.infallibleAppend(INT_TO_JSID(i)); } else if (key == JSProto_Function) { - if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_LENGTH))) + if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LENGTH))) return false; - if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_NAME))) + if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_NAME))) return false; // Handle the .prototype property and static properties on standard // constructors. JSProtoKey standardConstructor = constructorFor(holder); if (standardConstructor != JSProto_Null) { - if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_PROTOTYPE))) + if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_PROTOTYPE))) return false; if (ShouldResolveStaticProperties(standardConstructor)) { @@ -882,16 +882,16 @@ JSXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper, unsigned flags } } } else if (IsErrorObjectKey(key)) { - if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_FILENAME)) || - !props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_LINENUMBER)) || - !props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_COLUMNNUMBER)) || - !props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_STACK)) || - !props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_MESSAGE))) + if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_FILENAME)) || + !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LINENUMBER)) || + !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_COLUMNNUMBER)) || + !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_STACK)) || + !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_MESSAGE))) { return false; } } else if (key == JSProto_RegExp) { - if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_LASTINDEX))) + if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX))) return false; } @@ -900,15 +900,15 @@ JSXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper, unsigned flags } // Add the 'constructor' property. - if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_CONSTRUCTOR))) + if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_CONSTRUCTOR))) return false; // For Error protoypes, add the 'name' property. - if (IsErrorObjectKey(key) && !props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_NAME))) + if (IsErrorObjectKey(key) && !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_NAME))) return false; // For RegExp protoypes, add the 'lastIndex' property. - if (key == JSProto_RegExp && !props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_LASTINDEX))) + if (key == JSProto_RegExp && !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX))) return false; // Grab the JSClass. We require all Xrayable classes to have a ClassSpec. @@ -1361,7 +1361,7 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext* cx, HandleObject wr } if (!(iface = ccx.GetInterface()) || !(member = ccx.GetMember())) { - if (id != nsXPConnect::GetRuntimeInstance()->GetStringID(XPCJSRuntime::IDX_TO_STRING)) + if (id != nsXPConnect::GetContextInstance()->GetStringID(XPCJSContext::IDX_TO_STRING)) return true; JSFunction* toString = JS_NewFunction(cx, XrayToString, 0, 0, "toString"); @@ -1482,7 +1482,7 @@ XrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, MOZ_ASSERT(constructor); desc.value().set(ObjectValue(*constructor)); found = true; - } else if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_EVAL)) { + } else if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_EVAL)) { RootedObject eval(cx); if (!js::GetOriginalEval(cx, target, &eval)) return false; @@ -1501,7 +1501,7 @@ XrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, // Handle .wrappedJSObject for subsuming callers. This should move once we // sort out own-ness for the holder. - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_WRAPPED_JSOBJECT) && + if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_WRAPPED_JSOBJECT) && WrapperFactory::AllowWaiver(wrapper)) { if (!JS_AlreadyHasOwnPropertyById(cx, holder, id, &found)) diff --git a/toolkit/components/perfmonitoring/README.md b/toolkit/components/perfmonitoring/README.md index ce4aadc548446..abd109e45fb2c 100644 --- a/toolkit/components/perfmonitoring/README.md +++ b/toolkit/components/perfmonitoring/README.md @@ -61,7 +61,7 @@ The instrumentation of CPOW lives in `js/ipc/src`. It maintains a CPOW clock tha ## XPConnect-level -The instrumentation of XPConnect lives in `js/xpconnect/src/XPCJSRuntime.cpp`. +The instrumentation of XPConnect lives in `js/xpconnect/src/XPCJSContext.cpp`. ### When we enter a nested event loop diff --git a/tools/memory-profiler/MemoryProfiler.cpp b/tools/memory-profiler/MemoryProfiler.cpp index 309eba3ca3e79..c2b8cbd1d144b 100644 --- a/tools/memory-profiler/MemoryProfiler.cpp +++ b/tools/memory-profiler/MemoryProfiler.cpp @@ -107,7 +107,7 @@ MemoryProfiler::StartProfiler() InitOnce(); AutoUseUncensoredAllocator ua; AutoMPLock lock(sLock); - JSContext* context = XPCJSRuntime::Get()->Context(); + JSContext* context = XPCJSContext::Get()->Context(); ProfilerForJSContext profiler; if (!sJSContextProfilerMap->Get(context, &profiler) || !profiler.mEnabled) { @@ -137,7 +137,7 @@ MemoryProfiler::StopProfiler() InitOnce(); AutoUseUncensoredAllocator ua; AutoMPLock lock(sLock); - JSContext* context = XPCJSRuntime::Get()->Context(); + JSContext* context = XPCJSContext::Get()->Context(); ProfilerForJSContext profiler; if (sJSContextProfilerMap->Get(context, &profiler) && profiler.mEnabled) { @@ -159,7 +159,7 @@ MemoryProfiler::ResetProfiler() InitOnce(); AutoUseUncensoredAllocator ua; AutoMPLock lock(sLock); - JSContext* context = XPCJSRuntime::Get()->Context(); + JSContext* context = XPCJSContext::Get()->Context(); ProfilerForJSContext profiler; if (!sJSContextProfilerMap->Get(context, &profiler) || !profiler.mEnabled) { @@ -249,7 +249,7 @@ MemoryProfiler::GetResults(JSContext* cx, JS::MutableHandle aResult) InitOnce(); AutoUseUncensoredAllocator ua; AutoMPLock lock(sLock); - JSContext* context = XPCJSRuntime::Get()->Context(); + JSContext* context = XPCJSContext::Get()->Context(); // Getting results when the profiler is running is not allowed. if (sProfileContextCount > 0) { return NS_OK; diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index 3988ce7e8241f..381de9d2f2c09 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -1019,11 +1019,11 @@ ShutdownXPCOM(nsIServiceManager* aServMgr) #ifdef MOZ_ENABLE_PROFILER_SPS // In optimized builds we don't do shutdown collections by default, so // uncollected (garbage) objects may keep the nsXPConnect singleton alive, - // and its XPCJSRuntime along with it. However, we still destroy various + // and its XPCJSContext along with it. However, we still destroy various // bits of state in JS_ShutDown(), so we need to make sure the profiler // can't access them when it shuts down. This call nulls out the - // JS pseudo-stack's internal reference to the main thread JSRuntime, - // duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that + // JS pseudo-stack's internal reference to the main thread JSContext, + // duplicating the call in XPCJSContext::~XPCJSContext() in case that // never fired. if (PseudoStack* stack = mozilla_get_pseudo_stack()) { stack->sampleContext(nullptr);