Bug 1292892 part 1 - Stop using JSRuntime outside SpiderMonkey. r=bz,terrence,fitzgen,kanru

This commit is contained in:
Jan de Mooij 2016-08-11 14:39:22 +02:00
parent 9e5cf920d2
commit 0ad12515f4
83 changed files with 428 additions and 483 deletions

View File

@ -76,7 +76,7 @@ using namespace mozilla::dom;
nsIIOService *nsScriptSecurityManager::sIOService = nullptr;
nsIStringBundle *nsScriptSecurityManager::sStrBundle = nullptr;
JSRuntime *nsScriptSecurityManager::sRuntime = 0;
JSContext *nsScriptSecurityManager::sContext = nullptr;
bool nsScriptSecurityManager::sStrictFileOriginPolicy = true;
///////////////////////////
@ -1413,19 +1413,18 @@ nsresult nsScriptSecurityManager::Init()
//-- Register security check callback in the JS engine
// Currently this is used to control access to function.caller
sRuntime = xpc::GetJSRuntime();
sContext = danger::GetJSContext();
static const JSSecurityCallbacks securityCallbacks = {
ContentSecurityPolicyPermitsJSAction,
JSPrincipalsSubsume,
};
JSContext* cx = JS_GetContext(sRuntime);
MOZ_ASSERT(!JS_GetSecurityCallbacks(cx));
JS_SetSecurityCallbacks(cx, &securityCallbacks);
JS_InitDestroyPrincipalsCallback(cx, nsJSPrincipals::Destroy);
MOZ_ASSERT(!JS_GetSecurityCallbacks(sContext));
JS_SetSecurityCallbacks(sContext, &securityCallbacks);
JS_InitDestroyPrincipalsCallback(sContext, nsJSPrincipals::Destroy);
JS_SetTrustedPrincipals(cx, system);
JS_SetTrustedPrincipals(sContext, system);
return NS_OK;
}
@ -1448,10 +1447,10 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void)
void
nsScriptSecurityManager::Shutdown()
{
if (sRuntime) {
JS_SetSecurityCallbacks(JS_GetContext(sRuntime), nullptr);
JS_SetTrustedPrincipals(JS_GetContext(sRuntime), nullptr);
sRuntime = nullptr;
if (sContext) {
JS_SetSecurityCallbacks(sContext, nullptr);
JS_SetTrustedPrincipals(sContext, nullptr);
sContext = nullptr;
}
NS_IF_RELEASE(sIOService);

View File

@ -148,7 +148,7 @@ private:
static nsIIOService *sIOService;
static nsIStringBundle *sStrBundle;
static JSRuntime *sRuntime;
static JSContext *sContext;
};
namespace mozilla {

View File

@ -29,7 +29,6 @@ using namespace testing;
// GTest fixture class that all of our tests derive from.
struct DevTools : public ::testing::Test {
bool _initialized;
JSRuntime* rt;
JSContext* cx;
JSCompartment* compartment;
JS::Zone* zone;
@ -37,23 +36,19 @@ struct DevTools : public ::testing::Test {
DevTools()
: _initialized(false),
rt(nullptr),
cx(nullptr)
{ }
virtual void SetUp() {
MOZ_ASSERT(!_initialized);
rt = getRuntime();
if (!rt)
cx = getContext();
if (!cx)
return;
MOZ_RELEASE_ASSERT(!cx);
cx = JS_GetContext(rt);
JS_BeginRequest(cx);
global.init(rt, createGlobal());
global.init(cx, createGlobal());
if (!global)
return;
JS_EnterCompartment(cx, global);
@ -64,8 +59,8 @@ struct DevTools : public ::testing::Test {
_initialized = true;
}
JSRuntime* getRuntime() {
return CycleCollectedJSRuntime::Get()->Runtime();
JSContext* getContext() {
return CycleCollectedJSRuntime::Get()->Context();
}
static void reportError(JSContext* cx, const char* message, JSErrorReport* report) {

View File

@ -23,7 +23,7 @@ using mozilla::dom::DOMRequestService;
using mozilla::dom::DOMCursor;
using mozilla::dom::Promise;
using mozilla::dom::AutoJSAPI;
using mozilla::dom::GetJSRuntime;
using mozilla::dom::RootingCx;
DOMRequest::DOMRequest(nsPIDOMWindowInner* aWindow)
: DOMEventTargetHelper(aWindow)
@ -302,7 +302,7 @@ class FireSuccessAsyncTask : public mozilla::Runnable
FireSuccessAsyncTask(DOMRequest* aRequest,
const JS::Value& aResult) :
mReq(aRequest),
mResult(GetJSRuntime(), aResult)
mResult(RootingCx(), aResult)
{
}

View File

@ -293,10 +293,10 @@ GetJSContext()
}
} // namespace danger
JSRuntime*
GetJSRuntime()
js::RootingContext*
RootingCx()
{
return CycleCollectedJSRuntime::Get()->Runtime();
return CycleCollectedJSRuntime::Get()->RootingCx();
}
AutoJSAPI::AutoJSAPI()
@ -590,7 +590,7 @@ AutoJSAPI::ReportException()
nsContentUtils::IsCallerChrome(),
inner ? inner->WindowID() : 0);
if (inner && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) {
DispatchScriptErrorEvent(inner, JS_GetRuntime(cx()), xpcReport, exn);
DispatchScriptErrorEvent(inner, cx(), xpcReport, exn);
} else {
JS::Rooted<JSObject*> stack(cx(),
xpc::FindExceptionStackForConsoleReport(inner, exn));

View File

@ -136,7 +136,7 @@ JSContext* GetJSContext();
} // namespace danger
JSRuntime* GetJSRuntime();
js::RootingContext* RootingCx();
class ScriptSettingsStack;
class ScriptSettingsStackEntry {

View File

@ -2790,7 +2790,10 @@ nsIPrincipal*
nsContentUtils::ObjectPrincipal(JSObject* aObj)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(JS_GetObjectRuntime(aObj) == CycleCollectedJSRuntime::Get()->Runtime());
#ifdef DEBUG
JS::AssertObjectBelongsToCurrentThread(aObj);
#endif
// This is duplicated from nsScriptSecurityManager. We don't call through there
// because the API unnecessarily requires a JSContext for historical reasons.

View File

@ -1711,8 +1711,8 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
return;
}
JSRuntime* rt = CycleCollectedJSRuntime::Get()->Runtime();
JS::Rooted<JSScript*> script(rt);
js::RootingContext* rcx = RootingCx();
JS::Rooted<JSScript*> script(rcx);
nsMessageManagerScriptHolder* holder = sCachedScripts->Get(aURL);
if (holder && holder->WillRunInGlobalScope() == aRunInGlobalScope) {
@ -1725,7 +1725,7 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
shouldCache, &script);
}
JS::Rooted<JSObject*> global(rt, mGlobal->GetJSObject());
JS::Rooted<JSObject*> global(rcx, mGlobal->GetJSObject());
if (global) {
AutoEntryScript aes(global, "message manager script load");
JSContext* cx = aes.cx();

View File

@ -12209,7 +12209,7 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
// Hold strong ref to ourselves while we call the callback.
nsCOMPtr<nsISupports> me(static_cast<nsIDOMWindow *>(this));
ErrorResult rv;
JS::Rooted<JS::Value> ignoredVal(CycleCollectedJSRuntime::Get()->Runtime());
JS::Rooted<JS::Value> ignoredVal(RootingCx());
callback->Call(me, handler->GetArgs(), &ignoredVal, rv, reason);
if (rv.IsUncatchableException()) {
abortIntervalHandler = true;

View File

@ -1531,8 +1531,7 @@ static nsresult
CheckForOutdatedParent(nsINode* aParent, nsINode* aNode)
{
if (JSObject* existingObjUnrooted = aNode->GetWrapper()) {
JSRuntime* runtime = JS_GetObjectRuntime(existingObjUnrooted);
JS::Rooted<JSObject*> existingObj(runtime, existingObjUnrooted);
JS::Rooted<JSObject*> existingObj(RootingCx(), existingObjUnrooted);
AutoJSContext cx;
nsIGlobalObject* global = aParent->OwnerDoc()->GetScopeObject();

View File

@ -188,7 +188,6 @@ static nsScriptNameSpaceManager *gNameSpaceManager;
static PRTime sFirstCollectionTime;
static JSRuntime* sRuntime;
static JSContext* sContext;
static bool sIsInitialized;
@ -246,8 +245,8 @@ FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
return nullptr;
}
JSRuntime* rt = GetJSRuntime();
JS::RootedObject exceptionObject(rt, &exceptionValue.toObject());
js::RootingContext* rcx = RootingCx();
JS::RootedObject exceptionObject(rcx, &exceptionValue.toObject());
JSObject* stackObject = ExceptionStackOrNull(exceptionObject);
if (stackObject) {
return stackObject;
@ -268,7 +267,7 @@ FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
if (!stack) {
return nullptr;
}
JS::RootedValue value(rt);
JS::RootedValue value(rcx);
stack->GetNativeSavedFrame(&value);
if (value.isObject()) {
return &value.toObject();
@ -422,12 +421,12 @@ class ScriptErrorEvent : public Runnable
{
public:
ScriptErrorEvent(nsPIDOMWindowInner* aWindow,
JSRuntime* aRuntime,
JSContext* aContext,
xpc::ErrorReport* aReport,
JS::Handle<JS::Value> aError)
: mWindow(aWindow)
, mReport(aReport)
, mError(aRuntime, aError)
, mError(aContext, aError)
{}
NS_IMETHOD Run() override
@ -496,10 +495,10 @@ bool ScriptErrorEvent::sHandlingScriptError = false;
namespace xpc {
void
DispatchScriptErrorEvent(nsPIDOMWindowInner *win, JSRuntime *rt, xpc::ErrorReport *xpcReport,
DispatchScriptErrorEvent(nsPIDOMWindowInner *win, JSContext *cx, xpc::ErrorReport *xpcReport,
JS::Handle<JS::Value> exception)
{
nsContentUtils::AddScriptRunner(new ScriptErrorEvent(win, rt, xpcReport, exception));
nsContentUtils::AddScriptRunner(new ScriptErrorEvent(win, cx, xpcReport, exception));
}
} /* namespace xpc */
@ -1196,7 +1195,7 @@ nsJSContext::GarbageCollectNow(JS::gcreason::Reason aReason,
sPendingLoadCount = 0;
sLoadingInProgress = false;
if (!nsContentUtils::XPConnect() || !sRuntime) {
if (!nsContentUtils::XPConnect() || !sContext) {
return;
}
@ -2234,7 +2233,6 @@ mozilla::dom::StartupJSEnvironment()
sNeedsFullGC = false;
sNeedsGCAfterCC = false;
gNameSpaceManager = nullptr;
sRuntime = nullptr;
sContext = nullptr;
sIsInitialized = false;
sDidShutdown = false;
@ -2378,13 +2376,11 @@ nsJSContext::EnsureStatics()
MOZ_CRASH();
}
sRuntime = xpc::GetJSRuntime();
if (!sRuntime) {
sContext = danger::GetJSContext();
if (!sContext) {
MOZ_CRASH();
}
sContext = JS_GetContext(sRuntime);
// Let's make sure that our main thread is the same as the xpcom main thread.
MOZ_ASSERT(NS_IsMainThread());

View File

@ -119,7 +119,7 @@ nsScriptLoadRequest::MaybeCancelOffThreadScript()
return;
}
JSContext* cx = JS_GetContext(xpc::GetJSRuntime());
JSContext* cx = danger::GetJSContext();
JS::CancelOffThreadScript(cx, mOffThreadToken);
mOffThreadToken = nullptr;
}

View File

@ -2448,7 +2448,7 @@ ConstructJSImplementation(const char* aContractId,
do_QueryInterface(implISupports);
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
if (gpi) {
JS::Rooted<JS::Value> initReturn(GetJSRuntime());
JS::Rooted<JS::Value> initReturn(RootingCx());
rv = gpi->Init(window, &initReturn);
if (NS_FAILED(rv)) {
aRv.Throw(rv);

View File

@ -489,8 +489,8 @@ struct VerifyTraceProtoAndIfaceCacheCalledTracer : public JS::CallbackTracer
{
bool ok;
explicit VerifyTraceProtoAndIfaceCacheCalledTracer(JSRuntime *rt)
: JS::CallbackTracer(rt), ok(false)
explicit VerifyTraceProtoAndIfaceCacheCalledTracer(JSContext* cx)
: JS::CallbackTracer(cx), ok(false)
{}
void onChild(const JS::GCCellPtr&) override {
@ -3243,8 +3243,7 @@ WrappedJSToDictionary(nsISupports* aObject, T& aDictionary)
{
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(aObject);
NS_ENSURE_TRUE(wrappedObj, false);
JS::Rooted<JSObject*> obj(CycleCollectedJSRuntime::Get()->Runtime(),
wrappedObj->GetJSObject());
JS::Rooted<JSObject*> obj(RootingCx(), wrappedObj->GetJSObject());
NS_ENSURE_TRUE(obj, false);
nsIGlobalObject* global = xpc::NativeGlobal(obj);

View File

@ -3977,7 +3977,7 @@ DeviceStorageRequestManager::Resolve(uint32_t aId, uint64_t aValue,
return NS_OK;
}
JS::RootedValue value(GetJSRuntime(), JS_NumberValue((double)aValue));
JS::RootedValue value(RootingCx(), JS_NumberValue((double)aValue));
return ResolveInternal(i, value);
}

View File

@ -154,7 +154,7 @@ JSEventHandler::HandleEvent(nsIDOMEvent* aEvent)
columnNumber.Construct();
columnNumber.Value() = scriptEvent->Colno();
error.Construct(GetJSRuntime());
error.Construct(RootingCx());
scriptEvent->GetError(&error.Value());
} else {
msgOrEvent.SetAsEvent() = aEvent->InternalDOMEvent();
@ -210,7 +210,7 @@ JSEventHandler::HandleEvent(nsIDOMEvent* aEvent)
MOZ_ASSERT(mTypedHandler.Type() == TypedEventHandler::eNormal);
ErrorResult rv;
RefPtr<EventHandlerNonNull> handler = mTypedHandler.NormalEventHandler();
JS::Rooted<JS::Value> retval(CycleCollectedJSRuntime::Get()->Runtime());
JS::Rooted<JS::Value> retval(RootingCx());
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), &retval, rv);
if (rv.Failed()) {
return rv.StealNSResult();

View File

@ -27,7 +27,7 @@ namespace dom {
PJavaScriptChild*
nsIContentChild::AllocPJavaScriptChild()
{
return NewJavaScriptChild(xpc::GetJSRuntime());
return NewJavaScriptChild(danger::GetJSContext());
}
bool

View File

@ -58,7 +58,7 @@ nsIContentParent::AsContentBridgeParent()
PJavaScriptParent*
nsIContentParent::AllocPJavaScriptParent()
{
return NewJavaScriptParent(xpc::GetJSRuntime());
return NewJavaScriptParent(danger::GetJSContext());
}
bool

View File

@ -336,7 +336,7 @@ RegisterGCCallbacks()
}
// Register a callback to trace wrapped JSObjects.
JSContext* cx = JS_GetContext(xpc::GetJSRuntime());
JSContext* cx = dom::danger::GetJSContext();
if (!JS_AddExtraGCRootsTracer(cx, TraceJSObjWrappers, nullptr)) {
return false;
}
@ -356,7 +356,7 @@ UnregisterGCCallbacks()
MOZ_ASSERT(sCallbackIsRegistered);
// Remove tracing callback.
JSContext* cx = JS_GetContext(xpc::GetJSRuntime());
JSContext* cx = dom::danger::GetJSContext();
JS_RemoveExtraGCRootsTracer(cx, TraceJSObjWrappers, nullptr);
// Remove delayed destruction callback.

View File

@ -743,8 +743,8 @@ private:
operator=(const WorkerThreadContextPrivate&) = delete;
};
JSContext*
InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
bool
InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSContext* aWorkerCx)
{
aWorkerPrivate->AssertIsOnWorkerThread();
NS_ASSERTION(!aWorkerPrivate->GetJSContext(), "Already has a context!");
@ -752,9 +752,7 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
JSSettings settings;
aWorkerPrivate->CopyJSSettings(settings);
JSContext* workerCx = JS_GetContext(aRuntime);
JS::ContextOptionsRef(workerCx) = settings.contextOptions;
JS::ContextOptionsRef(aWorkerCx) = settings.contextOptions;
JSSettings::JSGCSettingsArray& gcSettings = settings.gcSettings;
@ -763,17 +761,17 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
const JSSettings::JSGCSetting& setting = gcSettings[index];
if (setting.IsSet()) {
NS_ASSERTION(setting.value, "Can't handle 0 values!");
JS_SetGCParameter(workerCx, setting.key, setting.value);
JS_SetGCParameter(aWorkerCx, setting.key, setting.value);
}
}
JS_SetNativeStackQuota(workerCx, WORKER_CONTEXT_NATIVE_STACK_LIMIT);
JS_SetNativeStackQuota(aWorkerCx, WORKER_CONTEXT_NATIVE_STACK_LIMIT);
// Security policy:
static const JSSecurityCallbacks securityCallbacks = {
ContentSecurityPolicyAllows
};
JS_SetSecurityCallbacks(workerCx, &securityCallbacks);
JS_SetSecurityCallbacks(aWorkerCx, &securityCallbacks);
// Set up the asm.js cache callbacks
static const JS::AsmJSCacheOps asmJSCacheOps = {
@ -782,22 +780,22 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
AsmJSCacheOpenEntryForWrite,
asmjscache::CloseEntryForWrite
};
JS::SetAsmJSCacheOps(workerCx, &asmJSCacheOps);
JS::SetAsmJSCacheOps(aWorkerCx, &asmJSCacheOps);
if (!JS::InitSelfHostedCode(workerCx)) {
if (!JS::InitSelfHostedCode(aWorkerCx)) {
NS_WARNING("Could not init self-hosted code!");
return nullptr;
return false;
}
JS_SetInterruptCallback(workerCx, InterruptCallback);
JS_SetInterruptCallback(aWorkerCx, InterruptCallback);
js::SetCTypesActivityCallback(workerCx, CTypesActivityCallback);
js::SetCTypesActivityCallback(aWorkerCx, CTypesActivityCallback);
#ifdef JS_GC_ZEAL
JS_SetGCZeal(workerCx, settings.gcZeal, settings.gcZealFrequency);
JS_SetGCZeal(aWorkerCx, settings.gcZeal, settings.gcZealFrequency);
#endif
return workerCx;
return true;
}
static bool
@ -851,12 +849,11 @@ public:
~WorkerJSRuntime()
{
JSRuntime* rt = MaybeRuntime();
if (!rt) {
JSContext* cx = MaybeContext();
if (!cx) {
return; // Initialize() must have failed
}
JSContext* cx = JS_GetContext(rt);
delete static_cast<WorkerThreadContextPrivate*>(JS_GetContextPrivate(cx));
JS_SetContextPrivate(cx, nullptr);
@ -2552,10 +2549,9 @@ WorkerThreadPrimaryRunnable::Run()
return rv;
}
JSRuntime* rt = runtime.Runtime();
JSContext* cx = runtime.Context();
JSContext* cx = InitJSContextForWorker(mWorkerPrivate, rt);
if (!cx) {
if (!InitJSContextForWorker(mWorkerPrivate, cx)) {
// XXX need to fire an error at parent.
NS_ERROR("Failed to create runtime and context!");
return NS_ERROR_FAILURE;
@ -2565,7 +2561,7 @@ WorkerThreadPrimaryRunnable::Run()
#ifdef MOZ_ENABLE_PROFILER_SPS
PseudoStack* stack = mozilla_get_pseudo_stack();
if (stack) {
stack->sampleRuntime(rt);
stack->sampleContext(cx);
}
#endif
@ -2583,7 +2579,7 @@ WorkerThreadPrimaryRunnable::Run()
#ifdef MOZ_ENABLE_PROFILER_SPS
if (stack) {
stack->sampleRuntime(nullptr);
stack->sampleContext(nullptr);
}
#endif
}

View File

@ -508,7 +508,7 @@ public:
mReadyState(0), mUploadEvent(aUploadEvent), mProgressEvent(true),
mLengthComputable(aLengthComputable), mUseCachedArrayBufferResponse(false),
mResponseTextResult(NS_OK), mStatusResult(NS_OK), mResponseResult(NS_OK),
mScopeObj(GetJSRuntime(), aScopeObj)
mScopeObj(RootingCx(), aScopeObj)
{ }
EventRunnable(Proxy* aProxy, bool aUploadEvent, const nsString& aType,
@ -521,7 +521,7 @@ public:
mUploadEvent(aUploadEvent), mProgressEvent(false), mLengthComputable(0),
mUseCachedArrayBufferResponse(false), mResponseTextResult(NS_OK),
mStatusResult(NS_OK), mResponseResult(NS_OK),
mScopeObj(GetJSRuntime(), aScopeObj)
mScopeObj(RootingCx(), aScopeObj)
{ }
private:

View File

@ -384,7 +384,7 @@ txXPCOMExtensionFunctionCall::evaluate(txIEvalContext* aContext,
uint8_t paramCount = methodInfo->GetParamCount();
uint8_t inArgs = paramCount - 1;
JS::Rooted<txParamArrayHolder> invokeParams(mozilla::dom::GetJSRuntime());
JS::Rooted<txParamArrayHolder> invokeParams(mozilla::dom::RootingCx());
if (!invokeParams.get().Init(paramCount)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -480,16 +480,10 @@ XPCShellEnvironment::Init()
// is unbuffered by default
setbuf(stdout, 0);
JSRuntime *rt = xpc::GetJSRuntime();
if (!rt) {
NS_ERROR("failed to get JSRuntime from nsJSRuntimeService!");
return false;
}
mGlobalHolder.init(rt);
AutoSafeJSContext cx;
mGlobalHolder.init(cx);
nsCOMPtr<nsIXPConnect> xpc =
do_GetService(nsIXPConnect::GetCID());
if (!xpc) {

View File

@ -78,13 +78,13 @@ void
GetWrappedCPOWTag(JSObject* obj, nsACString& out);
PJavaScriptParent*
NewJavaScriptParent(JSRuntime* rt);
NewJavaScriptParent(JSContext* cx);
void
ReleaseJavaScriptParent(PJavaScriptParent* parent);
PJavaScriptChild*
NewJavaScriptChild(JSRuntime* rt);
NewJavaScriptChild(JSContext* cx);
void
ReleaseJavaScriptChild(PJavaScriptChild* child);

View File

@ -22,10 +22,10 @@ class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base
typedef WrapperAnswer Answer;
public:
explicit JavaScriptBase(JSRuntime* rt)
: JavaScriptShared(rt),
WrapperOwner(rt),
WrapperAnswer(rt)
explicit JavaScriptBase(JSContext* cx)
: JavaScriptShared(cx),
WrapperOwner(cx),
WrapperAnswer(cx)
{}
virtual ~JavaScriptBase() {}

View File

@ -26,16 +26,15 @@ UpdateChildWeakPointersBeforeSweepingZoneGroup(JSContext* cx, void* data)
static_cast<JavaScriptChild*>(data)->updateWeakPointers();
}
JavaScriptChild::JavaScriptChild(JSRuntime* rt)
: JavaScriptShared(rt),
JavaScriptBase<PJavaScriptChild>(rt)
JavaScriptChild::JavaScriptChild(JSContext* cx)
: JavaScriptShared(cx),
JavaScriptBase<PJavaScriptChild>(cx)
{
}
JavaScriptChild::~JavaScriptChild()
{
JSContext* cx = JS_GetContext(rt_);
JS_RemoveWeakPointerZoneGroupCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup);
JS_RemoveWeakPointerZoneGroupCallback(cx_, UpdateChildWeakPointersBeforeSweepingZoneGroup);
}
bool
@ -46,8 +45,7 @@ JavaScriptChild::init()
if (!WrapperAnswer::init())
return false;
JSContext* cx = JS_GetContext(rt_);
JS_AddWeakPointerZoneGroupCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
JS_AddWeakPointerZoneGroupCallback(cx_, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
return true;
}
@ -68,9 +66,9 @@ JavaScriptChild::scopeForTargetObjects()
}
PJavaScriptChild*
mozilla::jsipc::NewJavaScriptChild(JSRuntime* rt)
mozilla::jsipc::NewJavaScriptChild(JSContext* cx)
{
JavaScriptChild* child = new JavaScriptChild(rt);
JavaScriptChild* child = new JavaScriptChild(cx);
if (!child->init()) {
delete child;
return nullptr;

View File

@ -17,7 +17,7 @@ namespace jsipc {
class JavaScriptChild : public JavaScriptBase<PJavaScriptChild>
{
public:
explicit JavaScriptChild(JSRuntime* rt);
explicit JavaScriptChild(JSContext* cx);
virtual ~JavaScriptChild();
bool init();

View File

@ -30,15 +30,15 @@ TraceParent(JSTracer* trc, void* data)
static_cast<JavaScriptParent*>(data)->trace(trc);
}
JavaScriptParent::JavaScriptParent(JSRuntime* rt)
: JavaScriptShared(rt),
JavaScriptBase<PJavaScriptParent>(rt)
JavaScriptParent::JavaScriptParent(JSContext* cx)
: JavaScriptShared(cx),
JavaScriptBase<PJavaScriptParent>(cx)
{
}
JavaScriptParent::~JavaScriptParent()
{
JS_RemoveExtraGCRootsTracer(JS_GetContext(rt_), TraceParent, this);
JS_RemoveExtraGCRootsTracer(cx_, TraceParent, this);
}
bool
@ -47,7 +47,7 @@ JavaScriptParent::init()
if (!WrapperOwner::init())
return false;
JS_AddExtraGCRootsTracer(JS_GetContext(rt_), TraceParent, this);
JS_AddExtraGCRootsTracer(cx_, TraceParent, this);
return true;
}
@ -190,9 +190,9 @@ JavaScriptParent::CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx)
}
PJavaScriptParent*
mozilla::jsipc::NewJavaScriptParent(JSRuntime* rt)
mozilla::jsipc::NewJavaScriptParent(JSContext* cx)
{
JavaScriptParent* parent = new JavaScriptParent(rt);
JavaScriptParent* parent = new JavaScriptParent(cx);
if (!parent->init()) {
delete parent;
return nullptr;

View File

@ -17,7 +17,7 @@ namespace jsipc {
class JavaScriptParent : public JavaScriptBase<PJavaScriptParent>
{
public:
explicit JavaScriptParent(JSRuntime* rt);
explicit JavaScriptParent(JSContext* cx);
virtual ~JavaScriptParent();
bool init();

View File

@ -132,8 +132,8 @@ bool JavaScriptShared::sLoggingInitialized;
bool JavaScriptShared::sLoggingEnabled;
bool JavaScriptShared::sStackLoggingEnabled;
JavaScriptShared::JavaScriptShared(JSRuntime* rt)
: rt_(rt),
JavaScriptShared::JavaScriptShared(JSContext* cx)
: cx_(cx),
refcount_(1),
nextSerialNumber_(1)
{

View File

@ -130,7 +130,7 @@ class Logging;
class JavaScriptShared : public CPOWManager
{
public:
explicit JavaScriptShared(JSRuntime* rt);
explicit JavaScriptShared(JSContext* cx);
virtual ~JavaScriptShared();
bool init();
@ -183,7 +183,7 @@ class JavaScriptShared : public CPOWManager
virtual JSObject* scopeForTargetObjects() = 0;
protected:
JSRuntime* rt_;
JSContext* cx_;
uintptr_t refcount_;
IdToObjectMap objects_;

View File

@ -21,7 +21,7 @@ namespace jsipc {
class WrapperAnswer : public virtual JavaScriptShared
{
public:
explicit WrapperAnswer(JSRuntime* rt) : JavaScriptShared(rt) {}
explicit WrapperAnswer(JSContext* cx) : JavaScriptShared(cx) {}
bool RecvPreventExtensions(const ObjectId& objId, ReturnStatus* rs);
bool RecvGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,

View File

@ -50,8 +50,8 @@ struct AuxCPOWData
{}
};
WrapperOwner::WrapperOwner(JSRuntime* rt)
: JavaScriptShared(rt),
WrapperOwner::WrapperOwner(JSContext* cx)
: JavaScriptShared(cx),
inactive_(false)
{
}

View File

@ -24,7 +24,7 @@ class WrapperOwner : public virtual JavaScriptShared
mozilla::ipc::IProtocol>::ActorDestroyReason
ActorDestroyReason;
explicit WrapperOwner(JSRuntime* rt);
explicit WrapperOwner(JSContext* cx);
bool init();
// Standard internal methods.

View File

@ -886,13 +886,13 @@ extern JS_PUBLIC_API(bool)
CollectRuntimeStats(JSContext* cx, RuntimeStats* rtStats, ObjectPrivateVisitor* opv, bool anonymize);
extern JS_PUBLIC_API(size_t)
SystemCompartmentCount(JSRuntime* rt);
SystemCompartmentCount(JSContext* cx);
extern JS_PUBLIC_API(size_t)
UserCompartmentCount(JSRuntime* rt);
UserCompartmentCount(JSContext* cx);
extern JS_PUBLIC_API(size_t)
PeakSizeOfTemporary(const JSRuntime* rt);
PeakSizeOfTemporary(const JSContext* cx);
extern JS_PUBLIC_API(bool)
AddSizeOfTab(JSContext* cx, JS::HandleObject obj, mozilla::MallocSizeOf mallocSizeOf,

View File

@ -14,6 +14,7 @@
#include "js/TypeDecls.h"
#include "js/Utility.h"
struct JSContext;
struct JSRuntime;
class JSScript;
@ -89,7 +90,7 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
void* lr;
};
ProfilingFrameIterator(JSRuntime* rt, const RegisterState& state,
ProfilingFrameIterator(JSContext* cx, const RegisterState& state,
uint32_t sampleBufferGen = UINT32_MAX);
~ProfilingFrameIterator();
void operator++();
@ -135,7 +136,7 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
};
JS_FRIEND_API(bool)
IsProfilingEnabledForRuntime(JSRuntime* runtime);
IsProfilingEnabledForContext(JSContext* cx);
/**
* After each sample run, this method should be called with the latest sample
@ -146,7 +147,7 @@ IsProfilingEnabledForRuntime(JSRuntime* runtime);
* JSRuntime for documentation about what these values are used for.
*/
JS_FRIEND_API(void)
UpdateJSRuntimeProfilerSampleBufferGen(JSRuntime* runtime, uint32_t generation,
UpdateJSContextProfilerSampleBufferGen(JSContext* cx, uint32_t generation,
uint32_t lapCount);
struct ForEachProfiledFrameOp
@ -155,7 +156,7 @@ struct ForEachProfiledFrameOp
// lookups on JitcodeGlobalTable.
class MOZ_STACK_CLASS FrameHandle
{
friend JS_PUBLIC_API(void) ForEachProfiledFrame(JSRuntime* rt, void* addr,
friend JS_PUBLIC_API(void) ForEachProfiledFrame(JSContext* cx, void* addr,
ForEachProfiledFrameOp& op);
JSRuntime* rt_;
@ -188,7 +189,7 @@ struct ForEachProfiledFrameOp
};
JS_PUBLIC_API(void)
ForEachProfiledFrame(JSRuntime* rt, void* addr, ForEachProfiledFrameOp& op);
ForEachProfiledFrame(JSContext* cx, void* addr, ForEachProfiledFrameOp& op);
} // namespace JS

View File

@ -188,17 +188,17 @@ class ProfileEntry
};
JS_FRIEND_API(void)
SetRuntimeProfilingStack(JSRuntime* rt, ProfileEntry* stack, uint32_t* size,
SetContextProfilingStack(JSContext* cx, ProfileEntry* stack, uint32_t* size,
uint32_t max);
JS_FRIEND_API(void)
EnableRuntimeProfilingStack(JSRuntime* rt, bool enabled);
EnableContextProfilingStack(JSContext* cx, bool enabled);
JS_FRIEND_API(void)
RegisterRuntimeProfilingEventMarker(JSRuntime* rt, void (*fn)(const char*));
RegisterContextProfilingEventMarker(JSContext* cx, void (*fn)(const char*));
JS_FRIEND_API(jsbytecode*)
ProfilingGetPC(JSRuntime* rt, JSScript* script, void* ip);
ProfilingGetPC(JSContext* cx, JSScript* script, void* ip);
} // namespace js

View File

@ -660,7 +660,7 @@ class MOZ_RAII Rooted : public js::RootedBase<T>
*stack = reinterpret_cast<Rooted<void*>*>(this);
}
inline js::RootedListHeads& rootLists(js::ContextFriendFields* cx) {
inline js::RootedListHeads& rootLists(js::RootingContext* cx) {
return rootLists(reinterpret_cast<JSContext*>(cx));
}
inline js::RootedListHeads& rootLists(JSContext* cx) {
@ -992,7 +992,7 @@ class PersistentRooted : public js::PersistentRootedBase<T>,
return js::PerThreadDataFriendFields::getMainThread(rt)->roots;
}
js::RootLists& rootLists(JSContext* cx) { return rootLists(js::GetRuntime(cx)); }
js::RootLists& rootLists(js::ContextFriendFields* cx) {
js::RootLists& rootLists(js::RootingContext* cx) {
return rootLists(reinterpret_cast<JSContext*>(cx));
}
@ -1095,6 +1095,7 @@ class JS_PUBLIC_API(ObjectPtr)
~ObjectPtr() { MOZ_ASSERT(!value); }
void finalize(JSRuntime* rt);
void finalize(JSContext* cx);
void init(JSObject* obj) { value = obj; }

View File

@ -132,6 +132,7 @@ class JS_PUBLIC_API(CallbackTracer) : public JSTracer
: JSTracer(rt, JSTracer::TracerKindTag::Callback, weakTraceKind),
contextName_(nullptr), contextIndex_(InvalidIndex), contextFunctor_(nullptr)
{}
CallbackTracer(JSContext* cx, WeakMapTraceKind weakTraceKind = TraceWeakMapValues);
// Override these methods to receive notification when an edge is visited
// with the type contained in the callback. The default implementation

View File

@ -1655,7 +1655,7 @@ ReadSPSProfilingStack(JSContext* cx, unsigned argc, Value* vp)
JS::ProfilingFrameIterator::RegisterState state;
uint32_t physicalFrameNo = 0;
const unsigned propAttrs = JSPROP_ENUMERATE;
for (JS::ProfilingFrameIterator i(cx->runtime(), state); !i.done(); ++i, ++physicalFrameNo) {
for (JS::ProfilingFrameIterator i(cx, state); !i.done(); ++i, ++physicalFrameNo) {
MOZ_ASSERT(i.stackAddress() != nullptr);
// Array holding all inline frames in a single physical jit stack frame.

View File

@ -7325,7 +7325,7 @@ CClosure::Create(JSContext* cx,
return nullptr;
}
ClosureInfo* cinfo = cx->new_<ClosureInfo>(JS_GetRuntime(cx));
ClosureInfo* cinfo = cx->new_<ClosureInfo>(cx);
if (!cinfo) {
JS_ReportOutOfMemory(cx);
return nullptr;
@ -7403,10 +7403,9 @@ CClosure::ClosureStub(ffi_cif* cif, void* result, void** args, void* userData)
// Retrieve the essentials from our closure object.
ArgClosure argClosure(cif, result, args, static_cast<ClosureInfo*>(userData));
JSRuntime* rt = argClosure.cinfo->rt;
RootedObject fun(rt, argClosure.cinfo->jsfnObj);
JSContext* cx = argClosure.cinfo->cx;
RootedObject fun(cx, argClosure.cinfo->jsfnObj);
JSContext* cx = JS_GetContext(rt);
js::PrepareScriptEnvironmentAndInvoke(cx, fun, argClosure);
}

View File

@ -317,7 +317,7 @@ struct FunctionInfo
// Parameters necessary for invoking a JS function from a C closure.
struct ClosureInfo
{
JSRuntime* rt;
JSContext* cx;
JS::Heap<JSObject*> closureObj; // CClosure object
JS::Heap<JSObject*> typeObj; // FunctionType describing the C function
JS::Heap<JSObject*> thisObj; // 'this' object to use for the JS function call
@ -327,8 +327,8 @@ struct ClosureInfo
// Anything conditionally freed in the destructor should be initialized to
// nullptr here.
explicit ClosureInfo(JSRuntime* runtime)
: rt(runtime)
explicit ClosureInfo(JSContext* context)
: cx(context)
, errResult(nullptr)
, closure(nullptr)
{}

View File

@ -4,6 +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/. */
#include "jscntxt.h"
#include "jsfriendapi.h"
#include "vm/Runtime.h"
@ -27,9 +28,9 @@ MemProfiler::GetGCHeapProfiler(JSRuntime* runtime)
}
MemProfiler*
MemProfiler::GetMemProfiler(JSRuntime* runtime)
MemProfiler::GetMemProfiler(JSContext* context)
{
return &runtime->gc.mMemProfiler;
return &context->gc.mMemProfiler;
}
void

View File

@ -435,3 +435,7 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing,
}
buf[bufsize - 1] = '\0';
}
JS::CallbackTracer::CallbackTracer(JSContext* cx, WeakMapTraceKind weakTraceKind)
: CallbackTracer(cx->runtime(), weakTraceKind)
{}

View File

@ -1642,17 +1642,17 @@ JS::ForEachProfiledFrameOp::FrameHandle::frameKind() const
}
JS_PUBLIC_API(void)
JS::ForEachProfiledFrame(JSRuntime* rt, void* addr, ForEachProfiledFrameOp& op)
JS::ForEachProfiledFrame(JSContext* cx, void* addr, ForEachProfiledFrameOp& op)
{
js::jit::JitcodeGlobalTable* table = rt->jitRuntime()->getJitcodeGlobalTable();
js::jit::JitcodeGlobalTable* table = cx->jitRuntime()->getJitcodeGlobalTable();
js::jit::JitcodeGlobalEntry& entry = table->lookupInfallible(addr);
// Extract the stack for the entry. Assume maximum inlining depth is <64
const char* labels[64];
uint32_t depth = entry.callStackAtAddr(rt, addr, labels, 64);
uint32_t depth = entry.callStackAtAddr(cx, addr, labels, 64);
MOZ_ASSERT(depth < 64);
for (uint32_t i = depth; i != 0; i--) {
JS::ForEachProfiledFrameOp::FrameHandle handle(rt, entry, addr, labels[i - 1], i - 1);
JS::ForEachProfiledFrameOp::FrameHandle handle(cx, entry, addr, labels[i - 1], i - 1);
op(handle);
}
}

View File

@ -32,7 +32,7 @@ class CCWTestTracer : public JS::CallbackTracer {
JS::TraceKind expectedKind;
CCWTestTracer(JSContext* cx, void** expectedThingp, JS::TraceKind expectedKind)
: JS::CallbackTracer(JS_GetRuntime(cx)),
: JS::CallbackTracer(cx),
okay(true),
numberOfThingsTraced(0),
expectedThingp(expectedThingp),

View File

@ -23,7 +23,7 @@ class TestTracer : public JS::CallbackTracer
bool found;
explicit TestTracer(JSContext* cx)
: JS::CallbackTracer(JS_GetRuntime(cx)),
: JS::CallbackTracer(cx),
found(false)
{ }
};

View File

@ -20,9 +20,9 @@ reset(JSContext* cx)
{
psize = max_stack = 0;
memset(pstack, 0, sizeof(pstack));
cx->runtime()->spsProfiler.stringsReset();
cx->runtime()->spsProfiler.enableSlowAssertions(true);
js::EnableRuntimeProfilingStack(cx->runtime(), true);
cx->spsProfiler.stringsReset();
cx->spsProfiler.enableSlowAssertions(true);
js::EnableContextProfilingStack(cx, true);
}
static const JSClass ptestClass = {
@ -47,14 +47,14 @@ test_fn2(JSContext* cx, unsigned argc, JS::Value* vp)
static bool
enable(JSContext* cx, unsigned argc, JS::Value* vp)
{
js::EnableRuntimeProfilingStack(cx->runtime(), true);
js::EnableContextProfilingStack(cx, true);
return true;
}
static bool
disable(JSContext* cx, unsigned argc, JS::Value* vp)
{
js::EnableRuntimeProfilingStack(cx->runtime(), false);
js::EnableContextProfilingStack(cx, false);
return true;
}
@ -80,7 +80,7 @@ static const JSFunctionSpec ptestFunctions[] = {
static JSObject*
initialize(JSContext* cx)
{
js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 10);
js::SetContextProfilingStack(cx, pstack, &psize, 10);
JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
return JS_InitClass(cx, global, nullptr, &ptestClass, Prof, 0,
nullptr, ptestFunctions, nullptr, nullptr);
@ -126,8 +126,8 @@ BEGIN_TEST(testProfileStrings_isCalledWithInterpreter)
CHECK(max_stack >= 6);
CHECK(psize == 0);
}
js::EnableRuntimeProfilingStack(cx->runtime(), false);
js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 3);
js::EnableContextProfilingStack(cx, false);
js::SetContextProfilingStack(cx, pstack, &psize, 3);
reset(cx);
{
JS::RootedValue rval(cx);
@ -177,8 +177,8 @@ BEGIN_TEST(testProfileStrings_isCalledWithJIT)
CHECK(max_stack >= 8);
}
js::EnableRuntimeProfilingStack(cx->runtime(), false);
js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 3);
js::EnableContextProfilingStack(cx, false);
js::SetContextProfilingStack(cx, pstack, &psize, 3);
reset(cx);
{
/* Limit the size of the stack and make sure we don't overflow */
@ -227,7 +227,7 @@ BEGIN_TEST(testProfileStrings_worksWhenEnabledOnTheFly)
EXEC("function b(p) { p.test_fn(); }");
EXEC("function a() { var p = new Prof(); p.enable(); b(p); }");
reset(cx);
js::EnableRuntimeProfilingStack(cx->runtime(), false);
js::EnableContextProfilingStack(cx, false);
{
/* enable it in the middle of JS and make sure things check out */
JS::RootedValue rval(cx);

View File

@ -559,18 +559,6 @@ JS_EndRequest(JSContext* cx)
StopRequest(cx);
}
JS_PUBLIC_API(JSRuntime*)
JS_GetRuntime(JSContext* cx)
{
return cx->runtime();
}
JS_PUBLIC_API(JSContext*)
JS_GetContext(JSRuntime* rt)
{
return rt->contextFromMainThread();
}
JS_PUBLIC_API(JSContext*)
JS_GetParentContext(JSContext* cx)
{
@ -1942,10 +1930,11 @@ JS_IsNative(JSObject* obj)
return obj->isNative();
}
JS_PUBLIC_API(JSRuntime*)
JS_GetObjectRuntime(JSObject* obj)
JS_PUBLIC_API(void)
JS::AssertObjectBelongsToCurrentThread(JSObject* obj)
{
return obj->compartment()->runtimeFromMainThread();
JSRuntime* rt = obj->compartment()->runtimeFromAnyThread();
MOZ_RELEASE_ASSERT(CurrentThreadCanAccessRuntime(rt));
}

View File

@ -998,9 +998,6 @@ JS_GetContextPrivate(JSContext* cx);
JS_PUBLIC_API(void)
JS_SetContextPrivate(JSContext* cx, void* data);
extern JS_PUBLIC_API(JSRuntime*)
JS_GetRuntime(JSContext* cx);
extern JS_PUBLIC_API(JSContext*)
JS_GetParentContext(JSContext* cx);
@ -1045,16 +1042,6 @@ class MOZ_RAII JSAutoRequest
#endif
};
extern JS_PUBLIC_API(JSRuntime*)
JS_GetRuntime(JSContext* cx);
/**
* Returns the runtime's JSContext. The plan is to expose a single type to the
* API, so this function will likely be removed soon.
*/
extern JS_PUBLIC_API(JSContext*)
JS_GetContext(JSRuntime* rt);
extern JS_PUBLIC_API(JSVersion)
JS_GetVersion(JSContext* cx);
@ -1245,6 +1232,13 @@ ContextOptionsRef(JSContext* cx);
JS_PUBLIC_API(bool)
InitSelfHostedCode(JSContext* cx);
/**
* Asserts (in debug and release builds) that `obj` belongs to the current
* thread's context.
*/
JS_PUBLIC_API(void)
AssertObjectBelongsToCurrentThread(JSObject* obj);
} /* namespace JS */
extern JS_PUBLIC_API(const char*)
@ -2456,9 +2450,6 @@ JS_NewObject(JSContext* cx, const JSClass* clasp);
extern JS_PUBLIC_API(bool)
JS_IsNative(JSObject* obj);
extern JS_PUBLIC_API(JSRuntime*)
JS_GetObjectRuntime(JSObject* obj);
/**
* Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
* proto. If proto is nullptr, the JS object will have `null` as [[Prototype]].

View File

@ -1028,9 +1028,9 @@ struct DumpHeapTracer : public JS::CallbackTracer, public WeakMapTracer
const char* prefix;
FILE* output;
DumpHeapTracer(FILE* fp, JSRuntime* rt)
: JS::CallbackTracer(rt, DoNotTraceWeakMaps),
js::WeakMapTracer(rt), prefix(""), output(fp)
DumpHeapTracer(FILE* fp, JSContext* cx)
: JS::CallbackTracer(cx, DoNotTraceWeakMaps),
js::WeakMapTracer(cx), prefix(""), output(fp)
{}
private:
@ -1167,6 +1167,12 @@ JS::ObjectPtr::finalize(JSRuntime* rt)
value = nullptr;
}
void
JS::ObjectPtr::finalize(JSContext* cx)
{
finalize(cx->runtime());
}
void
JS::ObjectPtr::updateWeakPointerAfterGC()
{

View File

@ -493,9 +493,9 @@ IsAtomsZone(JS::Zone* zone);
struct WeakMapTracer
{
JSRuntime* runtime;
JSContext* context;
explicit WeakMapTracer(JSRuntime* rt) : runtime(rt) {}
explicit WeakMapTracer(JSContext* cx) : context(cx) {}
// Weak map tracer callback, called once for every binding of every
// weak map that was live at the time of the last garbage collection.
@ -2982,7 +2982,7 @@ class MemProfiler
return sActiveProfilerCount > 0;
}
static MemProfiler* GetMemProfiler(JSRuntime* runtime);
static MemProfiler* GetMemProfiler(JSContext* context);
static void SetNativeProfiler(NativeProfiler* aProfiler) {
sNativeProfiler = aProfiler;

View File

@ -321,7 +321,12 @@ class RootLists
void finishPersistentRoots();
};
struct ContextFriendFields
struct RootingContext
{
RootLists roots;
};
struct ContextFriendFields : public RootingContext
{
protected:
JSRuntime* const runtime_;
@ -333,9 +338,6 @@ struct ContextFriendFields
JS::Zone* zone_;
public:
/* Rooting structures. */
RootLists roots;
explicit ContextFriendFields(JSRuntime* rt)
: runtime_(rt), compartment_(nullptr), zone_(nullptr)
{}

View File

@ -225,7 +225,7 @@ WatchpointMap::sweep()
void
WatchpointMap::traceAll(WeakMapTracer* trc)
{
JSRuntime* rt = trc->runtime;
JSRuntime* rt = trc->context;
for (CompartmentsIter comp(rt, SkipAtoms); !comp.done(); comp.next()) {
if (WatchpointMap* wpmap = comp->watchpointMap)
wpmap->trace(trc);

View File

@ -97,7 +97,7 @@ WeakMapBase::sweepZone(JS::Zone* zone)
void
WeakMapBase::traceAllMappings(WeakMapTracer* tracer)
{
JSRuntime* rt = tracer->runtime;
JSRuntime* rt = tracer->context;
for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) {
for (WeakMapBase* m : zone->gcWeakMapList) {
// The WeakMapTracer callback is not allowed to GC.

View File

@ -4525,7 +4525,7 @@ PrintProfilerEvents(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (cx->runtime()->spsProfiler.enabled())
js::RegisterRuntimeProfilingEventMarker(cx->runtime(), &PrintProfilerEvents_Callback);
js::RegisterContextProfilingEventMarker(cx, &PrintProfilerEvents_Callback);
args.rval().setUndefined();
return true;
}
@ -4537,10 +4537,10 @@ Vector<StackChars, 0, SystemAllocPolicy> stacks;
static void
SingleStepCallback(void* arg, jit::Simulator* sim, void* pc)
{
JSRuntime* rt = reinterpret_cast<JSRuntime*>(arg);
JSContext* cx = reinterpret_cast<JSContext*>(arg);
// If profiling is not enabled, don't do anything.
if (!rt->spsProfiler.enabled())
if (!cx->spsProfiler.enabled())
return;
JS::ProfilingFrameIterator::RegisterState state;
@ -4557,7 +4557,7 @@ SingleStepCallback(void* arg, jit::Simulator* sim, void* pc)
StackChars stack;
uint32_t frameNo = 0;
AutoEnterOOMUnsafeRegion oomUnsafe;
for (JS::ProfilingFrameIterator i(rt, state); !i.done(); ++i) {
for (JS::ProfilingFrameIterator i(cx, state); !i.done(); ++i) {
MOZ_ASSERT(i.stackAddress() != nullptr);
MOZ_ASSERT(lastStackAddress <= i.stackAddress());
lastStackAddress = i.stackAddress();
@ -4592,7 +4592,7 @@ EnableSingleStepProfiling(JSContext* cx, unsigned argc, Value* vp)
CallArgs args = CallArgsFromVp(argc, vp);
jit::Simulator* sim = cx->runtime()->simulator();
sim->enable_single_stepping(SingleStepCallback, cx->runtime());
sim->enable_single_stepping(SingleStepCallback, cx);
args.rval().setUndefined();
return true;
@ -4650,13 +4650,13 @@ EnableSPSProfiling(JSContext* cx, unsigned argc, Value* vp)
ShellContext* sc = GetShellContext(cx);
// Disable before re-enabling; see the assertion in |SPSProfiler::setProfilingStack|.
if (cx->runtime()->spsProfiler.installed())
cx->runtime()->spsProfiler.enable(false);
if (cx->spsProfiler.installed())
cx->spsProfiler.enable(false);
SetRuntimeProfilingStack(cx->runtime(), sc->spsProfilingStack, &sc->spsProfilingStackSize,
SetContextProfilingStack(cx, sc->spsProfilingStack, &sc->spsProfilingStackSize,
ShellContext::SpsProfilingMaxStackSize);
cx->runtime()->spsProfiler.enableSlowAssertions(false);
cx->runtime()->spsProfiler.enable(true);
cx->spsProfiler.enableSlowAssertions(false);
cx->spsProfiler.enable(true);
args.rval().setUndefined();
return true;
@ -4670,25 +4670,25 @@ EnableSPSProfilingWithSlowAssertions(JSContext* cx, unsigned argc, Value* vp)
ShellContext* sc = GetShellContext(cx);
if (cx->runtime()->spsProfiler.enabled()) {
if (cx->spsProfiler.enabled()) {
// If profiling already enabled with slow assertions disabled,
// this is a no-op.
if (cx->runtime()->spsProfiler.slowAssertionsEnabled())
if (cx->spsProfiler.slowAssertionsEnabled())
return true;
// Slow assertions are off. Disable profiling before re-enabling
// with slow assertions on.
cx->runtime()->spsProfiler.enable(false);
cx->spsProfiler.enable(false);
}
// Disable before re-enabling; see the assertion in |SPSProfiler::setProfilingStack|.
if (cx->runtime()->spsProfiler.installed())
cx->runtime()->spsProfiler.enable(false);
if (cx->spsProfiler.installed())
cx->spsProfiler.enable(false);
SetRuntimeProfilingStack(cx->runtime(), sc->spsProfilingStack, &sc->spsProfilingStackSize,
SetContextProfilingStack(cx, sc->spsProfilingStack, &sc->spsProfilingStackSize,
ShellContext::SpsProfilingMaxStackSize);
cx->runtime()->spsProfiler.enableSlowAssertions(true);
cx->runtime()->spsProfiler.enable(true);
cx->spsProfiler.enableSlowAssertions(true);
cx->spsProfiler.enable(true);
return true;
}

View File

@ -876,10 +876,10 @@ JS::CollectRuntimeStats(JSContext* cx, RuntimeStats *rtStats, ObjectPrivateVisit
}
JS_PUBLIC_API(size_t)
JS::SystemCompartmentCount(JSRuntime* rt)
JS::SystemCompartmentCount(JSContext* cx)
{
size_t n = 0;
for (CompartmentsIter comp(rt, WithAtoms); !comp.done(); comp.next()) {
for (CompartmentsIter comp(cx, WithAtoms); !comp.done(); comp.next()) {
if (comp->isSystem())
++n;
}
@ -887,10 +887,10 @@ JS::SystemCompartmentCount(JSRuntime* rt)
}
JS_PUBLIC_API(size_t)
JS::UserCompartmentCount(JSRuntime* rt)
JS::UserCompartmentCount(JSContext* cx)
{
size_t n = 0;
for (CompartmentsIter comp(rt, WithAtoms); !comp.done(); comp.next()) {
for (CompartmentsIter comp(cx, WithAtoms); !comp.done(); comp.next()) {
if (!comp->isSystem())
++n;
}
@ -898,9 +898,9 @@ JS::UserCompartmentCount(JSRuntime* rt)
}
JS_PUBLIC_API(size_t)
JS::PeakSizeOfTemporary(const JSRuntime* rt)
JS::PeakSizeOfTemporary(const JSContext* cx)
{
return rt->tempLifoAlloc.peakSizeOfExcludingThis();
return cx->JSRuntime::tempLifoAlloc.peakSizeOfExcludingThis();
}
namespace JS {

View File

@ -887,25 +887,25 @@ js::CurrentThreadCanAccessZone(Zone* zone)
}
JS_FRIEND_API(void)
JS::UpdateJSRuntimeProfilerSampleBufferGen(JSRuntime* runtime, uint32_t generation,
JS::UpdateJSContextProfilerSampleBufferGen(JSContext* cx, uint32_t generation,
uint32_t lapCount)
{
runtime->setProfilerSampleBufferGen(generation);
runtime->updateProfilerSampleBufferLapCount(lapCount);
cx->setProfilerSampleBufferGen(generation);
cx->updateProfilerSampleBufferLapCount(lapCount);
}
JS_FRIEND_API(bool)
JS::IsProfilingEnabledForRuntime(JSRuntime* runtime)
JS::IsProfilingEnabledForContext(JSContext* cx)
{
MOZ_ASSERT(runtime);
return runtime->spsProfiler.enabled();
MOZ_ASSERT(cx);
return cx->spsProfiler.enabled();
}
JSRuntime::IonBuilderList&
JSRuntime::ionLazyLinkList()
{
MOZ_ASSERT(TlsPerThreadData.get()->runtimeFromMainThread(),
"Should only be mutated by the main thread.");
"Should only be mutated by the main thread.");
return ionLazyLinkList_;
}

View File

@ -508,28 +508,28 @@ ProfileEntry::setPC(jsbytecode* pc) volatile
}
JS_FRIEND_API(void)
js::SetRuntimeProfilingStack(JSRuntime* rt, ProfileEntry* stack, uint32_t* size, uint32_t max)
js::SetContextProfilingStack(JSContext* cx, ProfileEntry* stack, uint32_t* size, uint32_t max)
{
rt->spsProfiler.setProfilingStack(stack, size, max);
cx->spsProfiler.setProfilingStack(stack, size, max);
}
JS_FRIEND_API(void)
js::EnableRuntimeProfilingStack(JSRuntime* rt, bool enabled)
js::EnableContextProfilingStack(JSContext* cx, bool enabled)
{
rt->spsProfiler.enable(enabled);
cx->spsProfiler.enable(enabled);
}
JS_FRIEND_API(void)
js::RegisterRuntimeProfilingEventMarker(JSRuntime* rt, void (*fn)(const char*))
js::RegisterContextProfilingEventMarker(JSContext* cx, void (*fn)(const char*))
{
MOZ_ASSERT(rt->spsProfiler.enabled());
rt->spsProfiler.setEventMarker(fn);
MOZ_ASSERT(cx->spsProfiler.enabled());
cx->spsProfiler.setEventMarker(fn);
}
JS_FRIEND_API(jsbytecode*)
js::ProfilingGetPC(JSRuntime* rt, JSScript* script, void* ip)
js::ProfilingGetPC(JSContext* cx, JSScript* script, void* ip)
{
return rt->spsProfiler.ipToPC(script, size_t(ip));
return cx->spsProfiler.ipToPC(script, size_t(ip));
}
AutoSuppressProfilerSampling::AutoSuppressProfilerSampling(JSContext* cx

View File

@ -1719,24 +1719,24 @@ ActivationIterator::settle()
activation_ = activation_->prev();
}
JS::ProfilingFrameIterator::ProfilingFrameIterator(JSRuntime* rt, const RegisterState& state,
JS::ProfilingFrameIterator::ProfilingFrameIterator(JSContext* cx, const RegisterState& state,
uint32_t sampleBufferGen)
: rt_(rt),
: rt_(cx),
sampleBufferGen_(sampleBufferGen),
activation_(nullptr),
savedPrevJitTop_(nullptr)
{
if (!rt->spsProfiler.enabled())
if (!cx->spsProfiler.enabled())
MOZ_CRASH("ProfilingFrameIterator called when spsProfiler not enabled for runtime.");
if (!rt->profilingActivation())
if (!cx->profilingActivation())
return;
// If profiler sampling is not enabled, skip.
if (!rt_->isProfilerSamplingEnabled())
if (!cx->isProfilerSamplingEnabled())
return;
activation_ = rt->profilingActivation();
activation_ = cx->profilingActivation();
MOZ_ASSERT(activation_->isProfiling());

View File

@ -89,7 +89,7 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
{
public:
explicit ModuleEntry(JSContext* aCx)
: mozilla::Module(), obj(JS_GetRuntime(aCx)), thisObjectKey(JS_GetRuntime(aCx))
: mozilla::Module(), obj(aCx), thisObjectKey(aCx)
{
mVersion = mozilla::Module::kVersion;
mCIDs = nullptr;

View File

@ -2614,7 +2614,7 @@ nsXPCComponents_Utils::ClearMaxCCTime()
NS_IMETHODIMP
nsXPCComponents_Utils::ForceShrinkingGC()
{
JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context();
JSContext* cx = dom::danger::GetJSContext();
PrepareForFullGC(cx);
GCForReason(cx, GC_SHRINK, gcreason::COMPONENT_UTILS);
return NS_OK;
@ -2628,9 +2628,7 @@ class PreciseGCRunnable : public Runnable
NS_IMETHOD Run() override
{
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
JSContext* cx = JS_GetContext(rt);
JSContext* cx = dom::danger::GetJSContext();
if (JS_IsRunning(cx))
return NS_DispatchToMainThread(this);

View File

@ -1628,8 +1628,8 @@ ReloadPrefsCallback(const char* pref, void* data)
XPCJSRuntime::~XPCJSRuntime()
{
// Elsewhere we abort immediately if XPCJSRuntime initialization fails.
// Therefore the runtime must be non-null.
MOZ_ASSERT(MaybeRuntime());
// Therefore the context must be non-null.
MOZ_ASSERT(MaybeContext());
// This destructor runs before ~CycleCollectedJSRuntime, which does the
// actual JS_DestroyRuntime() call. But destroying the runtime triggers
@ -1690,7 +1690,7 @@ XPCJSRuntime::~XPCJSRuntime()
#ifdef MOZ_ENABLE_PROFILER_SPS
// Tell the profiler that the runtime is gone
if (PseudoStack* stack = mozilla_get_pseudo_stack())
stack->sampleRuntime(nullptr);
stack->sampleContext(nullptr);
#endif
Preferences::UnregisterCallback(ReloadPrefsCallback, JS_OPTIONS_DOT_STR, this);
@ -1790,12 +1790,6 @@ xpc::GetCurrentCompartmentName(JSContext* cx, nsCString& name)
GetCompartmentName(compartment, name, &anonymizeID, false);
}
JSRuntime*
xpc::GetJSRuntime()
{
return XPCJSRuntime::Get()->Runtime();
}
void
xpc::AddGCCallback(xpcGCCallback cb)
{
@ -1811,7 +1805,7 @@ xpc::RemoveGCCallback(xpcGCCallback cb)
static int64_t
JSMainRuntimeGCHeapDistinguishedAmount()
{
JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context();
JSContext* cx = danger::GetJSContext();
return int64_t(JS_GetGCParameter(cx, JSGC_TOTAL_CHUNKS)) *
js::gc::ChunkSize;
}
@ -1819,22 +1813,22 @@ JSMainRuntimeGCHeapDistinguishedAmount()
static int64_t
JSMainRuntimeTemporaryPeakDistinguishedAmount()
{
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
return JS::PeakSizeOfTemporary(rt);
JSContext* cx = danger::GetJSContext();
return JS::PeakSizeOfTemporary(cx);
}
static int64_t
JSMainRuntimeCompartmentsSystemDistinguishedAmount()
{
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
return JS::SystemCompartmentCount(rt);
JSContext* cx = danger::GetJSContext();
return JS::SystemCompartmentCount(cx);
}
static int64_t
JSMainRuntimeCompartmentsUserDistinguishedAmount()
{
JSRuntime* rt = nsXPConnect::GetRuntimeInstance()->Runtime();
return JS::UserCompartmentCount(rt);
JSContext* cx = nsXPConnect::GetRuntimeInstance()->Context();
return JS::UserCompartmentCount(cx);
}
class JSMainRuntimeTemporaryPeakReporter final : public nsIMemoryReporter
@ -3442,14 +3436,12 @@ XPCJSRuntime::Initialize()
return rv;
}
MOZ_ASSERT(Runtime());
JSRuntime* runtime = Runtime();
MOZ_ASSERT(Context());
JSContext* cx = Context();
JSContext* cx = JS_GetContext(runtime);
mUnprivilegedJunkScope.init(runtime, nullptr);
mPrivilegedJunkScope.init(runtime, nullptr);
mCompilationScope.init(runtime, nullptr);
mUnprivilegedJunkScope.init(cx, nullptr);
mPrivilegedJunkScope.init(cx, nullptr);
mCompilationScope.init(cx, nullptr);
// these jsids filled in later when we have a JSContext to work with.
mStrIDs[0] = JSID_VOID;
@ -3554,7 +3546,7 @@ XPCJSRuntime::Initialize()
js::SetPreserveWrapperCallback(cx, PreserveWrapper);
#ifdef MOZ_ENABLE_PROFILER_SPS
if (PseudoStack* stack = mozilla_get_pseudo_stack())
stack->sampleRuntime(runtime);
stack->sampleContext(cx);
#endif
JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback);
js::SetActivityCallback(cx, ActivityCallback, this);
@ -3618,7 +3610,7 @@ XPCJSRuntime::newXPCJSRuntime()
return nullptr;
}
if (self->Runtime() &&
if (self->Context() &&
self->GetMultiCompartmentWrappedJSMap() &&
self->GetWrappedJSClassMap() &&
self->GetIID2NativeInterfaceMap() &&
@ -3761,7 +3753,6 @@ XPCJSRuntime::DebugDump(int16_t depth)
depth--;
XPC_LOG_ALWAYS(("XPCJSRuntime @ %x", this));
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mJSRuntime @ %x", Runtime()));
XPC_LOG_ALWAYS(("mJSContext @ %x", Context()));
XPC_LOG_ALWAYS(("mWrappedJSClassMap @ %x with %d wrapperclasses(s)",

View File

@ -1247,7 +1247,6 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
{
MOZ_ASSERT(aShellData);
JSRuntime* rt;
JSContext* cx;
int result = 0;
nsresult rv;
@ -1412,21 +1411,15 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
return 1;
}
rt = xpc::GetJSRuntime();
if (!rt) {
printf("failed to get JSRuntime from XPConnect!\n");
return 1;
}
AutoJSAPI jsapi;
jsapi.Init();
cx = jsapi.cx();
// Override the default XPConnect interrupt callback. We could store the
// old one and restore it before shutting down, but there's not really a
// reason to bother.
sScriptedInterruptCallback = new PersistentRootedValue;
sScriptedInterruptCallback->init(rt, UndefinedValue());
AutoJSAPI jsapi;
jsapi.Init();
cx = jsapi.cx();
sScriptedInterruptCallback->init(cx, UndefinedValue());
JS_SetInterruptCallback(cx, XPCShellInterruptCallback);

View File

@ -474,11 +474,11 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
if (mXrayExpandos.initialized())
mXrayExpandos.destroy();
JSRuntime* rt = XPCJSRuntime::Get()->Runtime();
mContentXBLScope.finalize(rt);
JSContext* cx = dom::danger::GetJSContext();
mContentXBLScope.finalize(cx);
for (size_t i = 0; i < mAddonScopes.Length(); i++)
mAddonScopes[i].finalize(rt);
mGlobalJSObject.finalize(rt);
mAddonScopes[i].finalize(cx);
mGlobalJSObject.finalize(cx);
}
// static

View File

@ -408,7 +408,7 @@ CreateGlobalObject(JSContext* cx, const JSClass* clasp, nsIPrincipal* principal,
// TraceProtoAndIfaceCache unless that flag is set.
if (!((const js::Class*)clasp)->isWrappedNative())
{
VerifyTraceProtoAndIfaceCacheCalledTracer trc(JS_GetRuntime(cx));
VerifyTraceProtoAndIfaceCacheCalledTracer trc(cx);
TraceChildren(&trc, GCCellPtr(global.get()));
MOZ_ASSERT(trc.ok, "Trace hook on global needs to call TraceXPCGlobal for XPConnect compartments.");
}

View File

@ -561,7 +561,7 @@ class ErrorReport {
};
void
DispatchScriptErrorEvent(nsPIDOMWindowInner* win, JSRuntime* rt, xpc::ErrorReport* xpcReport,
DispatchScriptErrorEvent(nsPIDOMWindowInner* win, JSContext* cx, xpc::ErrorReport* xpcReport,
JS::Handle<JS::Value> exception);
// Get a stack of the sort that can be passed to
@ -585,9 +585,6 @@ FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
extern void
GetCurrentCompartmentName(JSContext*, nsCString& name);
JSRuntime*
GetJSRuntime();
void AddGCCallback(xpcGCCallback cb);
void RemoveGCCallback(xpcGCCallback cb);

View File

@ -125,13 +125,13 @@ CompartmentName(JSContext* cx, JS::Handle<JSObject*> global, nsAString& name) {
* Generate a unique-to-the-application identifier for a group.
*/
void
GenerateUniqueGroupId(const JSRuntime* rt, uint64_t uid, uint64_t processId, nsAString& groupId) {
uint64_t runtimeId = reinterpret_cast<uintptr_t>(rt);
GenerateUniqueGroupId(const JSContext* cx, uint64_t uid, uint64_t processId, nsAString& groupId) {
uint64_t contextId = reinterpret_cast<uintptr_t>(cx);
groupId.AssignLiteral("process: ");
groupId.AppendInt(processId);
groupId.AppendLiteral(", thread: ");
groupId.AppendInt(runtimeId);
groupId.AppendInt(contextId);
groupId.AppendLiteral(", group: ");
groupId.AppendInt(uid);
}
@ -570,7 +570,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSITIMERCALLBACK
PendingAlertsCollector(JSRuntime* runtime, nsPerformanceStatsService* service)
explicit PendingAlertsCollector(nsPerformanceStatsService* service)
: mService(service)
, mPending(false)
{ }
@ -651,9 +651,9 @@ nsPerformanceStatsService::nsPerformanceStatsService()
#else
, mProcessId(getpid())
#endif
, mRuntime(xpc::GetJSRuntime())
, mContext(mozilla::dom::danger::GetJSContext())
, mUIdCounter(0)
, mTopGroup(nsPerformanceGroup::Make(mRuntime,
, mTopGroup(nsPerformanceGroup::Make(mContext,
this,
NS_LITERAL_STRING("<process>"), // name
NS_LITERAL_STRING(""), // addonid
@ -672,11 +672,11 @@ nsPerformanceStatsService::nsPerformanceStatsService()
, mJankLevelVisibilityThreshold(/* 2 ^ */ 8 /* ms */)
, mMaxExpectedDurationOfInteractionUS(150 * 1000)
{
mPendingAlertsCollector = new PendingAlertsCollector(mRuntime, this);
mPendingAlertsCollector = new PendingAlertsCollector(this);
// Attach some artificial group information to the universal listeners, to aid with debugging.
nsString groupIdForAddons;
GenerateUniqueGroupId(mRuntime, GetNextId(), mProcessId, groupIdForAddons);
GenerateUniqueGroupId(mContext, GetNextId(), mProcessId, groupIdForAddons);
mUniversalTargets.mAddons->
SetTarget(new nsPerformanceGroupDetails(NS_LITERAL_STRING("<universal add-on listener>"),
groupIdForAddons,
@ -687,7 +687,7 @@ nsPerformanceStatsService::nsPerformanceStatsService()
nsString groupIdForWindows;
GenerateUniqueGroupId(mRuntime, GetNextId(), mProcessId, groupIdForWindows);
GenerateUniqueGroupId(mContext, GetNextId(), mProcessId, groupIdForWindows);
mUniversalTargets.mWindows->
SetTarget(new nsPerformanceGroupDetails(NS_LITERAL_STRING("<universal window listener>"),
groupIdForWindows,
@ -728,7 +728,7 @@ nsPerformanceStatsService::Dispose()
}
// Clear up and disconnect from JSAPI.
JSContext* cx = JS_GetContext(mRuntime);
JSContext* cx = mContext;
js::DisposePerformanceMonitoring(cx);
mozilla::Unused << js::SetStopwatchIsMonitoringCPOW(cx, false);
@ -800,7 +800,7 @@ nsPerformanceStatsService::InitInternal()
}
// Connect to JSAPI.
JSContext* cx = JS_GetContext(mRuntime);
JSContext* cx = mContext;
if (!js::SetStopwatchStartCallback(cx, StopwatchStartCallback, this)) {
return NS_ERROR_UNEXPECTED;
}
@ -1067,7 +1067,7 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx,
addonName.Append(addonId);
addonName.AppendLiteral(")");
entry->
SetGroup(nsPerformanceGroup::Make(mRuntime, this,
SetGroup(nsPerformanceGroup::Make(mContext, this,
addonName, addonId, 0,
mProcessId, isSystem,
nsPerformanceGroup::GroupScope::ADDON)
@ -1091,7 +1091,7 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx,
windowName.AppendInt(windowId);
windowName.AppendLiteral(")");
entry->
SetGroup(nsPerformanceGroup::Make(mRuntime, this,
SetGroup(nsPerformanceGroup::Make(mContext, this,
windowName, EmptyString(), windowId,
mProcessId, isSystem,
nsPerformanceGroup::GroupScope::WINDOW)
@ -1105,7 +1105,7 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx,
// All compartments have their own group.
auto group =
nsPerformanceGroup::Make(mRuntime, this,
nsPerformanceGroup::Make(mContext, this,
name, addonId, windowId,
mProcessId, isSystem,
nsPerformanceGroup::GroupScope::COMPARTMENT);
@ -1469,7 +1469,7 @@ nsPerformanceStatsService::UniversalTargets::UniversalTargets()
*/
/*static*/ nsPerformanceGroup*
nsPerformanceGroup::Make(JSRuntime* rt,
nsPerformanceGroup::Make(JSContext* cx,
nsPerformanceStatsService* service,
const nsAString& name,
const nsAString& addonId,
@ -1479,7 +1479,7 @@ nsPerformanceGroup::Make(JSRuntime* rt,
GroupScope scope)
{
nsString groupId;
::GenerateUniqueGroupId(rt, service->GetNextId(), processId, groupId);
::GenerateUniqueGroupId(cx, service->GetNextId(), processId, groupId);
return new nsPerformanceGroup(service, name, groupId, addonId, windowId, processId, isSystem, scope);
}

View File

@ -154,9 +154,9 @@ protected:
const uint64_t mProcessId;
/**
* The JS Runtime for the main thread.
* The JS Context for the main thread.
*/
JSRuntime* const mRuntime;
JSContext* const mContext;
/**
* Generate unique identifiers.
@ -630,7 +630,7 @@ public:
/**
* Construct a performance group.
*
* @param rt The container runtime. Used to generate a unique identifier.
* @param cx The container context. Used to generate a unique identifier.
* @param service The performance service. Used during destruction to
* cleanup the hash tables.
* @param name A name for the group, designed mostly for debugging purposes,
@ -645,7 +645,7 @@ public:
* @param scope the scope of this group.
*/
static nsPerformanceGroup*
Make(JSRuntime* rt,
Make(JSContext* cx,
nsPerformanceStatsService* service,
const nsAString& name,
const nsAString& addonId,

View File

@ -35,6 +35,8 @@
#include "SpecialSystemDirectory.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Services.h"
#include "mozilla/Omnijar.h"
#include "mozilla/Preferences.h"
@ -1219,9 +1221,8 @@ nsXREDirProvider::DoShutdown()
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
// resources which are about to go away in "profile-before-change" are destroyed first.
JSRuntime *rt = xpc::GetJSRuntime();
if (rt) {
JS_GC(JS_GetContext(rt));
if (JSContext* cx = dom::danger::GetJSContext()) {
JS_GC(cx);
}
// Phase 3: Notify observers of a profile change

View File

@ -25,8 +25,6 @@
#include "prtime.h"
#include "xpcprivate.h"
struct JSRuntime;
namespace mozilla {
#define MEMORY_PROFILER_SAMPLE_SIZE 65536
@ -77,9 +75,9 @@ ProfilerImpl::AddBytesSampled(uint32_t aBytes)
NS_IMPL_ISUPPORTS(MemoryProfiler, nsIMemoryProfiler)
PRLock* MemoryProfiler::sLock;
uint32_t MemoryProfiler::sProfileRuntimeCount;
uint32_t MemoryProfiler::sProfileContextCount;
StaticAutoPtr<NativeProfilerImpl> MemoryProfiler::sNativeProfiler;
StaticAutoPtr<JSRuntimeProfilerMap> MemoryProfiler::sJSRuntimeProfilerMap;
StaticAutoPtr<JSContextProfilerMap> MemoryProfiler::sJSContextProfilerMap;
TimeStamp MemoryProfiler::sStartTime;
void
@ -92,9 +90,9 @@ MemoryProfiler::InitOnce()
if (!initialized) {
MallocHook::Initialize();
sLock = PR_NewLock();
sProfileRuntimeCount = 0;
sJSRuntimeProfilerMap = new JSRuntimeProfilerMap();
ClearOnShutdown(&sJSRuntimeProfilerMap);
sProfileContextCount = 0;
sJSContextProfilerMap = new JSContextProfilerMap();
ClearOnShutdown(&sJSContextProfilerMap);
ClearOnShutdown(&sNativeProfiler);
std::srand(PR_Now());
bool ignored;
@ -109,12 +107,12 @@ MemoryProfiler::StartProfiler()
InitOnce();
AutoUseUncensoredAllocator ua;
AutoMPLock lock(sLock);
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
ProfilerForJSRuntime profiler;
if (!sJSRuntimeProfilerMap->Get(runtime, &profiler) ||
JSContext* context = XPCJSRuntime::Get()->Context();
ProfilerForJSContext profiler;
if (!sJSContextProfilerMap->Get(context, &profiler) ||
!profiler.mEnabled) {
if (sProfileRuntimeCount == 0) {
js::EnableRuntimeProfilingStack(runtime, true);
if (sProfileContextCount == 0) {
js::EnableContextProfilingStack(context, true);
if (!sNativeProfiler) {
sNativeProfiler = new NativeProfilerImpl();
}
@ -123,12 +121,12 @@ MemoryProfiler::StartProfiler()
GCHeapProfilerImpl* gp = new GCHeapProfilerImpl();
profiler.mEnabled = true;
profiler.mProfiler = gp;
sJSRuntimeProfilerMap->Put(runtime, profiler);
MemProfiler::GetMemProfiler(runtime)->start(gp);
if (sProfileRuntimeCount == 0) {
sJSContextProfilerMap->Put(context, profiler);
MemProfiler::GetMemProfiler(context)->start(gp);
if (sProfileContextCount == 0) {
MallocHook::Enable(sNativeProfiler);
}
sProfileRuntimeCount++;
sProfileContextCount++;
}
return NS_OK;
}
@ -139,18 +137,18 @@ MemoryProfiler::StopProfiler()
InitOnce();
AutoUseUncensoredAllocator ua;
AutoMPLock lock(sLock);
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
ProfilerForJSRuntime profiler;
if (sJSRuntimeProfilerMap->Get(runtime, &profiler) &&
JSContext* context = XPCJSRuntime::Get()->Context();
ProfilerForJSContext profiler;
if (sJSContextProfilerMap->Get(context, &profiler) &&
profiler.mEnabled) {
MemProfiler::GetMemProfiler(runtime)->stop();
if (--sProfileRuntimeCount == 0) {
MemProfiler::GetMemProfiler(context)->stop();
if (--sProfileContextCount == 0) {
MallocHook::Disable();
MemProfiler::SetNativeProfiler(nullptr);
js::EnableRuntimeProfilingStack(runtime, false);
js::EnableContextProfilingStack(context, false);
}
profiler.mEnabled = false;
sJSRuntimeProfilerMap->Put(runtime, profiler);
sJSContextProfilerMap->Put(context, profiler);
}
return NS_OK;
}
@ -161,15 +159,15 @@ MemoryProfiler::ResetProfiler()
InitOnce();
AutoUseUncensoredAllocator ua;
AutoMPLock lock(sLock);
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
ProfilerForJSRuntime profiler;
if (!sJSRuntimeProfilerMap->Get(runtime, &profiler) ||
JSContext* context = XPCJSRuntime::Get()->Context();
ProfilerForJSContext profiler;
if (!sJSContextProfilerMap->Get(context, &profiler) ||
!profiler.mEnabled) {
delete profiler.mProfiler;
profiler.mProfiler = nullptr;
sJSRuntimeProfilerMap->Put(runtime, profiler);
sJSContextProfilerMap->Put(context, profiler);
}
if (sProfileRuntimeCount == 0) {
if (sProfileContextCount == 0) {
sNativeProfiler = nullptr;
}
return NS_OK;
@ -251,18 +249,18 @@ MemoryProfiler::GetResults(JSContext* cx, JS::MutableHandle<JS::Value> aResult)
InitOnce();
AutoUseUncensoredAllocator ua;
AutoMPLock lock(sLock);
JSRuntime* runtime = XPCJSRuntime::Get()->Runtime();
JSContext* context = XPCJSRuntime::Get()->Context();
// Getting results when the profiler is running is not allowed.
if (sProfileRuntimeCount > 0) {
if (sProfileContextCount > 0) {
return NS_OK;
}
// Return immediately when native profiler does not exist.
if (!sNativeProfiler) {
return NS_OK;
}
// Return immediately when there's no result in current runtime.
ProfilerForJSRuntime profiler;
if (!sJSRuntimeProfilerMap->Get(runtime, &profiler) ||
// Return immediately when there's no result in current context.
ProfilerForJSContext profiler;
if (!sJSContextProfilerMap->Get(context, &profiler) ||
!profiler.mProfiler) {
return NS_OK;
}

View File

@ -22,7 +22,6 @@
#define MEMORY_PROFILER_CONTRACT_ID "@mozilla.org/tools/memory-profiler;1"
struct JSRuntime;
struct PRLock;
namespace mozilla {
@ -30,17 +29,17 @@ namespace mozilla {
class NativeProfilerImpl;
class GCHeapProfilerImpl;
struct ProfilerForJSRuntime
struct ProfilerForJSContext
{
ProfilerForJSRuntime()
ProfilerForJSContext()
: mProfiler(nullptr)
, mEnabled(false)
{}
GCHeapProfilerImpl* mProfiler;
bool mEnabled;
};
using JSRuntimeProfilerMap =
nsDataHashtable<nsClearingPtrHashKey<JSRuntime>, ProfilerForJSRuntime>;
using JSContextProfilerMap =
nsDataHashtable<nsClearingPtrHashKey<JSContext>, ProfilerForJSContext>;
class MemoryProfiler final : public nsIMemoryProfiler
{
@ -53,12 +52,12 @@ private:
~MemoryProfiler() {}
// The accesses to other static member are guarded by sLock and
// sProfileRuntimeCount.
// sProfileContextCount.
static PRLock* sLock;
static uint32_t sProfileRuntimeCount;
static uint32_t sProfileContextCount;
static StaticAutoPtr<NativeProfilerImpl> sNativeProfiler;
static StaticAutoPtr<JSRuntimeProfilerMap> sJSRuntimeProfilerMap;
static StaticAutoPtr<JSContextProfilerMap> sJSContextProfilerMap;
static TimeStamp sStartTime;
};

View File

@ -582,7 +582,7 @@ void GeckoSampler::StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime)
aWriter.End();
}
void GeckoSampler::FlushOnJSShutdown(JSRuntime* aRuntime)
void GeckoSampler::FlushOnJSShutdown(JSContext* aContext)
{
#ifndef SPS_STANDALONE
SetPaused(true);
@ -597,8 +597,8 @@ void GeckoSampler::FlushOnJSShutdown(JSRuntime* aRuntime)
continue;
}
// Thread not profiling the runtime that's going away, skip it.
if (sRegisteredThreads->at(i)->Profile()->GetPseudoStack()->mRuntime != aRuntime) {
// Thread not profiling the context that's going away, skip it.
if (sRegisteredThreads->at(i)->Profile()->GetPseudoStack()->mContext != aContext) {
continue;
}
@ -614,10 +614,10 @@ void GeckoSampler::FlushOnJSShutdown(JSRuntime* aRuntime)
void PseudoStack::flushSamplerOnJSShutdown()
{
#ifndef SPS_STANDALONE
MOZ_ASSERT(mRuntime);
MOZ_ASSERT(mContext);
GeckoSampler* t = tlsTicker.get();
if (t) {
t->FlushOnJSShutdown(mRuntime);
t->FlushOnJSShutdown(mContext);
}
#endif
}
@ -671,7 +671,7 @@ void addPseudoEntry(volatile StackEntry &entry, ThreadProfile &aProfile,
MOZ_ASSERT(&entry == &stack->mStack[stack->stackSize() - 1]);
// If stack-walking was disabled, then that's just unfortunate
if (lastpc) {
jsbytecode *jspc = js::ProfilingGetPC(stack->mRuntime, entry.script(),
jsbytecode *jspc = js::ProfilingGetPC(stack->mContext, entry.script(),
lastpc);
if (jspc) {
lineno = JS_PCToLineNumber(entry.script(), jspc);
@ -755,7 +755,7 @@ void mergeStacksIntoProfile(ThreadProfile& aProfile, TickSample* aSample, Native
#ifndef SPS_STANDALONE
JS::ProfilingFrameIterator::Frame jsFrames[1000];
// Only walk jit stack if profiling frame iterator is turned on.
if (pseudoStack->mRuntime && JS::IsProfilingEnabledForRuntime(pseudoStack->mRuntime)) {
if (pseudoStack->mContext && JS::IsProfilingEnabledForContext(pseudoStack->mContext)) {
AutoWalkJSStack autoWalkJSStack;
const uint32_t maxFrames = mozilla::ArrayLength(jsFrames);
@ -767,7 +767,7 @@ void mergeStacksIntoProfile(ThreadProfile& aProfile, TickSample* aSample, Native
registerState.lr = aSample->lr;
#endif
JS::ProfilingFrameIterator jsIter(pseudoStack->mRuntime,
JS::ProfilingFrameIterator jsIter(pseudoStack->mContext,
registerState,
startBufferGen);
for (; jsCount < maxFrames && !jsIter.done(); ++jsIter) {
@ -916,14 +916,14 @@ void mergeStacksIntoProfile(ThreadProfile& aProfile, TickSample* aSample, Native
}
#ifndef SPS_STANDALONE
// Update the JS runtime with the current profile sample buffer generation.
// Update the JS context with the current profile sample buffer generation.
//
// Do not do this for synchronous sampling, which create their own
// ProfileBuffers.
if (!aSample->isSamplingCurrentThread && pseudoStack->mRuntime) {
if (!aSample->isSamplingCurrentThread && pseudoStack->mContext) {
MOZ_ASSERT(aProfile.bufferGeneration() >= startBufferGen);
uint32_t lapCount = aProfile.bufferGeneration() - startBufferGen;
JS::UpdateJSRuntimeProfilerSampleBufferGen(pseudoStack->mRuntime,
JS::UpdateJSContextProfilerSampleBufferGen(pseudoStack->mContext,
aProfile.bufferGeneration(),
lapCount);
}

View File

@ -110,7 +110,7 @@ class GeckoSampler: public Sampler {
virtual void ToJSObjectAsync(double aSinceTime = 0, mozilla::dom::Promise* aPromise = 0);
void StreamMetaJSCustomObject(SpliceableJSONWriter& aWriter);
void StreamTaskTracer(SpliceableJSONWriter& aWriter);
void FlushOnJSShutdown(JSRuntime* aRuntime);
void FlushOnJSShutdown(JSContext* aContext);
bool ProfileJS() const { return mProfileJS; }
bool ProfileJava() const { return mProfileJava; }
bool ProfileGPU() const { return mProfileGPU; }

View File

@ -22,7 +22,7 @@ public:
void addTag(const ProfileEntry& aTag);
void StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
JSRuntime* rt, UniqueStacks& aUniqueStacks);
JSContext* cx, UniqueStacks& aUniqueStacks);
void StreamMarkersToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
UniqueStacks& aUniqueStacks);
void DuplicateLastSample(int aThreadId);

View File

@ -385,8 +385,8 @@ UniqueStacks::Stack UniqueStacks::BeginStack(const OnStackFrameKey& aRoot)
return Stack(*this, aRoot);
}
UniqueStacks::UniqueStacks(JSRuntime* aRuntime)
: mRuntime(aRuntime)
UniqueStacks::UniqueStacks(JSContext* aContext)
: mContext(aContext)
, mFrameCount(0)
{
mFrameTableWriter.StartBareList();
@ -568,7 +568,7 @@ void UniqueStacks::StreamFrame(const OnStackFrameKey& aFrame)
}
mFrameTableWriter.EndArray();
JS::Rooted<JSScript*> script(mRuntime);
JS::Rooted<JSScript*> script(mContext);
jsbytecode* pc;
mFrameTableWriter.StartObjectProperty("attempts");
{
@ -657,7 +657,7 @@ static void WriteSample(SpliceableJSONWriter& aWriter, ProfileSample& aSample)
}
void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
double aSinceTime, JSRuntime* aRuntime,
double aSinceTime, JSContext* aContext,
UniqueStacks& aUniqueStacks)
{
Maybe<ProfileSample> sample;
@ -775,7 +775,7 @@ void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThre
unsigned depth = aUniqueStacks.LookupJITFrameDepth(pc);
if (depth == 0) {
StreamJSFramesOp framesOp(pc, stack);
JS::ForEachProfiledFrame(aRuntime, pc, framesOp);
JS::ForEachProfiledFrame(aContext, pc, framesOp);
aUniqueStacks.AddJITFrameDepth(pc, framesOp.depth());
} else {
for (unsigned i = 0; i < depth; i++) {

View File

@ -265,7 +265,7 @@ public:
StackKey mStack;
};
explicit UniqueStacks(JSRuntime* aRuntime);
explicit UniqueStacks(JSContext* aContext);
Stack BeginStack(const OnStackFrameKey& aRoot);
uint32_t LookupJITFrameDepth(void* aAddr);
@ -283,7 +283,7 @@ public:
UniqueJSONStrings mUniqueStrings;
private:
JSRuntime* mRuntime;
JSContext* mContext;
// To avoid incurring JitcodeGlobalTable lookup costs for every JIT frame,
// we cache the depth of frames keyed by JIT code address. If an address a

View File

@ -48,7 +48,7 @@ void ThreadProfile::StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime)
// mUniqueStacks may already be emplaced from FlushSamplesAndMarkers.
if (!mUniqueStacks.isSome()) {
#ifndef SPS_STANDALONE
mUniqueStacks.emplace(mPseudoStack->mRuntime);
mUniqueStacks.emplace(mPseudoStack->mContext);
#else
mUniqueStacks.emplace(nullptr);
#endif
@ -150,7 +150,7 @@ void ThreadProfile::StreamSamplesAndMarkers(SpliceableJSONWriter& aWriter, doubl
}
mBuffer->StreamSamplesToJSON(aWriter, mThreadId, aSinceTime,
#ifndef SPS_STANDALONE
mPseudoStack->mRuntime,
mPseudoStack->mContext,
#else
nullptr,
#endif
@ -186,8 +186,8 @@ void ThreadProfile::StreamSamplesAndMarkers(SpliceableJSONWriter& aWriter, doubl
void ThreadProfile::FlushSamplesAndMarkers()
{
// This function is used to serialize the current buffer just before
// JSRuntime destruction.
MOZ_ASSERT(mPseudoStack->mRuntime);
// JSContext destruction.
MOZ_ASSERT(mPseudoStack->mContext);
// Unlike StreamJSObject, do not surround the samples in brackets by calling
// aWriter.{Start,End}BareList. The result string will be a comma-separated
@ -197,7 +197,7 @@ void ThreadProfile::FlushSamplesAndMarkers()
// Note that the UniqueStacks instance is persisted so that the frame-index
// mapping is stable across JS shutdown.
#ifndef SPS_STANDALONE
mUniqueStacks.emplace(mPseudoStack->mRuntime);
mUniqueStacks.emplace(mPseudoStack->mContext);
#else
mUniqueStacks.emplace(nullptr);
#endif
@ -208,7 +208,7 @@ void ThreadProfile::FlushSamplesAndMarkers()
{
mBuffer->StreamSamplesToJSON(b, mThreadId, /* aSinceTime = */ 0,
#ifndef SPS_STANDALONE
mPseudoStack->mRuntime,
mPseudoStack->mContext,
#else
nullptr,
#endif
@ -228,7 +228,7 @@ void ThreadProfile::FlushSamplesAndMarkers()
mSavedStreamedMarkers = b.WriteFunc()->CopyData();
}
// Reset the buffer. Attempting to symbolicate JS samples after mRuntime has
// Reset the buffer. Attempting to symbolicate JS samples after mContext has
// gone away will crash.
mBuffer->reset();
}

View File

@ -315,23 +315,23 @@ public:
return sMin(mStackPointer, mozilla::sig_safe_t(mozilla::ArrayLength(mStack)));
}
void sampleRuntime(JSRuntime* runtime) {
void sampleContext(JSContext* context) {
#ifndef SPS_STANDALONE
if (mRuntime && !runtime) {
if (mContext && !context) {
// On JS shut down, flush the current buffer as stringifying JIT samples
// requires a live JSRuntime.
// requires a live JSContext.
flushSamplerOnJSShutdown();
}
mRuntime = runtime;
mContext = context;
if (!runtime) {
if (!context) {
return;
}
static_assert(sizeof(mStack[0]) == sizeof(js::ProfileEntry),
"mStack must be binary compatible with js::ProfileEntry.");
js::SetRuntimeProfilingStack(runtime,
js::SetContextProfilingStack(context,
(js::ProfileEntry*) mStack,
(uint32_t*) &mStackPointer,
(uint32_t) mozilla::ArrayLength(mStack));
@ -341,9 +341,9 @@ public:
}
#ifndef SPS_STANDALONE
void enableJSSampling() {
if (mRuntime) {
js::EnableRuntimeProfilingStack(mRuntime, true);
js::RegisterRuntimeProfilingEventMarker(mRuntime, &ProfilerJSEventMarker);
if (mContext) {
js::EnableContextProfilingStack(mContext, true);
js::RegisterContextProfilingEventMarker(mContext, &ProfilerJSEventMarker);
mStartJSSampling = false;
} else {
mStartJSSampling = true;
@ -355,8 +355,8 @@ public:
}
void disableJSSampling() {
mStartJSSampling = false;
if (mRuntime)
js::EnableRuntimeProfilingStack(mRuntime, false);
if (mContext)
js::EnableContextProfilingStack(mContext, false);
}
#endif
@ -372,7 +372,7 @@ public:
, mSleeping(false)
, mRefCnt(1)
#ifndef SPS_STANDALONE
, mRuntime(nullptr)
, mContext(nullptr)
#endif
, mStartJSSampling(false)
, mPrivacyMode(false)
@ -414,8 +414,8 @@ public:
public:
#ifndef SPS_STANDALONE
// The runtime which is being sampled
JSRuntime *mRuntime;
// The context which is being sampled
JSContext *mContext;
#endif
// Start JS Profiling when possible
bool mStartJSSampling;

View File

@ -128,9 +128,9 @@ public:
struct NoteWeakMapChildrenTracer : public JS::CallbackTracer
{
NoteWeakMapChildrenTracer(JSRuntime* aRt,
NoteWeakMapChildrenTracer(JSContext* aCx,
nsCycleCollectionNoteRootCallback& aCb)
: JS::CallbackTracer(aRt), mCb(aCb), mTracedAny(false), mMap(nullptr),
: JS::CallbackTracer(aCx), mCb(aCb), mTracedAny(false), mMap(nullptr),
mKey(nullptr), mKeyDelegate(nullptr)
{
}
@ -163,8 +163,8 @@ NoteWeakMapChildrenTracer::onChild(const JS::GCCellPtr& aThing)
struct NoteWeakMapsTracer : public js::WeakMapTracer
{
NoteWeakMapsTracer(JSRuntime* aRt, nsCycleCollectionNoteRootCallback& aCccb)
: js::WeakMapTracer(aRt), mCb(aCccb), mChildTracer(aRt, aCccb)
NoteWeakMapsTracer(JSContext* aCx, nsCycleCollectionNoteRootCallback& aCccb)
: js::WeakMapTracer(aCx), mCb(aCccb), mChildTracer(aCx, aCccb)
{
}
void trace(JSObject* aMap, JS::GCCellPtr aKey, JS::GCCellPtr aValue) override;
@ -227,8 +227,8 @@ NoteWeakMapsTracer::trace(JSObject* aMap, JS::GCCellPtr aKey,
// This is based on the logic in FixWeakMappingGrayBitsTracer::trace.
struct FixWeakMappingGrayBitsTracer : public js::WeakMapTracer
{
explicit FixWeakMappingGrayBitsTracer(JSRuntime* aRt)
: js::WeakMapTracer(aRt)
explicit FixWeakMappingGrayBitsTracer(JSContext* aCx)
: js::WeakMapTracer(aCx)
{
}
@ -325,8 +325,8 @@ JSZoneParticipant::Traverse(void* aPtr, nsCycleCollectionTraversalCallback& aCb)
struct TraversalTracer : public JS::CallbackTracer
{
TraversalTracer(JSRuntime* aRt, nsCycleCollectionTraversalCallback& aCb)
: JS::CallbackTracer(aRt, DoNotTraceWeakMaps), mCb(aCb)
TraversalTracer(JSContext* aCx, nsCycleCollectionTraversalCallback& aCb)
: JS::CallbackTracer(aCx, DoNotTraceWeakMaps), mCb(aCb)
{
}
void onChild(const JS::GCCellPtr& aThing) override;
@ -437,7 +437,6 @@ mozilla::GetBuildId(JS::BuildIdCharVector* aBuildID)
CycleCollectedJSRuntime::CycleCollectedJSRuntime()
: mGCThingCycleCollectorGlobal(sGCThingCycleCollectorGlobal)
, mJSZoneCycleCollectorGlobal(sJSZoneCycleCollectorGlobal)
, mJSRuntime(nullptr)
, mJSContext(nullptr)
, mPrevGCSliceCallback(nullptr)
, mPrevGCNurseryCollectionCallback(nullptr)
@ -454,7 +453,7 @@ CycleCollectedJSRuntime::CycleCollectedJSRuntime()
CycleCollectedJSRuntime::~CycleCollectedJSRuntime()
{
// If the allocation failed, here we are.
if (!mJSRuntime) {
if (!mJSContext) {
return;
}
@ -479,7 +478,6 @@ CycleCollectedJSRuntime::~CycleCollectedJSRuntime()
#endif // SPIDERMONKEY_PROMISE
JS_DestroyContext(mJSContext);
mJSRuntime = nullptr;
mJSContext = nullptr;
nsCycleCollector_forgetJSRuntime();
@ -511,7 +509,6 @@ CycleCollectedJSRuntime::Initialize(JSContext* aParentContext,
if (!mJSContext) {
return NS_ERROR_OUT_OF_MEMORY;
}
mJSRuntime = JS_GetRuntime(mJSContext);
if (!JS_AddExtraGCRootsTracer(mJSContext, TraceBlackJS, this)) {
MOZ_CRASH("JS_AddExtraGCRootsTracer failed");
@ -552,8 +549,8 @@ CycleCollectedJSRuntime::Initialize(JSContext* aParentContext,
#ifdef SPIDERMONKEY_PROMISE
JS::SetEnqueuePromiseJobCallback(mJSContext, EnqueuePromiseJobCallback, this);
JS::SetPromiseRejectionTrackerCallback(mJSContext, PromiseRejectionTrackerCallback, this);
mUncaughtRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
mConsumedRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
mUncaughtRejections.init(mJSContext, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
mConsumedRejections.init(mJSContext, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
#endif // SPIDERMONKEY_PROMISE
JS::dbg::SetDebuggerMallocSizeOf(mJSContext, moz_malloc_size_of);
@ -631,8 +628,8 @@ void
CycleCollectedJSRuntime::NoteGCThingJSChildren(JS::GCCellPtr aThing,
nsCycleCollectionTraversalCallback& aCb) const
{
MOZ_ASSERT(mJSRuntime);
TraversalTracer trc(mJSRuntime, aCb);
MOZ_ASSERT(mJSContext);
TraversalTracer trc(mJSContext, aCb);
JS::TraceChildren(&trc, aThing);
}
@ -710,7 +707,7 @@ void
CycleCollectedJSRuntime::TraverseZone(JS::Zone* aZone,
nsCycleCollectionTraversalCallback& aCb)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
/*
* We treat the zone as being gray. We handle non-gray GCthings in the
@ -732,7 +729,7 @@ CycleCollectedJSRuntime::TraverseZone(JS::Zone* aZone,
* iterate over. Edges between compartments in the same zone will add
* unnecessary loop edges to the graph (bug 842137).
*/
TraversalTracer trc(mJSRuntime, aCb);
TraversalTracer trc(mJSContext, aCb);
js::VisitGrayWrapperTargets(aZone, NoteJSChildGrayWrapperShim, &trc);
/*
@ -906,7 +903,7 @@ CycleCollectedJSRuntime::OutOfMemoryCallback(JSContext* aContext,
{
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
MOZ_ASSERT(JS_GetRuntime(aContext) == self->Runtime());
MOZ_ASSERT(aContext == self->Context());
self->OnOutOfMemory();
}
@ -967,7 +964,7 @@ CycleCollectedJSRuntime::EnqueuePromiseJobCallback(JSContext* aCx,
void* aData)
{
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
MOZ_ASSERT(JS_GetRuntime(aCx) == self->Runtime());
MOZ_ASSERT(aCx == self->Context());
MOZ_ASSERT(Get() == self);
nsIGlobalObject* global = nullptr;
@ -990,7 +987,7 @@ CycleCollectedJSRuntime::PromiseRejectionTrackerCallback(JSContext* aCx,
#ifdef DEBUG
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
#endif // DEBUG
MOZ_ASSERT(JS_GetRuntime(aCx) == self->Runtime());
MOZ_ASSERT(aCx == self->Context());
MOZ_ASSERT(Get() == self);
if (state == PromiseRejectionHandlingState::Unhandled) {
@ -1056,7 +1053,7 @@ mozilla::TraceScriptHolder(nsISupports* aHolder, JSTracer* aTracer)
void
CycleCollectedJSRuntime::TraceNativeGrayRoots(JSTracer* aTracer)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
// NB: This is here just to preserve the existing XPConnect order. I doubt it
// would hurt to do this after the JS holders.
@ -1072,7 +1069,7 @@ CycleCollectedJSRuntime::TraceNativeGrayRoots(JSTracer* aTracer)
void
CycleCollectedJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
mJSHolders.Put(aHolder, aTracer);
}
@ -1123,7 +1120,7 @@ struct ClearJSHolder : public TraceCallbacks
void
CycleCollectedJSRuntime::RemoveJSHolder(void* aHolder)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
nsScriptObjectTracer* tracer = mJSHolders.Get(aHolder);
if (!tracer) {
@ -1137,7 +1134,7 @@ CycleCollectedJSRuntime::RemoveJSHolder(void* aHolder)
bool
CycleCollectedJSRuntime::IsJSHolder(void* aHolder)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
return mJSHolders.Get(aHolder, nullptr);
}
@ -1150,7 +1147,7 @@ AssertNoGcThing(JS::GCCellPtr aGCThing, const char* aName, void* aClosure)
void
CycleCollectedJSRuntime::AssertNoObjectsToTrace(void* aPossibleJSHolder)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
nsScriptObjectTracer* tracer = mJSHolders.Get(aPossibleJSHolder);
if (tracer) {
@ -1162,7 +1159,7 @@ CycleCollectedJSRuntime::AssertNoObjectsToTrace(void* aPossibleJSHolder)
already_AddRefed<nsIException>
CycleCollectedJSRuntime::GetPendingException() const
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
nsCOMPtr<nsIException> out = mPendingException;
return out.forget();
@ -1171,46 +1168,46 @@ CycleCollectedJSRuntime::GetPendingException() const
void
CycleCollectedJSRuntime::SetPendingException(nsIException* aException)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
mPendingException = aException;
}
std::queue<nsCOMPtr<nsIRunnable>>&
CycleCollectedJSRuntime::GetPromiseMicroTaskQueue()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
return mPromiseMicroTaskQueue;
}
std::queue<nsCOMPtr<nsIRunnable>>&
CycleCollectedJSRuntime::GetDebuggerPromiseMicroTaskQueue()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
return mDebuggerPromiseMicroTaskQueue;
}
nsCycleCollectionParticipant*
CycleCollectedJSRuntime::GCThingParticipant()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
return &mGCThingCycleCollectorGlobal;
}
nsCycleCollectionParticipant*
CycleCollectedJSRuntime::ZoneParticipant()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
return &mJSZoneCycleCollectorGlobal;
}
nsresult
CycleCollectedJSRuntime::TraverseRoots(nsCycleCollectionNoteRootCallback& aCb)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
TraverseNativeRoots(aCb);
NoteWeakMapsTracer trc(mJSRuntime, aCb);
NoteWeakMapsTracer trc(mJSContext, aCb);
js::TraceWeakMaps(&trc);
return NS_OK;
@ -1225,10 +1222,10 @@ CycleCollectedJSRuntime::UsefulToMergeZones() const
void
CycleCollectedJSRuntime::FixWeakMappingGrayBits() const
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
MOZ_ASSERT(!JS::IsIncrementalGCInProgress(mJSContext),
"Don't call FixWeakMappingGrayBits during a GC.");
FixWeakMappingGrayBitsTracer fixer(mJSRuntime);
FixWeakMappingGrayBitsTracer fixer(mJSContext);
fixer.FixAll();
}
@ -1242,7 +1239,7 @@ CycleCollectedJSRuntime::AreGCGrayBitsValid() const
void
CycleCollectedJSRuntime::GarbageCollect(uint32_t aReason) const
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
MOZ_ASSERT(aReason < JS::gcreason::NUM_REASONS);
JS::gcreason::Reason gcreason = static_cast<JS::gcreason::Reason>(aReason);
@ -1254,7 +1251,7 @@ CycleCollectedJSRuntime::GarbageCollect(uint32_t aReason) const
void
CycleCollectedJSRuntime::JSObjectsTenured()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
for (auto iter = mNurseryObjects.Iter(); !iter.Done(); iter.Next()) {
nsWrapperCache* cache = iter.Get();
@ -1280,7 +1277,7 @@ for (auto iter = mPreservedNurseryObjects.Iter(); !iter.Done(); iter.Next()) {
void
CycleCollectedJSRuntime::NurseryWrapperAdded(nsWrapperCache* aCache)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
MOZ_ASSERT(aCache);
MOZ_ASSERT(aCache->GetWrapperPreserveColor());
MOZ_ASSERT(!JS::ObjectIsTenured(aCache->GetWrapperPreserveColor()));
@ -1290,10 +1287,10 @@ CycleCollectedJSRuntime::NurseryWrapperAdded(nsWrapperCache* aCache)
void
CycleCollectedJSRuntime::NurseryWrapperPreserved(JSObject* aWrapper)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
mPreservedNurseryObjects.InfallibleAppend(
JS::PersistentRooted<JSObject*>(mJSRuntime, aWrapper));
JS::PersistentRooted<JSObject*>(mJSContext, aWrapper));
}
void
@ -1301,7 +1298,7 @@ CycleCollectedJSRuntime::DeferredFinalize(DeferredFinalizeAppendFunction aAppend
DeferredFinalizeFunction aFunc,
void* aThing)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
void* thingArray = nullptr;
bool hadThingArray = mDeferredFinalizerTable.Get(aFunc, &thingArray);
@ -1315,7 +1312,7 @@ CycleCollectedJSRuntime::DeferredFinalize(DeferredFinalizeAppendFunction aAppend
void
CycleCollectedJSRuntime::DeferredFinalize(nsISupports* aSupports)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
typedef DeferredFinalizerImpl<nsISupports> Impl;
DeferredFinalize(Impl::AppendDeferredFinalizePointer, Impl::DeferredFinalize,
@ -1331,7 +1328,7 @@ CycleCollectedJSRuntime::DumpJSHeap(FILE* aFile)
void
CycleCollectedJSRuntime::ProcessStableStateQueue()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
MOZ_RELEASE_ASSERT(!mDoingStableStates);
mDoingStableStates = true;
@ -1347,7 +1344,7 @@ CycleCollectedJSRuntime::ProcessStableStateQueue()
void
CycleCollectedJSRuntime::ProcessMetastableStateQueue(uint32_t aRecursionDepth)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
MOZ_RELEASE_ASSERT(!mDoingStableStates);
mDoingStableStates = true;
@ -1378,7 +1375,7 @@ CycleCollectedJSRuntime::ProcessMetastableStateQueue(uint32_t aRecursionDepth)
void
CycleCollectedJSRuntime::AfterProcessTask(uint32_t aRecursionDepth)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
// See HTML 6.1.4.2 Processing model
@ -1401,14 +1398,14 @@ CycleCollectedJSRuntime::AfterProcessTask(uint32_t aRecursionDepth)
void
CycleCollectedJSRuntime::AfterProcessMicrotask()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
AfterProcessMicrotask(RecursionDepth());
}
void
CycleCollectedJSRuntime::AfterProcessMicrotask(uint32_t aRecursionDepth)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
// Between microtasks, execute any events that were waiting for a microtask
// to complete.
@ -1424,14 +1421,14 @@ CycleCollectedJSRuntime::RecursionDepth()
void
CycleCollectedJSRuntime::RunInStableState(already_AddRefed<nsIRunnable>&& aRunnable)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
mStableStateEvents.AppendElement(Move(aRunnable));
}
void
CycleCollectedJSRuntime::RunInMetastableState(already_AddRefed<nsIRunnable>&& aRunnable)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
RunInMetastableStateData data;
data.mRunnable = aRunnable;
@ -1558,7 +1555,7 @@ IncrementalFinalizeRunnable::Run()
void
CycleCollectedJSRuntime::FinalizeDeferredThings(DeferredFinalizeType aType)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
/*
* If the previous GC created a runnable to finalize objects
@ -1598,7 +1595,7 @@ void
CycleCollectedJSRuntime::AnnotateAndSetOutOfMemory(OOMState* aStatePtr,
OOMState aNewState)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
*aStatePtr = aNewState;
#ifdef MOZ_CRASHREPORTER
@ -1616,7 +1613,7 @@ CycleCollectedJSRuntime::AnnotateAndSetOutOfMemory(OOMState* aStatePtr,
void
CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
switch (aStatus) {
case JSGC_BEGIN:
@ -1648,7 +1645,7 @@ CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
void
CycleCollectedJSRuntime::OnOutOfMemory()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
AnnotateAndSetOutOfMemory(&mOutOfMemoryState, OOMState::Reporting);
CustomOutOfMemoryCallback();
@ -1658,7 +1655,7 @@ CycleCollectedJSRuntime::OnOutOfMemory()
void
CycleCollectedJSRuntime::OnLargeAllocationFailure()
{
MOZ_ASSERT(mJSRuntime);
MOZ_ASSERT(mJSContext);
AnnotateAndSetOutOfMemory(&mLargeAllocationFailureState, OOMState::Reporting);
CustomLargeAllocationFailureCallback();

View File

@ -324,20 +324,20 @@ public:
virtual void EndCycleCollectionCallback(CycleCollectorResults& aResults) = 0;
virtual void DispatchDeferredDeletion(bool aContinuation, bool aPurge = false) = 0;
JSRuntime* Runtime() const
{
MOZ_ASSERT(mJSRuntime);
return mJSRuntime;
}
JSContext* Context() const
{
MOZ_ASSERT(mJSContext);
return mJSContext;
}
js::RootingContext* RootingCx() const
{
MOZ_ASSERT(mJSContext);
return js::ContextFriendFields::get(mJSContext);
}
protected:
JSRuntime* MaybeRuntime() const { return mJSRuntime; }
JSContext* MaybeContext() const { return mJSContext; }
public:
// nsThread entrypoints
@ -401,7 +401,6 @@ private:
JSZoneParticipant mJSZoneCycleCollectorGlobal;
JSRuntime* mJSRuntime;
JSContext* mJSContext;
JS::GCSliceCallback mPrevGCSliceCallback;

View File

@ -999,7 +999,7 @@ ShutdownXPCOM(nsIServiceManager* aServMgr)
// duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that
// never fired.
if (PseudoStack* stack = mozilla_get_pseudo_stack()) {
stack->sampleRuntime(nullptr);
stack->sampleContext(nullptr);
}
#endif

View File

@ -129,10 +129,8 @@ CreateGlobalAndRunTest(JSContext* cx)
TEST(GCPostBarriers, nsTArray) {
CycleCollectedJSRuntime* ccrt = CycleCollectedJSRuntime::Get();
ASSERT_TRUE(ccrt != nullptr);
JSRuntime* rt = ccrt->Runtime();
ASSERT_TRUE(rt != nullptr);
JSContext* cx = JS_GetContext(rt);
JSContext* cx = ccrt->Context();
ASSERT_TRUE(cx != nullptr);
JS_BeginRequest(cx);