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"
|
|
|
|
|
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 "nsIDocument.h"
|
|
|
|
#include "nsIDOMDOMException.h"
|
|
|
|
#include "nsIException.h"
|
|
|
|
#include "nsMemory.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},
|
|
|
|
|
2017-02-01 05:42:33 +03:00
|
|
|
static constexpr struct ResultStruct
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
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)
|
2018-02-06 00:34:04 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2013-09-09 07:28:50 +04:00
|
|
|
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_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-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)
|
2018-02-06 00:34:04 +03:00
|
|
|
: mMessage(aMessage)
|
|
|
|
, mResult(aResult)
|
|
|
|
, mName(aName)
|
|
|
|
, mData(aData)
|
|
|
|
, mHoldingJSVal(false)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2018-02-06 00:34:04 +03:00
|
|
|
if (aLocation) {
|
|
|
|
mLocation = aLocation;
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
void
|
|
|
|
Exception::GetName(nsAString& aName)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2014-01-20 20:51:41 +04:00
|
|
|
if (!mName.IsEmpty()) {
|
2018-02-06 00:34:05 +03:00
|
|
|
CopyUTF8toUTF16(mName, aName);
|
2014-01-20 20:51:41 +04:00
|
|
|
} 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) {
|
2018-02-06 00:34:05 +03:00
|
|
|
CopyUTF8toUTF16(name, aName);
|
2014-01-20 20:51:41 +04:00
|
|
|
}
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
void
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::GetFilename(JSContext* aCx, nsAString& aFilename)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
2014-01-08 04:53:18 +04:00
|
|
|
if (mLocation) {
|
2018-02-06 00:34:04 +03:00
|
|
|
mLocation->GetFilename(aCx, aFilename);
|
2018-02-06 00:34:05 +03:00
|
|
|
return;
|
2014-01-08 04:53:18 +04:00
|
|
|
}
|
|
|
|
|
2016-09-01 17:26:15 +03:00
|
|
|
aFilename.Truncate();
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
2018-02-06 00:34:06 +03:00
|
|
|
void
|
2016-03-22 20:50:31 +03:00
|
|
|
Exception::ToString(JSContext* aCx, nsACString& _retval)
|
2013-09-09 07:28:50 +04:00
|
|
|
{
|
|
|
|
static const char defaultMsg[] = "<no message>";
|
|
|
|
static const char defaultLocation[] = "<unknown>";
|
|
|
|
static const char format[] =
|
2016-12-14 19:32:21 +03:00
|
|
|
"[Exception... \"%s\" nsresult: \"0x%" PRIx32 " (%s)\" location: \"%s\" data: %s]";
|
2013-09-09 07:28:50 +04:00
|
|
|
|
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
|
2018-02-06 00:34:05 +03:00
|
|
|
mLocation->ToString(aCx, location);
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
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();
|
2016-12-14 19:32:21 +03:00
|
|
|
_retval.AppendPrintf(format, msg, static_cast<uint32_t>(mResult), resultName,
|
2014-01-20 20:51:41 +04:00
|
|
|
location.get(), data);
|
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
|
|
|
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)
|
|
|
|
{
|
2018-02-06 00:34:06 +03:00
|
|
|
CopyUTF8toUTF16(mMessage, retval);
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Exception::Result() const
|
|
|
|
{
|
|
|
|
return (uint32_t)mResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-02-06 00:34:04 +03:00
|
|
|
return mLocation->GetLineNumber(aCx);
|
2014-01-08 04:53:18 +04:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-02-06 00:34:06 +03:00
|
|
|
nsISupports*
|
2013-09-09 07:28:50 +04:00
|
|
|
Exception::GetData() const
|
|
|
|
{
|
2018-02-06 00:34:06 +03:00
|
|
|
return mData;
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
2014-07-04 09:25:16 +04:00
|
|
|
void
|
2018-02-06 00:34:05 +03:00
|
|
|
Exception::GetStack(JSContext* aCx, nsAString& aStack) const
|
2014-07-04 09:25:16 +04:00
|
|
|
{
|
|
|
|
if (mLocation) {
|
2018-02-06 00:34:05 +03:00
|
|
|
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;
|
2016-03-22 20:50:31 +03:00
|
|
|
ToString(aCx, str);
|
2013-09-09 07:28:50 +04:00
|
|
|
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)
|
2018-02-06 00:34:06 +03:00
|
|
|
: Exception(aMessage, aRv, aName, nullptr, nullptr),
|
2013-09-09 07:28:50 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-06 00:34:06 +03:00
|
|
|
void
|
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[] =
|
2016-12-14 19:32:21 +03:00
|
|
|
"[Exception... \"%s\" code: \"%d\" nsresult: \"0x%" PRIx32 " (%s)\" location: \"%s\"]";
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-12-14 19:32:21 +03:00
|
|
|
aReturn.AppendPrintf(format, msg, mCode, static_cast<uint32_t>(mResult), resultName,
|
2014-01-20 20:51:41 +04:00
|
|
|
location.get());
|
2013-09-09 07:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMException::GetName(nsString& retval)
|
|
|
|
{
|
|
|
|
CopyUTF8toUTF16(mName, 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
|