From 289744e70a8773fad512c16bc54c84b7158a9738 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Wed, 4 Sep 2019 09:46:41 +0000 Subject: [PATCH] Bug 1558128 report errors from worklet scripts to console r=baku There is no ErrorEvent dispatched to WorkletGlobalScope. See also https://github.com/whatwg/html/issues/2611 Differential Revision: https://phabricator.services.mozilla.com/D44600 --HG-- extra : moz-landing-system : lando --- dom/worklet/WorkletThread.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/dom/worklet/WorkletThread.cpp b/dom/worklet/WorkletThread.cpp index c41eaed978c15..87bdda86bd30e 100644 --- a/dom/worklet/WorkletThread.cpp +++ b/dom/worklet/WorkletThread.cpp @@ -169,11 +169,33 @@ class WorkletJSContext final : public CycleCollectedJSContext { } void ReportError(JSErrorReport* aReport, - JS::ConstUTF8CharsZ aToStringResult) override { - // TODO: bug 1558128; + JS::ConstUTF8CharsZ aToStringResult) override; + + uint64_t GetCurrentWorkletWindowID() { + JSObject* global = JS::CurrentGlobalOrNull(Context()); + if (NS_WARN_IF(!global)) { + return 0; + } + nsIGlobalObject* nativeGlobal = xpc::NativeGlobal(global); + nsCOMPtr workletGlobal = + do_QueryInterface(nativeGlobal); + if (NS_WARN_IF(!workletGlobal)) { + return 0; + } + return workletGlobal->Impl()->LoadInfo().InnerWindowID(); } }; +void WorkletJSContext::ReportError(JSErrorReport* aReport, + JS::ConstUTF8CharsZ aToStringResult) { + RefPtr xpcReport = new xpc::ErrorReport(); + xpcReport->Init(aReport, aToStringResult.c_str(), IsSystemCaller(), + GetCurrentWorkletWindowID()); + + RefPtr reporter = new AsyncErrorReporter(xpcReport); + NS_DispatchToMainThread(reporter); +} + // This is the first runnable to be dispatched. It calls the RunEventLoop() so // basically everything happens into this runnable. The reason behind this // approach is that, when the Worklet is terminated, it must not have any JS in