зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1306200 part 1. Move the "report this error now" machinery from Debugger.cpp to ErrorReporting. r=waldo
This allows other consumers to share this machinery.
This commit is contained in:
Родитель
ef4af45102
Коммит
d8b203fe04
|
@ -1353,26 +1353,6 @@ Debugger::unwrapPropertyDescriptor(JSContext* cx, HandleObject obj,
|
|||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class MOZ_STACK_CLASS ReportExceptionClosure : public ScriptEnvironmentPreparer::Closure
|
||||
{
|
||||
public:
|
||||
explicit ReportExceptionClosure(RootedValue& exn)
|
||||
: exn_(exn)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()(JSContext* cx) override
|
||||
{
|
||||
cx->setPendingException(exn_);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
RootedValue& exn_;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
JSTrapStatus
|
||||
Debugger::reportUncaughtException(Maybe<AutoCompartment>& ac)
|
||||
{
|
||||
|
@ -1395,13 +1375,11 @@ Debugger::reportUncaughtException(Maybe<AutoCompartment>& ac)
|
|||
RootedValue exn(cx);
|
||||
if (cx->getPendingException(&exn)) {
|
||||
/*
|
||||
* Clear the exception, because
|
||||
* PrepareScriptEnvironmentAndInvoke will assert that we don't
|
||||
* have one.
|
||||
* Clear the exception, because ReportErrorToGlobal will assert that
|
||||
* we don't have one.
|
||||
*/
|
||||
cx->clearPendingException();
|
||||
ReportExceptionClosure reportExn(exn);
|
||||
PrepareScriptEnvironmentAndInvoke(cx, cx->global(), reportExn);
|
||||
ReportErrorToGlobal(cx, cx->global(), exn);
|
||||
}
|
||||
/*
|
||||
* And if not, or if PrepareScriptEnvironmentAndInvoke somehow left
|
||||
|
|
|
@ -12,9 +12,12 @@
|
|||
|
||||
#include "jscntxt.h"
|
||||
#include "jsexn.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
using mozilla::Move;
|
||||
|
||||
using JS::HandleObject;
|
||||
using JS::HandleValue;
|
||||
using JS::UniqueTwoByteChars;
|
||||
|
||||
void
|
||||
|
@ -118,3 +121,40 @@ js::ReportCompileError(JSContext* cx, ErrorMetadata&& metadata, UniquePtr<JSErro
|
|||
if (!cx->helperThread())
|
||||
err->throwError(cx);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class MOZ_STACK_CLASS ReportExceptionClosure
|
||||
: public js::ScriptEnvironmentPreparer::Closure
|
||||
{
|
||||
public:
|
||||
explicit ReportExceptionClosure(HandleValue& exn)
|
||||
: exn_(exn)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()(JSContext* cx) override
|
||||
{
|
||||
cx->setPendingException(exn_);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
HandleValue& exn_;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void
|
||||
js::ReportErrorToGlobal(JSContext* cx, HandleObject global, HandleValue error)
|
||||
{
|
||||
MOZ_ASSERT(!cx->isExceptionPending());
|
||||
#ifdef DEBUG
|
||||
// No assertSameCompartment version that doesn't take JSContext...
|
||||
if (error.isObject()) {
|
||||
AssertSameCompartment(global, &error.toObject());
|
||||
}
|
||||
#endif // DEBUG
|
||||
ReportExceptionClosure report(error);
|
||||
PrepareScriptEnvironmentAndInvoke(cx, global, report);
|
||||
}
|
||||
|
|
|
@ -86,6 +86,14 @@ extern MOZ_MUST_USE bool
|
|||
ReportCompileWarning(JSContext* cx, ErrorMetadata&& metadata, UniquePtr<JSErrorNotes> notes,
|
||||
unsigned flags, unsigned errorNumber, va_list args);
|
||||
|
||||
/**
|
||||
* Report the given error Value to the given global. The JSContext is not
|
||||
* assumed to be in any particular compartment, but the global and error are
|
||||
* expected to be same-compartment.
|
||||
*/
|
||||
extern void
|
||||
ReportErrorToGlobal(JSContext* cx, JS::HandleObject global, JS::HandleValue error);
|
||||
|
||||
} // namespace js
|
||||
|
||||
#endif /* vm_ErrorReporting_h */
|
||||
|
|
Загрузка…
Ссылка в новой задаче