2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-09-09 07:28:50 +04:00
|
|
|
/* 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_Exceptions_h__
|
|
|
|
#define mozilla_dom_Exceptions_h__
|
|
|
|
|
|
|
|
// DOM exception throwing machinery (for both main thread and workers).
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "jspubtd.h"
|
|
|
|
#include "nsIException.h"
|
2015-10-09 23:48:10 +03:00
|
|
|
#include "nsStringGlue.h"
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
class nsIStackFrame;
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2013-09-09 07:28:50 +04:00
|
|
|
template <class T>
|
2014-06-17 18:57:23 +04:00
|
|
|
struct already_AddRefed;
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Exception;
|
|
|
|
|
2015-10-09 23:48:10 +03:00
|
|
|
// If we're throwing a DOMException and message is empty, the default
|
|
|
|
// message for the nsresult in question will be used.
|
2013-09-09 07:29:21 +04:00
|
|
|
bool
|
2015-10-09 23:48:10 +03:00
|
|
|
Throw(JSContext* cx, nsresult rv, const nsACString& message = EmptyCString());
|
2013-09-09 07:28:50 +04:00
|
|
|
|
2014-07-02 14:26:49 +04:00
|
|
|
// Create, throw and report an exception to a given window.
|
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
ThrowAndReport(nsPIDOMWindowInner* aWindow, nsresult aRv);
|
2014-07-02 14:26:49 +04:00
|
|
|
|
2013-09-09 07:28:50 +04:00
|
|
|
bool
|
|
|
|
ThrowExceptionObject(JSContext* aCx, Exception* aException);
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThrowExceptionObject(JSContext* aCx, nsIException* aException);
|
|
|
|
|
2015-10-09 23:48:10 +03:00
|
|
|
// Create an exception object for the given nsresult and message but don't set
|
|
|
|
// it pending on aCx. If we're throwing a DOMException and aMessage is empty,
|
|
|
|
// the default message for the nsresult in question will be used.
|
|
|
|
//
|
|
|
|
// This never returns null.
|
2014-04-16 23:13:41 +04:00
|
|
|
already_AddRefed<Exception>
|
2015-10-09 23:48:10 +03:00
|
|
|
CreateException(JSContext* aCx, nsresult aRv,
|
|
|
|
const nsACString& aMessage = EmptyCString());
|
2014-04-16 23:13:41 +04:00
|
|
|
|
2016-03-22 20:50:31 +03:00
|
|
|
// aMaxDepth can be used to define a maximal depth for the stack trace. If the
|
|
|
|
// value is -1, a default maximal depth will be selected. Will return null if
|
|
|
|
// there is no JS stack right now.
|
2013-09-09 07:29:21 +04:00
|
|
|
already_AddRefed<nsIStackFrame>
|
2016-03-22 20:50:31 +03:00
|
|
|
GetCurrentJSStack(int32_t aMaxDepth = -1);
|
2013-09-09 07:29:21 +04:00
|
|
|
|
2015-01-15 00:43:27 +03:00
|
|
|
// Throwing a TypeError on an ErrorResult may result in SpiderMonkey using its
|
|
|
|
// own error reporting mechanism instead of just setting the exception on the
|
|
|
|
// context. This happens if no script is running. Bug 1107777 adds a flag that
|
|
|
|
// forcibly turns this behaviour off. This is a stack helper to set the flag.
|
|
|
|
class MOZ_STACK_CLASS AutoForceSetExceptionOnContext {
|
|
|
|
private:
|
|
|
|
JSContext* mCx;
|
|
|
|
bool mOldValue;
|
|
|
|
public:
|
|
|
|
explicit AutoForceSetExceptionOnContext(JSContext* aCx);
|
|
|
|
~AutoForceSetExceptionOnContext();
|
|
|
|
};
|
|
|
|
|
2013-09-09 07:28:50 +04:00
|
|
|
// Internal stuff not intended to be widely used.
|
|
|
|
namespace exceptions {
|
|
|
|
|
2014-01-26 16:35:17 +04:00
|
|
|
// aMaxDepth can be used to define a maximal depth for the stack trace. If the
|
2016-03-22 20:50:31 +03:00
|
|
|
// value is -1, a default maximal depth will be selected. Will return null if
|
|
|
|
// there is no JS stack right now.
|
2013-09-09 07:28:50 +04:00
|
|
|
already_AddRefed<nsIStackFrame>
|
2014-01-26 16:35:17 +04:00
|
|
|
CreateStack(JSContext* aCx, int32_t aMaxDepth = -1);
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
} // namespace exceptions
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|