WorkerError.h (2521B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_workers_WorkerError_h 8 #define mozilla_dom_workers_WorkerError_h 9 10 #include "jsapi.h" 11 #include "mozilla/dom/SerializedStackHolder.h" 12 #include "mozilla/dom/WorkerCommon.h" 13 14 namespace mozilla { 15 16 class DOMEventTargetHelper; 17 18 namespace dom { 19 20 class ErrorData; 21 class WorkerErrorBase { 22 public: 23 nsString mMessage; 24 nsCString mFilename; 25 // Line number (1-origin). 26 uint32_t mLineNumber = 0; 27 // Column number in UTF-16 code units (1-origin). 28 uint32_t mColumnNumber = 0; 29 uint32_t mErrorNumber = 0; 30 31 WorkerErrorBase() = default; 32 33 void AssignErrorBase(JSErrorBase* aReport); 34 }; 35 36 class WorkerErrorNote : public WorkerErrorBase { 37 public: 38 void AssignErrorNote(JSErrorNotes::Note* aNote); 39 }; 40 41 class WorkerPrivate; 42 43 class WorkerErrorReport : public WorkerErrorBase, public SerializedStackHolder { 44 public: 45 bool mIsWarning; 46 JSExnType mExnType; 47 bool mMutedError; 48 nsTArray<WorkerErrorNote> mNotes; 49 50 WorkerErrorReport(); 51 52 void AssignErrorReport(JSErrorReport* aReport); 53 54 // aWorkerPrivate is the worker thread we're on (or the main thread, if null) 55 // aTarget is the worker object that we are going to fire an error at 56 // (if any). 57 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1743443) 58 MOZ_CAN_RUN_SCRIPT_BOUNDARY static void ReportError( 59 JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aFireAtScope, 60 DOMEventTargetHelper* aTarget, UniquePtr<WorkerErrorReport> aReport, 61 uint64_t aInnerWindowId, 62 JS::Handle<JS::Value> aException = JS::NullHandleValue); 63 64 static void LogErrorToConsole(JSContext* aCx, WorkerErrorReport& aReport, 65 uint64_t aInnerWindowId); 66 67 static void LogErrorToConsole(const mozilla::dom::ErrorData& aReport, 68 uint64_t aInnerWindowId, 69 JS::Handle<JSObject*> aStack = nullptr, 70 JS::Handle<JSObject*> aStackGlobal = nullptr); 71 72 static void LogErrorToConsole(const nsAString& aMessage); 73 74 static void CreateAndDispatchGenericErrorRunnableToParent( 75 WorkerPrivate* aWorkerPrivate); 76 }; 77 78 } // namespace dom 79 } // namespace mozilla 80 81 #endif // mozilla_dom_workers_WorkerError_h