From 31bd9d01bbb892db4d68ca27cf6b568c118bf0ee Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Tue, 5 Jul 2016 11:06:05 +0200 Subject: [PATCH] Bug 1283855 part 5 - Make warning reporter APIs take JSContext instead of JSRuntime. r=arai --- dom/base/ScriptSettings.cpp | 7 +++---- ipc/testshell/XPCShellEnvironment.cpp | 8 ++++---- js/src/gdb/gdb-tests.cpp | 2 +- js/src/jsapi-tests/tests.h | 2 +- js/src/jsapi.cpp | 14 +++++++------- js/src/jsapi.h | 4 ++-- js/src/jsexn.cpp | 4 ++-- js/src/shell/js.cpp | 4 ++-- js/src/vm/Debugger.cpp | 6 +++--- js/src/vm/SelfHosting.cpp | 4 ++-- netwerk/base/ProxyAutoConfig.cpp | 5 +++-- xpcom/base/CycleCollectedJSRuntime.cpp | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 0b7a17acaa8d..68be85ef6174 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -305,7 +305,7 @@ AutoJSAPI::~AutoJSAPI() ReportException(); if (mOldWarningReporter.isSome()) { - JS::SetWarningReporter(JS_GetRuntime(cx()), mOldWarningReporter.value()); + JS::SetWarningReporter(cx(), mOldWarningReporter.value()); } // Leave the request before popping. @@ -345,10 +345,9 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal, ScriptSettingsStack::Push(this); - JSRuntime* rt = JS_GetRuntime(aCx); - mOldWarningReporter.emplace(JS::GetWarningReporter(rt)); + mOldWarningReporter.emplace(JS::GetWarningReporter(aCx)); - JS::SetWarningReporter(rt, WarningOnlyErrorReporter); + JS::SetWarningReporter(aCx, WarningOnlyErrorReporter); #ifdef DEBUG if (haveException) { diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index 83831e4e58da..59909607f75d 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -374,12 +374,12 @@ XPCShellEnvironment::ProcessFile(JSContext *cx, ok = JS_ExecuteScript(cx, script, &result); if (ok && !result.isUndefined()) { /* Suppress warnings from JS::ToString(). */ - older = JS::SetWarningReporter(JS_GetRuntime(cx), nullptr); + older = JS::SetWarningReporter(cx, nullptr); str = JS::ToString(cx, result); JSAutoByteString bytes; if (str) bytes.encodeLatin1(cx, str); - JS::SetWarningReporter(JS_GetRuntime(cx), older); + JS::SetWarningReporter(cx, older); if (!!bytes) fprintf(stdout, "%s\n", bytes.ptr()); @@ -595,12 +595,12 @@ XPCShellEnvironment::EvaluateString(const nsString& aString, JS::Rooted result(cx); bool ok = JS_ExecuteScript(cx, script, &result); if (ok && !result.isUndefined()) { - JS::WarningReporter old = JS::SetWarningReporter(JS_GetRuntime(cx), nullptr); + JS::WarningReporter old = JS::SetWarningReporter(cx, nullptr); JSString* str = JS::ToString(cx, result); nsAutoJSString autoStr; if (str) autoStr.init(cx, str); - JS::SetWarningReporter(JS_GetRuntime(cx), old); + JS::SetWarningReporter(cx, old); if (!autoStr.IsEmpty() && aResult) { aResult->Assign(autoStr); diff --git a/js/src/gdb/gdb-tests.cpp b/js/src/gdb/gdb-tests.cpp index eb3e025455c1..fe507944df80 100644 --- a/js/src/gdb/gdb-tests.cpp +++ b/js/src/gdb/gdb-tests.cpp @@ -73,7 +73,7 @@ main(int argc, const char** argv) JSContext* cx = JS_GetContext(runtime); checkBool(JS::InitSelfHostedCode(cx)); - JS::SetWarningReporter(runtime, reportWarning); + JS::SetWarningReporter(cx, reportWarning); JSAutoRequest ar(cx); diff --git a/js/src/jsapi-tests/tests.h b/js/src/jsapi-tests/tests.h index 3f8426e7ca08..67c71d4e5f43 100644 --- a/js/src/jsapi-tests/tests.h +++ b/js/src/jsapi-tests/tests.h @@ -289,7 +289,7 @@ class JSAPITest JSRuntime* rt = JS_NewRuntime(8L * 1024 * 1024); if (!rt) return nullptr; - JS::SetWarningReporter(rt, &reportWarning); + JS::SetWarningReporter(JS_GetContext(rt), &reportWarning); setNativeStackQuota(rt); return rt; } diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 9a316fc60875..379a4b166a83 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4126,7 +4126,7 @@ JS_BufferIsCompilableUnit(JSContext* cx, HandleObject obj, const char* utf8, siz Parser parser(cx, &cx->tempLifoAlloc(), options, chars, length, /* foldConstants = */ true, nullptr, nullptr); - JS::WarningReporter older = JS::SetWarningReporter(cx->runtime(), nullptr); + JS::WarningReporter older = JS::SetWarningReporter(cx, nullptr); if (!parser.checkOptions() || !parser.parse()) { // We ran into an error. If it was because we ran out of source, we // return false so our caller knows to try to collect more buffered @@ -4136,7 +4136,7 @@ JS_BufferIsCompilableUnit(JSContext* cx, HandleObject obj, const char* utf8, siz cx->clearPendingException(); } - JS::SetWarningReporter(cx->runtime(), older); + JS::SetWarningReporter(cx, older); js_free(chars); return result; @@ -5636,16 +5636,16 @@ JS_ReportAllocationOverflow(JSContext* cx) } JS_PUBLIC_API(JS::WarningReporter) -JS::GetWarningReporter(JSRuntime* rt) +JS::GetWarningReporter(JSContext* cx) { - return rt->warningReporter; + return cx->warningReporter; } JS_PUBLIC_API(JS::WarningReporter) -JS::SetWarningReporter(JSRuntime* rt, JS::WarningReporter reporter) +JS::SetWarningReporter(JSContext* cx, JS::WarningReporter reporter) { - WarningReporter older = rt->warningReporter; - rt->warningReporter = reporter; + WarningReporter older = cx->warningReporter; + cx->warningReporter = reporter; return older; } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 5c06216de850..114395552a02 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -5219,10 +5219,10 @@ typedef void (* WarningReporter)(JSContext* cx, const char* message, JSErrorReport* report); extern JS_PUBLIC_API(WarningReporter) -SetWarningReporter(JSRuntime* rt, WarningReporter reporter); +SetWarningReporter(JSContext* cx, WarningReporter reporter); extern JS_PUBLIC_API(WarningReporter) -GetWarningReporter(JSRuntime* rt); +GetWarningReporter(JSContext* cx); extern JS_PUBLIC_API(bool) CreateError(JSContext* cx, JSExnType type, HandleObject stack, diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp index da81673c0123..aef4794b13ff 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -249,13 +249,13 @@ struct SuppressErrorsGuard explicit SuppressErrorsGuard(JSContext* cx) : cx(cx), - prevReporter(JS::SetWarningReporter(cx->runtime(), nullptr)), + prevReporter(JS::SetWarningReporter(cx, nullptr)), prevState(cx) {} ~SuppressErrorsGuard() { - JS::SetWarningReporter(cx->runtime(), prevReporter); + JS::SetWarningReporter(cx, prevReporter); } }; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index e9c40b635c9e..b18031b9fb1e 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2948,7 +2948,7 @@ WorkerMain(void* arg) sr->isWorker = true; JS_SetRuntimePrivate(rt, sr.get()); JS_SetFutexCanWait(cx); - JS::SetWarningReporter(rt, WarningReporter); + JS::SetWarningReporter(cx, WarningReporter); JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy); SetWorkerRuntimeOptions(rt); @@ -7386,7 +7386,7 @@ main(int argc, char** argv, char** envp) JS_SetRuntimePrivate(rt, sr.get()); // Waiting is allowed on the shell's main thread, for now. JS_SetFutexCanWait(cx); - JS::SetWarningReporter(rt, WarningReporter); + JS::SetWarningReporter(cx, WarningReporter); if (!SetRuntimeOptions(rt, op)) return 1; diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index cf0555e664de..bedf8b08af10 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -4939,12 +4939,12 @@ Debugger::isCompilableUnit(JSContext* cx, unsigned argc, Value* vp) options, chars.twoByteChars(), length, /* foldConstants = */ true, nullptr, nullptr); - JS::WarningReporter older = JS::SetWarningReporter(cx->runtime(), nullptr); + JS::WarningReporter older = JS::SetWarningReporter(cx, nullptr); if (!parser.checkOptions() || !parser.parse()) { // We ran into an error. If it was because we ran out of memory we report // it in the usual way. if (cx->isThrowingOutOfMemory()) { - JS::SetWarningReporter(cx->runtime(), older); + JS::SetWarningReporter(cx, older); return false; } @@ -4955,7 +4955,7 @@ Debugger::isCompilableUnit(JSContext* cx, unsigned argc, Value* vp) cx->clearPendingException(); } - JS::SetWarningReporter(cx->runtime(), older); + JS::SetWarningReporter(cx, older); args.rval().setBoolean(result); return true; } diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index 42c63c2ed977..6b01c98d10d4 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -2753,10 +2753,10 @@ class MOZ_STACK_CLASS AutoSelfHostingErrorReporter explicit AutoSelfHostingErrorReporter(JSContext* cx) : cx_(cx) { - oldReporter_ = JS::SetWarningReporter(cx_->runtime(), selfHosting_WarningReporter); + oldReporter_ = JS::SetWarningReporter(cx_, selfHosting_WarningReporter); } ~AutoSelfHostingErrorReporter() { - JS::SetWarningReporter(cx_->runtime(), oldReporter_); + JS::SetWarningReporter(cx_, oldReporter_); // Exceptions in self-hosted code will usually be printed to stderr in // ErrorToException, but not all exceptions are handled there. For diff --git a/netwerk/base/ProxyAutoConfig.cpp b/netwerk/base/ProxyAutoConfig.cpp index 55f7709ab08e..76018dbcc631 100644 --- a/netwerk/base/ProxyAutoConfig.cpp +++ b/netwerk/base/ProxyAutoConfig.cpp @@ -673,15 +673,16 @@ private: nsresult Init() { + mContext = JS_GetContext(mRuntime); + /* * Not setting this will cause JS_CHECK_RECURSION to report false * positives */ JS_SetNativeStackQuota(mRuntime, 128 * sizeof(size_t) * 1024); - JS::SetWarningReporter(mRuntime, PACWarningReporter); + JS::SetWarningReporter(mContext, PACWarningReporter); - mContext = JS_GetContext(mRuntime); if (!JS::InitSelfHostedCode(mContext)) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index 0c410695a292..926875eaab3e 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -539,7 +539,7 @@ CycleCollectedJSRuntime::Initialize(JSRuntime* aParentRuntime, JS_SetDestroyZoneCallback(mJSContext, XPCStringConvert::FreeZoneCache); JS_SetSweepZoneCallback(mJSContext, XPCStringConvert::ClearZoneCache); JS::SetBuildIdOp(mJSRuntime, GetBuildId); - JS::SetWarningReporter(mJSRuntime, MozCrashWarningReporter); + JS::SetWarningReporter(mJSContext, MozCrashWarningReporter); static js::DOMCallbacks DOMcallbacks = { InstanceClassHasProtoAtDepth