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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/DOMException.h"
|
|
|
|
|
|
|
|
#include "jsprf.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-09-10 19:29:43 +04:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2013-09-09 07:29:21 +04:00
|
|
|
#include "mozilla/dom/Exceptions.h"
|
2013-09-09 07:28:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIClassInfoImpl.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDOMException.h"
|
|
|
|
#include "nsIException.h"
|
2013-09-23 21:29:27 +04:00
|
|
|
#include "nsIProgrammingLanguage.h"
|
2013-09-09 07:28:50 +04:00
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "xpcprivate.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/DOMExceptionBinding.h"
|
2014-07-04 09:25:16 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
enum DOM4ErrorTypeCodeMap {
|
|
|
|
/* DOM4 errors from http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#domexception */
|
|
|
|
IndexSizeError = nsIDOMDOMException::INDEX_SIZE_ERR,
|
|
|
|
HierarchyRequestError = nsIDOMDOMException::HIERARCHY_REQUEST_ERR,
|
|
|
|
WrongDocumentError = nsIDOMDOMException::WRONG_DOCUMENT_ERR,
|
|
|
|
InvalidCharacterError = nsIDOMDOMException::INVALID_CHARACTER_ERR,
|
|
|
|
NoModificationAllowedError = nsIDOMDOMException::NO_MODIFICATION_ALLOWED_ERR,
|
|
|
|
NotFoundError = nsIDOMDOMException::NOT_FOUND_ERR,
|
|
|
|
NotSupportedError = nsIDOMDOMException::NOT_SUPPORTED_ERR,
|
|
|
|
// Can't remove until setNamedItem is removed
|
|
|
|
InUseAttributeError = nsIDOMDOMException::INUSE_ATTRIBUTE_ERR,
|
|
|
|
InvalidStateError = nsIDOMDOMException::INVALID_STATE_ERR,
|
|
|
|
SyntaxError = nsIDOMDOMException::SYNTAX_ERR,
|
|
|
|
InvalidModificationError = nsIDOMDOMException::INVALID_MODIFICATION_ERR,
|
|
|
|
NamespaceError = nsIDOMDOMException::NAMESPACE_ERR,
|
|
|
|
InvalidAccessError = nsIDOMDOMException::INVALID_ACCESS_ERR,
|
|
|
|
TypeMismatchError = nsIDOMDOMException::TYPE_MISMATCH_ERR,
|
|
|
|
SecurityError = nsIDOMDOMException::SECURITY_ERR,
|
|
|
|
NetworkError = nsIDOMDOMException::NETWORK_ERR,
|
|
|
|
AbortError = nsIDOMDOMException::ABORT_ERR,
|
|
|
|
URLMismatchError = nsIDOMDOMException::URL_MISMATCH_ERR,
|
|
|
|
QuotaExceededError = nsIDOMDOMException::QUOTA_EXCEEDED_ERR,
|
|
|
|
TimeoutError = nsIDOMDOMException::TIMEOUT_ERR,
|
|
|
|
InvalidNodeTypeError = nsIDOMDOMException::INVALID_NODE_TYPE_ERR,
|
|
|
|
DataCloneError = nsIDOMDOMException::DATA_CLONE_ERR,
|
2014-04-04 21:09:10 +04:00
|
|
|
InvalidPointerId = nsIDOMDOMException::INVALID_POINTER_ERR,
|
2013-09-09 07:28:50 +04:00
|
|
|
EncodingError = 0,
|
|
|
|
|
|
|
|
/* XXX Should be JavaScript native errors */
|
|
|
|
TypeError = 0,
|
|
|
|
RangeError = 0,
|
|
|
|
|
|
|
|
/* IndexedDB errors http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#exceptions */
|
|
|
|
UnknownError = 0,
|
|
|
|
ConstraintError = 0,
|
|
|
|
DataError = 0,
|
|
|
|
TransactionInactiveError = 0,
|
|
|
|
ReadOnlyError = 0,
|
|
|
|
VersionError = 0,
|
|
|
|
|
|
|
|
/* File API errors http://dev.w3.org/2006/webapi/FileAPI/#ErrorAndException */
|
|
|
|
NotReadableError = 0,
|
|
|
|
|
|
|
|
/* FileHandle API errors */
|
2014-06-12 07:35:29 +04:00
|
|
|
FileHandleInactiveError = 0,
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
/* WebCrypto errors https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-DataError */
|
|
|
|
OperationError = 0,
|
2014-08-25 10:51:20 +04:00
|
|
|
|
2015-11-05 21:38:35 +03:00
|
|
|
/* Push API errors */
|
2016-05-11 20:48:31 +03:00
|
|
|
NotAllowedError = 0,
|
2013-09-09 07:28:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DOM4_MSG_DEF(name, message, nsresult) {(nsresult), name, #name, message},
|
|
|
|
#define DOM_MSG_DEF(val, message) {(val), NS_ERROR_GET_CODE(val), #val, message},
|
|
|
|
|
|
|
|
static const struct ResultStruct
|
|
|
|
{
|
|
|
|
nsresult mNSResult;
|
|
|
|
uint16_t mCode;
|
|
|
|
const char* mName;
|
|
|
|
const char* mMessage;
|
|
|
|
} sDOMErrorMsgMap[] = {
|
|
|
|
#include "domerr.msg"
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef DOM4_MSG_DEF
|
|
|
|
#undef DOM_MSG_DEF
|
|
|
|
|
|
|
|
static void
|
|
|
|
NSResultToNameAndMessage(nsresult aNSResult,
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString& aName,
|
|
|
|
nsCString& aMessage,
|
2013-09-09 07:28:50 +04:00
|
|
|
uint16_t* aCode)
|
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
aName.Truncate();
|
|
|
|
aMessage.Truncate();
|
2013-09-09 07:28:50 +04:00
|
|
|
*aCode = 0;
|
|
|
|
for (uint32_t idx = 0; idx < ArrayLength(sDOMErrorMsgMap); idx++) {
|
|
|
|
if (aNSResult == sDOMErrorMsgMap[idx].mNSResult) {
|
2014-01-20 20:51:41 +04:00
|
|
|
aName.Rebind(sDOMErrorMsgMap[idx].mName,
|
|
|
|
strlen(sDOMErrorMsgMap[idx].mName));
|
|
|
|
aMessage.Rebind(sDOMErrorMsgMap[idx].mMessage,
|
|
|
|
strlen(sDOMErrorMsgMap[idx].mMessage));
|
2013-09-09 07:28:50 +04:00
|
|
|
*aCode = sDOMErrorMsgMap[idx].mCode;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Huh, someone is throwing non-DOM errors using the DOM module!");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-20 20:51:41 +04:00
|
|
|
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName,
|
|
|
|
nsACString& aMessage, uint16_t* aCode)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString name;
|
|
|
|
nsCString message;
|
2013-09-09 07:28:50 +04:00
|
|
|
uint16_t code = 0;
|
2014-01-20 20:51:41 +04:00
|
|
|
NSResultToNameAndMessage(aNSResult, name, message, &code);
|
2013-09-09 07:28:50 +04:00
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
if (!name.IsEmpty() && !message.IsEmpty()) {
|
|
|
|
aName = name;
|
|
|
|
aMessage = message;
|
2013-09-09 07:28:50 +04:00
|
|
|
if (aCode) {
|
|
|
|
*aCode = code;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
bool Exception::sEverMadeOneFromFactory = false;
|
|
|
|
|
|
|
|
NS_IMPL_CLASSINFO(Exception, nullptr, nsIClassInfo::DOM_OBJECT,
|
|
|
|
NS_XPCEXCEPTION_CID)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Exception)
|
2014-11-07 22:40:04 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(Exception)
|
2013-09-09 07:28:50 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIException)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXPCException)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
|
|
|
|
NS_IMPL_QUERY_CLASSINFO(Exception)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Exception)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Exception)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Exception)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Exception)
|
2014-01-08 04:53:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation)
|
2016-03-04 19:54:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData)
|
2013-09-09 07:28:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Exception)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2016-02-22 21:11:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mThrownJSVal)
|
2013-09-09 07:28:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Exception)
|
2014-01-08 04:53:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocation)
|
2016-03-04 19:54:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mData)
|
2013-09-09 07:28:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2013-10-19 22:59:31 +04:00
|
|
|
tmp->mThrownJSVal.setNull();
|
2013-09-09 07:28:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(Exception, nsIXPCException)
|
2013-09-09 07:28:50 +04:00
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
Exception::Exception(const nsACString& aMessage,
|
2013-09-09 07:28:50 +04:00
|
|
|
nsresult aResult,
|
2014-01-20 20:51:41 +04:00
|
|
|
const nsACString& aName,
|
2013-09-09 07:28:50 +04:00
|
|
|
nsIStackFrame *aLocation,
|
|
|
|
nsISupports *aData)
|
2014-01-20 20:51:41 +04:00
|
|
|
: mResult(NS_OK),
|
2013-09-09 07:28:50 +04:00
|
|
|
mInitialized(false),
|
|
|
|
mHoldingJSVal(false)
|
|
|
|
{
|
|
|
|
// A little hack... The nsIGenericModule nsIClassInfo scheme relies on there
|
|
|
|
// having been at least one instance made via the factory. Otherwise, the
|
|
|
|
// shared factory/classinsance object never gets created and our QI getter
|
|
|
|
// for our instance's pointer to our nsIClassInfo will always return null.
|
|
|
|
// This is bad because it means that wrapped exceptions will never have a
|
|
|
|
// shared prototype. So... We force one to be created via the factory
|
|
|
|
// *once* and then go about our business.
|
|
|
|
if (!sEverMadeOneFromFactory) {
|
|
|
|
nsCOMPtr<nsIXPCException> e =
|
|
|
|
do_CreateInstance(XPC_EXCEPTION_CONTRACTID);
|
|
|
|
sEverMadeOneFromFactory = true;
|
|
|
|
}
|
|
|
|
|
2016-03-22 20:50:31 +03:00
|
|
|
Initialize(aMessage, aResult, aName, aLocation, aData);
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Exception::Exception()
|
2014-01-20 20:51:41 +04:00
|
|
|
: mResult(NS_OK),
|
2013-09-09 07:28:50 +04:00
|
|
|
mInitialized(false),
|
|
|
|
mHoldingJSVal(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Exception::~Exception()
|
|
|
|
{
|
|
|
|
if (mHoldingJSVal) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Exception::StealJSVal(JS::Value* aVp)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mHoldingJSVal) {
|
|
|
|
*aVp = mThrownJSVal;
|
2013-09-09 07:29:21 +04:00
|
|
|
mThrownJSVal.setNull();
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
mHoldingJSVal = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Exception::StowJSVal(JS::Value& aVp)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mThrownJSVal = aVp;
|
|
|
|
if (!mHoldingJSVal) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
mHoldingJSVal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-20 20:51:41 +04:00
|
|
|
Exception::GetMessageMoz(nsACString& aMessage)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
aMessage.Assign(mMessage);
|
2013-09-09 07:28:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Exception::GetResult(nsresult* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
*aResult = mResult;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-20 20:51:41 +04:00
|
|
|
Exception::GetName(nsACString& aName)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
if (!mName.IsEmpty()) {
|
|
|
|
aName.Assign(mName);
|
|
|
|
} else {
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
const char* name = nullptr;
|
2013-09-09 07:28:50 +04:00
|
|
|
nsXPCException::NameAndFormatForNSResult(mResult, &name, nullptr);
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
if (name) {
|
|
|
|
aName.Assign(name);
|
|
|
|
}
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::GetFilename(JSContext* aCx, nsAString& aFilename)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
2014-01-08 04:53:18 +04:00
|
|
|
|
|
|
|
if (mLocation) {
|
2016-03-22 20:50:31 +03:00
|
|
|
return mLocation->GetFilename(aCx, aFilename);
|
2014-01-08 04:53:18 +04:00
|
|
|
}
|
|
|
|
|
2016-09-01 17:26:15 +03:00
|
|
|
aFilename.Truncate();
|
2014-01-20 20:51:41 +04:00
|
|
|
return NS_OK;
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::GetLineNumber(JSContext* aCx, uint32_t *aLineNumber)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLineNumber);
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2014-01-08 04:53:18 +04:00
|
|
|
if (mLocation) {
|
|
|
|
int32_t lineno;
|
2016-03-22 20:50:31 +03:00
|
|
|
nsresult rv = mLocation->GetLineNumber(aCx, &lineno);
|
2014-01-08 04:53:18 +04:00
|
|
|
*aLineNumber = lineno;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-09-05 11:35:10 +03:00
|
|
|
*aLineNumber = 0;
|
2013-09-09 07:28:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Exception::GetColumnNumber(uint32_t* aColumnNumber)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnNumber);
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
*aColumnNumber = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Exception::GetLocation(nsIStackFrame** aLocation)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocation);
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStackFrame> location = mLocation;
|
|
|
|
location.forget(aLocation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Exception::GetData(nsISupports** aData)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aData);
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> data = mData;
|
|
|
|
data.forget(aData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::ToString(JSContext* aCx, nsACString& _retval)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
static const char defaultMsg[] = "<no message>";
|
|
|
|
static const char defaultLocation[] = "<unknown>";
|
|
|
|
static const char format[] =
|
|
|
|
"[Exception... \"%s\" nsresult: \"0x%x (%s)\" location: \"%s\" data: %s]";
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString location;
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
if (mLocation) {
|
|
|
|
// we need to free this if it does not fail
|
2016-03-22 20:50:31 +03:00
|
|
|
nsresult rv = mLocation->ToString(aCx, location);
|
2013-09-09 07:28:50 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
if (location.IsEmpty()) {
|
|
|
|
location.Assign(defaultLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* msg = mMessage.IsEmpty() ? nullptr : mMessage.get();
|
|
|
|
|
|
|
|
const char* resultName = mName.IsEmpty() ? nullptr: mName.get();
|
2013-09-09 07:28:50 +04:00
|
|
|
if (!resultName &&
|
|
|
|
!nsXPCException::NameAndFormatForNSResult(mResult, &resultName,
|
|
|
|
(!msg) ? &msg : nullptr)) {
|
|
|
|
if (!msg) {
|
|
|
|
msg = defaultMsg;
|
|
|
|
}
|
|
|
|
resultName = "<unknown>";
|
|
|
|
}
|
|
|
|
const char* data = mData ? "yes" : "no";
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
_retval.Truncate();
|
|
|
|
_retval.AppendPrintf(format, msg, mResult, resultName,
|
|
|
|
location.get(), data);
|
|
|
|
return NS_OK;
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-20 20:51:41 +04:00
|
|
|
Exception::Initialize(const nsACString& aMessage, nsresult aResult,
|
|
|
|
const nsACString& aName, nsIStackFrame *aLocation,
|
2015-12-02 21:52:59 +03:00
|
|
|
nsISupports *aData)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInitialized, NS_ERROR_ALREADY_INITIALIZED);
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
mMessage = aMessage;
|
|
|
|
mName = aName;
|
2013-09-09 07:28:50 +04:00
|
|
|
mResult = aResult;
|
|
|
|
|
|
|
|
if (aLocation) {
|
|
|
|
mLocation = aLocation;
|
|
|
|
} else {
|
2016-03-22 20:50:31 +03:00
|
|
|
mLocation = GetCurrentJSStack();
|
|
|
|
// it is legal for there to be no active JS stack, if C++ code
|
|
|
|
// is operating on a JS-implemented interface pointer without
|
|
|
|
// having been called in turn by JS. This happens in the JS
|
|
|
|
// component loader.
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mData = aData;
|
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
Exception::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return ExceptionBinding::Wrap(cx, this, aGivenProto);
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Exception::GetMessageMoz(nsString& retval)
|
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString str;
|
2013-09-09 07:28:50 +04:00
|
|
|
#ifdef DEBUG
|
2014-05-15 14:20:00 +04:00
|
|
|
DebugOnly<nsresult> rv =
|
2013-09-09 07:28:50 +04:00
|
|
|
#endif
|
2014-01-20 20:51:41 +04:00
|
|
|
GetMessageMoz(str);
|
2013-09-09 07:28:50 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
CopyUTF8toUTF16(str, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Exception::Result() const
|
|
|
|
{
|
|
|
|
return (uint32_t)mResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Exception::GetName(nsString& retval)
|
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString str;
|
2013-09-09 07:28:50 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
#endif
|
2014-01-20 20:51:41 +04:00
|
|
|
GetName(str);
|
2013-09-09 07:28:50 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
CopyUTF8toUTF16(str, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::LineNumber(JSContext* aCx) const
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2014-01-08 04:53:18 +04:00
|
|
|
if (mLocation) {
|
|
|
|
int32_t lineno;
|
2016-03-22 20:50:31 +03:00
|
|
|
if (NS_SUCCEEDED(mLocation->GetLineNumber(aCx, &lineno))) {
|
2014-01-08 04:53:18 +04:00
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-05 11:35:10 +03:00
|
|
|
return 0;
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Exception::ColumnNumber() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIStackFrame>
|
|
|
|
Exception::GetLocation() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStackFrame> location = mLocation;
|
|
|
|
return location.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsISupports>
|
|
|
|
Exception::GetData() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> data = mData;
|
|
|
|
return data.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-04 09:25:16 +04:00
|
|
|
void
|
2016-03-22 20:50:35 +03:00
|
|
|
Exception::GetStack(JSContext* aCx, nsAString& aStack, ErrorResult& aRv) const
|
2014-07-04 09:25:16 +04:00
|
|
|
{
|
|
|
|
if (mLocation) {
|
2016-03-22 20:50:35 +03:00
|
|
|
aRv = mLocation->GetFormattedStack(aCx, aStack);
|
2014-07-04 09:25:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-09 07:28:50 +04:00
|
|
|
void
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::Stringify(JSContext* aCx, nsString& retval)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString str;
|
2013-09-09 07:28:50 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
#endif
|
2016-03-22 20:50:31 +03:00
|
|
|
ToString(aCx, str);
|
2013-09-09 07:28:50 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
CopyUTF8toUTF16(str, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMException, Exception)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMException, Exception)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMException)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMException)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Exception)
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
DOMException::DOMException(nsresult aRv, const nsACString& aMessage,
|
|
|
|
const nsACString& aName, uint16_t aCode)
|
|
|
|
: Exception(EmptyCString(), aRv, EmptyCString(), nullptr, nullptr),
|
2013-09-09 07:28:50 +04:00
|
|
|
mName(aName),
|
|
|
|
mMessage(aMessage),
|
|
|
|
mCode(aCode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMException::GetCode(uint16_t* aCode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCode);
|
|
|
|
*aCode = mCode;
|
|
|
|
|
|
|
|
// Warn only when the code was changed (other than DOM Core)
|
|
|
|
// or the code is useless (zero)
|
|
|
|
if (NS_ERROR_GET_MODULE(mResult) != NS_ERROR_MODULE_DOM || !mCode) {
|
|
|
|
nsCOMPtr<nsIDocument> doc = nsContentUtils::GetDocumentFromCaller();
|
|
|
|
if (doc) {
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eDOMExceptionCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-03-22 20:50:31 +03:00
|
|
|
DOMException::ToString(JSContext* aCx, nsACString& aReturn)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
aReturn.Truncate();
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
static const char defaultMsg[] = "<no message>";
|
|
|
|
static const char defaultLocation[] = "<unknown>";
|
|
|
|
static const char defaultName[] = "<unknown>";
|
|
|
|
static const char format[] =
|
|
|
|
"[Exception... \"%s\" code: \"%d\" nsresult: \"0x%x (%s)\" location: \"%s\"]";
|
|
|
|
|
|
|
|
nsAutoCString location;
|
|
|
|
|
|
|
|
if (location.IsEmpty()) {
|
|
|
|
location = defaultLocation;
|
|
|
|
}
|
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
const char* msg = !mMessage.IsEmpty() ? mMessage.get() : defaultMsg;
|
|
|
|
const char* resultName = !mName.IsEmpty() ? mName.get() : defaultName;
|
2013-09-09 07:28:50 +04:00
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
aReturn.AppendPrintf(format, msg, mCode, mResult, resultName,
|
|
|
|
location.get());
|
2013-09-09 07:28:50 +04:00
|
|
|
|
2014-01-20 20:51:41 +04:00
|
|
|
return NS_OK;
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMException::GetName(nsString& retval)
|
|
|
|
{
|
|
|
|
CopyUTF8toUTF16(mName, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMException::GetMessageMoz(nsString& retval)
|
|
|
|
{
|
|
|
|
CopyUTF8toUTF16(mMessage, retval);
|
|
|
|
}
|
|
|
|
|
2015-01-03 01:08:33 +03:00
|
|
|
already_AddRefed<DOMException>
|
|
|
|
DOMException::Constructor(GlobalObject& /* unused */,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const Optional<nsAString>& aName,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
nsresult exceptionResult = NS_OK;
|
|
|
|
uint16_t exceptionCode = 0;
|
|
|
|
nsCString name(NS_LITERAL_CSTRING("Error"));
|
|
|
|
|
|
|
|
if (aName.WasPassed()) {
|
|
|
|
CopyUTF16toUTF8(aName.Value(), name);
|
|
|
|
for (uint32_t idx = 0; idx < ArrayLength(sDOMErrorMsgMap); idx++) {
|
|
|
|
if (name.EqualsASCII(sDOMErrorMsgMap[idx].mName)) {
|
|
|
|
exceptionResult = sDOMErrorMsgMap[idx].mNSResult;
|
|
|
|
exceptionCode = sDOMErrorMsgMap[idx].mCode;
|
2015-02-13 22:34:53 +03:00
|
|
|
break;
|
2015-01-03 01:08:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMException> retval =
|
2015-01-03 01:08:33 +03:00
|
|
|
new DOMException(exceptionResult,
|
|
|
|
NS_ConvertUTF16toUTF8(aMessage),
|
|
|
|
name,
|
|
|
|
exceptionCode);
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-09 07:28:50 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
DOMException::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return DOMExceptionBinding::Wrap(aCx, this, aGivenProto);
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */already_AddRefed<DOMException>
|
|
|
|
DOMException::Create(nsresult aRv)
|
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
nsCString name;
|
|
|
|
nsCString message;
|
2013-09-09 07:28:50 +04:00
|
|
|
uint16_t code;
|
2014-01-20 20:51:41 +04:00
|
|
|
NSResultToNameAndMessage(aRv, name, message, &code);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMException> inst =
|
2013-09-09 07:28:50 +04:00
|
|
|
new DOMException(aRv, message, name, code);
|
|
|
|
return inst.forget();
|
|
|
|
}
|
|
|
|
|
2015-06-03 04:42:50 +03:00
|
|
|
/* static */already_AddRefed<DOMException>
|
2015-06-05 12:55:52 +03:00
|
|
|
DOMException::Create(nsresult aRv, const nsACString& aMessage)
|
2015-06-03 04:42:50 +03:00
|
|
|
{
|
|
|
|
nsCString name;
|
|
|
|
nsCString message;
|
|
|
|
uint16_t code;
|
|
|
|
NSResultToNameAndMessage(aRv, name, message, &code);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMException> inst =
|
2015-06-03 04:42:50 +03:00
|
|
|
new DOMException(aRv, aMessage, name, code);
|
|
|
|
return inst.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-09 07:28:50 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|