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 "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;
|
2018-04-07 06:27:56 +03:00
|
|
|
using namespace mozilla::dom;
|
2013-09-09 07:28:50 +04:00
|
|
|
|
|
|
|
enum DOM4ErrorTypeCodeMap {
|
|
|
|
/* DOM4 errors from http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#domexception */
|
2018-06-26 00:20:54 +03:00
|
|
|
IndexSizeError = DOMException_Binding::INDEX_SIZE_ERR,
|
|
|
|
HierarchyRequestError = DOMException_Binding::HIERARCHY_REQUEST_ERR,
|
|
|
|
WrongDocumentError = DOMException_Binding::WRONG_DOCUMENT_ERR,
|
|
|
|
InvalidCharacterError = DOMException_Binding::INVALID_CHARACTER_ERR,
|
|
|
|
NoModificationAllowedError = DOMException_Binding::NO_MODIFICATION_ALLOWED_ERR,
|
|
|
|
NotFoundError = DOMException_Binding::NOT_FOUND_ERR,
|
|
|
|
NotSupportedError = DOMException_Binding::NOT_SUPPORTED_ERR,
|
2013-09-09 07:28:50 +04:00
|
|
|
// Can't remove until setNamedItem is removed
|
2018-06-26 00:20:54 +03:00
|
|
|
InUseAttributeError = DOMException_Binding::INUSE_ATTRIBUTE_ERR,
|
|
|
|
InvalidStateError = DOMException_Binding::INVALID_STATE_ERR,
|
|
|
|
SyntaxError = DOMException_Binding::SYNTAX_ERR,
|
|
|
|
InvalidModificationError = DOMException_Binding::INVALID_MODIFICATION_ERR,
|
|
|
|
NamespaceError = DOMException_Binding::NAMESPACE_ERR,
|
|
|
|
InvalidAccessError = DOMException_Binding::INVALID_ACCESS_ERR,
|
|
|
|
TypeMismatchError = DOMException_Binding::TYPE_MISMATCH_ERR,
|
|
|
|
SecurityError = DOMException_Binding::SECURITY_ERR,
|
|
|
|
NetworkError = DOMException_Binding::NETWORK_ERR,
|
|
|
|
AbortError = DOMException_Binding::ABORT_ERR,
|
|
|
|
URLMismatchError = DOMException_Binding::URL_MISMATCH_ERR,
|
|
|
|
QuotaExceededError = DOMException_Binding::QUOTA_EXCEEDED_ERR,
|
|
|
|
TimeoutError = DOMException_Binding::TIMEOUT_ERR,
|
|
|
|
InvalidNodeTypeError = DOMException_Binding::INVALID_NODE_TYPE_ERR,
|
|
|
|
DataCloneError = DOMException_Binding::DATA_CLONE_ERR,
|
2018-04-07 06:27:56 +03:00
|
|
|
InvalidPointerId = 0,
|
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,
|
2018-04-13 16:01:28 +03: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-07-06 10:44:43 +03:00
|
|
|
CopyUTF8toUTF16(mozilla::MakeStringSpan(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
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return Exception_Binding::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);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMException_Binding::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
|