dom/workers/WorkerError.h
author Daniel Varga <dvarga@mozilla.com>
Fri, 03 May 2019 11:56:25 +0300
changeset 531274 9dbf4a541fff28274537c379f29b7bdb58cfd60d
parent 531262 b765eaf69bcb947cedacfefd424a43fa403f0aa4
child 531551 7cebca65fa314ed2de10a68badf691563d3b2e58
permissions -rw-r--r--
Backed out 7 changesets (bug 1392408) for mochitest failures at test_xhr_withCredentials.html and xpcshell failures at test_startup_(no)session_async.js Backed out changeset 05656abf3e6c (bug 1392408) Backed out changeset ac9c08f90cd0 (bug 1392408) Backed out changeset 855b8dd227f9 (bug 1392408) Backed out changeset 9c3b9f800a0c (bug 1392408) Backed out changeset 2a64ecfab240 (bug 1392408) Backed out changeset b765eaf69bcb (bug 1392408) Backed out changeset 337d93c03c2e (bug 1392408)

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_workers_WorkerError_h
#define mozilla_dom_workers_WorkerError_h

#include "mozilla/dom/WorkerCommon.h"
#include "jsapi.h"
#include "WorkerRef.h"

namespace mozilla {

class DOMEventTargetHelper;

namespace dom {

class ErrorData;
class WorkerErrorBase {
 public:
  nsString mMessage;
  nsString mFilename;
  uint32_t mLineNumber;
  uint32_t mColumnNumber;
  uint32_t mErrorNumber;

  WorkerErrorBase() : mLineNumber(0), mColumnNumber(0), mErrorNumber(0) {}

  void AssignErrorBase(JSErrorBase* aReport);
};

class WorkerErrorNote : public WorkerErrorBase {
 public:
  void AssignErrorNote(JSErrorNotes::Note* aNote);
};

class WorkerPrivate;

// The StructuredCloneHolder superclass is used to encode the error's stack
// data, if there is any.
class WorkerErrorReport : public WorkerErrorBase, public StructuredCloneHolder {
 public:
  nsString mLine;
  uint32_t mFlags;
  JSExnType mExnType;
  bool mMutedError;
  nsTArray<WorkerErrorNote> mNotes;

  // Hold a reference on the originating worker until the error has been
  // processed.
  RefPtr<ThreadSafeWorkerRef> mWorkerRef;

  // Create a new error report. aWorkerPrivate represents the worker where the
  // error originated.
  explicit WorkerErrorReport(WorkerPrivate* aWorkerPrivate);

  void AssignErrorReport(JSErrorReport* aReport);

  // aWorkerPrivate is the worker thread we're on (or the main thread, if null)
  // aTarget is the worker object that we are going to fire an error at
  // (if any).
  static void ReportError(
      JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aFireAtScope,
      DOMEventTargetHelper* aTarget, UniquePtr<WorkerErrorReport> aReport,
      uint64_t aInnerWindowId,
      JS::Handle<JS::Value> aException = JS::NullHandleValue);

  static void LogErrorToConsole(JSContext* aCx, WorkerErrorReport& aReport,
                                uint64_t aInnerWindowId);

  static void LogErrorToConsole(const mozilla::dom::ErrorData& aReport,
                                uint64_t aInnerWindowId,
                                JS::HandleObject aStack = nullptr,
                                JS::HandleObject aStackGlobal = nullptr);

  static void CreateAndDispatchGenericErrorRunnableToParent(
      WorkerPrivate* aWorkerPrivate);
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_workers_WorkerError_h