Bug 1403348: Part 3 - Support plain XPC Exceptions in ExtractErrorValues. r=baku

MozReview-Commit-ID: LrnE82vHjK

--HG--
extra : rebase_source : 4c8500c4e3a2eb0758b7fe678eda7255340b518c
This commit is contained in:
Kris Maglione 2017-11-09 12:32:15 -08:00
Родитель 41e3646a3a
Коммит 21c2757678
1 изменённых файлов: 47 добавлений и 16 удалений

Просмотреть файл

@ -71,6 +71,7 @@
#include "mozilla/ManualNAC.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/TextEvents.h"
#include "nsArrayUtils.h"
@ -10912,6 +10913,42 @@ nsContentUtils::IsOverridingWindowName(const nsAString& aName)
!aName.LowerCaseEqualsLiteral("_self");
}
// Unfortunately, we can't unwrap an IDL object using only a concrete type.
// We need to calculate type data based on the IDL typename. Which means
// wrapping our templated function in a macro.
#define EXTRACT_EXN_VALUES(T, ...) \
ExtractExceptionValues<mozilla::dom::prototypes::id::T, \
T##Binding::NativeType, T>(__VA_ARGS__).isOk()
template <prototypes::ID PrototypeID, class NativeType, typename T>
static Result<Ok, nsresult>
ExtractExceptionValues(JSContext* aCx,
JS::HandleObject aObj,
nsACString& aSourceSpecOut,
uint32_t* aLineOut,
uint32_t* aColumnOut,
nsString& aMessageOut)
{
RefPtr<T> exn;
MOZ_TRY((UnwrapObject<PrototypeID, NativeType>(aObj, exn)));
nsAutoString filename;
exn->GetFilename(aCx, filename);
if (!filename.IsEmpty()) {
CopyUTF16toUTF8(filename, aSourceSpecOut);
*aLineOut = exn->LineNumber(aCx);
*aColumnOut = exn->ColumnNumber();
}
exn->GetName(aMessageOut);
aMessageOut.AppendLiteral(": ");
nsAutoString message;
exn->GetMessageMoz(message);
aMessageOut.Append(message);
return Ok();
}
/* static */ void
nsContentUtils::ExtractErrorValues(JSContext* aCx,
JS::Handle<JS::Value> aValue,
@ -10925,7 +10962,6 @@ nsContentUtils::ExtractErrorValues(JSContext* aCx,
if (aValue.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
RefPtr<dom::DOMException> domException;
// Try to process as an Error object. Use the file/line/column values
// from the Error as they will be more specific to the root cause of
@ -10949,22 +10985,15 @@ nsContentUtils::ExtractErrorValues(JSContext* aCx,
}
// Next, try to unwrap the rejection value as a DOMException.
else if(NS_SUCCEEDED(UNWRAP_OBJECT(DOMException, obj, domException))) {
else if (EXTRACT_EXN_VALUES(DOMException, aCx, obj, aSourceSpecOut,
aLineOut, aColumnOut, aMessageOut)) {
return;
}
nsAutoString filename;
domException->GetFilename(aCx, filename);
if (!filename.IsEmpty()) {
CopyUTF16toUTF8(filename, aSourceSpecOut);
*aLineOut = domException->LineNumber(aCx);
*aColumnOut = domException->ColumnNumber();
}
domException->GetName(aMessageOut);
aMessageOut.AppendLiteral(": ");
nsAutoString message;
domException->GetMessageMoz(message);
aMessageOut.Append(message);
// Next, try to unwrap the rejection value as an XPC Exception.
else if (EXTRACT_EXN_VALUES(Exception, aCx, obj, aSourceSpecOut,
aLineOut, aColumnOut, aMessageOut)) {
return;
}
}
@ -10981,6 +11010,8 @@ nsContentUtils::ExtractErrorValues(JSContext* aCx,
}
}
#undef EXTRACT_EXN_VALUES
/* static */ bool
nsContentUtils::DevToolsEnabled(JSContext* aCx)
{