From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- dom/console/ConsoleInstance.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'dom/console/ConsoleInstance.cpp') diff --git a/dom/console/ConsoleInstance.cpp b/dom/console/ConsoleInstance.cpp index ade82be50f..a73b83ee4c 100644 --- a/dom/console/ConsoleInstance.cpp +++ b/dom/console/ConsoleInstance.cpp @@ -65,9 +65,24 @@ ConsoleInstance::ConsoleInstance(JSContext* aCx, if (!aOptions.mMaxLogLevelPref.IsEmpty()) { if (!NS_IsMainThread()) { - NS_WARNING("Console.maxLogLevelPref is not supported on workers!"); // Set the log level based on what we have. SetLogLevel(); + + // Flag an error to the console. + JS::Rooted msg(aCx); + if (!ToJSValue( + aCx, + nsLiteralCString( + "Console.maxLogLevelPref is not supported within workers!"), + &msg)) { + JS_ClearPendingException(aCx); + return; + } + + AutoTArray sequence; + SequenceRooter rootedSequence(aCx, &sequence); + sequence.AppendElement(std::move(msg)); + this->Error(aCx, std::move(sequence)); return; } @@ -80,8 +95,9 @@ ConsoleInstance::ConsoleInstance(JSContext* aCx, } ConsoleInstance::~ConsoleInstance() { - AssertIsOnMainThread(); - if (!mMaxLogLevelPref.IsEmpty()) { + // We should only ever have set `mMaxLogLevelPref` when on the main thread, + // but check it here to be safe. + if (!mMaxLogLevelPref.IsEmpty() && NS_IsMainThread()) { Preferences::UnregisterCallback(MaxLogLevelPrefChangedCallback, mMaxLogLevelPref, this); } @@ -128,7 +144,6 @@ void ConsoleInstance::SetLogLevel() { // static void ConsoleInstance::MaxLogLevelPrefChangedCallback( const char* /* aPrefName */, void* aSelf) { - AssertIsOnMainThread(); auto* instance = static_cast(aSelf); if (MOZ_UNLIKELY(!instance->mConsole)) { // We've been unlinked already but not destroyed yet. Bail. -- cgit v1.2.3