Bug 1674336 - Add WorkerScope#clearConsoleEvents. r=asuth.

This will be used from the DevTools webconsole to clear events when
the user hits the clear button in the UI.

A test for the console is added in the next patch of the queue.

Differential Revision: https://phabricator.services.mozilla.com/D138314
This commit is contained in:
nchevobbe 2022-02-10 17:16:24 +00:00
Родитель 03a7882ef0
Коммит ce39e48888
4 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -1584,7 +1584,7 @@ DOMInterfaces = {
'WorkerDebuggerGlobalScope': {
'headerFile': 'mozilla/dom/WorkerScope.h',
'implicitJSContext': [
'dump', 'reportError', 'setConsoleEventHandler',
'dump', 'clearConsoleEvents', 'reportError', 'setConsoleEventHandler',
],
},

Просмотреть файл

@ -35,6 +35,9 @@ interface WorkerDebuggerGlobalScope : EventTarget {
[Throws]
void setConsoleEventHandler(AnyCallback? handler);
[Throws]
void clearConsoleEvents();
// base64 utility methods
[Throws]
DOMString btoa(DOMString btoa);

Просмотреть файл

@ -1253,6 +1253,20 @@ void WorkerDebuggerGlobalScope::RetrieveConsoleEvents(
console->RetrieveConsoleEvents(aCx, aEvents, aRv);
}
void WorkerDebuggerGlobalScope::ClearConsoleEvents(JSContext* aCx,
ErrorResult& aRv) {
WorkerGlobalScope* scope = mWorkerPrivate->GetOrCreateGlobalScope(aCx);
if (!scope) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
RefPtr<Console> console = scope->GetConsoleIfExists();
if (console) {
console->ClearStorage();
}
}
void WorkerDebuggerGlobalScope::SetConsoleEventHandler(JSContext* aCx,
AnyCallback* aHandler,
ErrorResult& aRv) {

Просмотреть файл

@ -489,6 +489,8 @@ class WorkerDebuggerGlobalScope final : public WorkerGlobalScopeBase {
void RetrieveConsoleEvents(JSContext* aCx, nsTArray<JS::Value>& aEvents,
ErrorResult& aRv);
void ClearConsoleEvents(JSContext* aCx, ErrorResult& aRv);
void SetConsoleEventHandler(JSContext* aCx, AnyCallback* aHandler,
ErrorResult& aRv);