ConsoleUtils.h (1719B)
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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_ConsoleUtils_h 8 #define mozilla_dom_ConsoleUtils_h 9 10 #include "mozilla/JSObjectHolder.h" 11 #include "nsISupportsImpl.h" 12 #include "nsString.h" 13 14 namespace mozilla::dom { 15 16 class ConsoleUtils final { 17 public: 18 NS_INLINE_DECL_REFCOUNTING(ConsoleUtils) 19 20 enum Level { 21 eLog, 22 eWarning, 23 eError, 24 }; 25 26 // Main-thread only, reports a console message from a ServiceWorker. 27 static void ReportForServiceWorkerScope(const nsAString& aScope, 28 const nsAString& aMessage, 29 const nsACString& aFilename, 30 uint32_t aLineNumber, 31 uint32_t aColumnNumber, Level aLevel); 32 33 private: 34 ConsoleUtils(); 35 ~ConsoleUtils(); 36 37 static ConsoleUtils* GetOrCreate(); 38 39 JSObject* GetOrCreateSandbox(JSContext* aCx); 40 41 void ReportForServiceWorkerScopeInternal(const nsAString& aScope, 42 const nsAString& aMessage, 43 const nsACString& aFilename, 44 uint32_t aLineNumber, 45 uint32_t aColumnNumber, 46 Level aLevel); 47 48 RefPtr<JSObjectHolder> mSandbox; 49 }; 50 51 } // namespace mozilla::dom 52 53 #endif /* mozilla_dom_ConsoleUtils_h */