зеркало из https://github.com/mozilla/gecko-dev.git
Bug 889016 - Part 1: Add an API to report a not-enough-arguments error in Web IDL bindings; r=bzbarsky
This commit is contained in:
Родитель
0b7fe769e3
Коммит
7721ae648c
|
@ -23,6 +23,7 @@
|
||||||
#include "xpcprivate.h"
|
#include "xpcprivate.h"
|
||||||
#include "XPCQuickStubs.h"
|
#include "XPCQuickStubs.h"
|
||||||
#include "XrayWrapper.h"
|
#include "XrayWrapper.h"
|
||||||
|
#include "nsPrintfCString.h"
|
||||||
|
|
||||||
#include "mozilla/dom/HTMLObjectElement.h"
|
#include "mozilla/dom/HTMLObjectElement.h"
|
||||||
#include "mozilla/dom/HTMLObjectElementBinding.h"
|
#include "mozilla/dom/HTMLObjectElementBinding.h"
|
||||||
|
@ -196,6 +197,17 @@ ErrorResult::StealJSException(JSContext* cx,
|
||||||
mResult = NS_OK;
|
mResult = NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ErrorResult::ReportNotEnoughArgsError(JSContext* cx,
|
||||||
|
const char* ifaceName,
|
||||||
|
const char* memberName)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(ErrorCode() == NS_ERROR_XPC_NOT_ENOUGH_ARGS);
|
||||||
|
|
||||||
|
nsPrintfCString errorMessage("%s.%s", ifaceName, memberName);
|
||||||
|
ThrowErrorMessage(cx, dom::MSG_MISSING_ARGUMENTS, errorMessage.get());
|
||||||
|
}
|
||||||
|
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -84,8 +84,8 @@ Throw(JSContext* cx, nsresult rv)
|
||||||
template<bool mainThread>
|
template<bool mainThread>
|
||||||
inline bool
|
inline bool
|
||||||
ThrowMethodFailedWithDetails(JSContext* cx, ErrorResult& rv,
|
ThrowMethodFailedWithDetails(JSContext* cx, ErrorResult& rv,
|
||||||
const char* /* ifaceName */,
|
const char* ifaceName,
|
||||||
const char* /* memberName */)
|
const char* memberName)
|
||||||
{
|
{
|
||||||
if (rv.IsTypeError()) {
|
if (rv.IsTypeError()) {
|
||||||
rv.ReportTypeError(cx);
|
rv.ReportTypeError(cx);
|
||||||
|
@ -95,6 +95,9 @@ ThrowMethodFailedWithDetails(JSContext* cx, ErrorResult& rv,
|
||||||
rv.ReportJSException(cx);
|
rv.ReportJSException(cx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (rv.IsNotEnoughArgsError()) {
|
||||||
|
rv.ReportNotEnoughArgsError(cx, ifaceName, memberName);
|
||||||
|
}
|
||||||
return Throw<mainThread>(cx, rv.ErrorCode());
|
return Throw<mainThread>(cx, rv.ErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
MOZ_ASSERT(!IsTypeError(), "Don't overwite TypeError");
|
MOZ_ASSERT(!IsTypeError(), "Don't overwite TypeError");
|
||||||
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
|
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
|
||||||
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
|
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
|
||||||
|
MOZ_ASSERT(rv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "Use ThrowNotEnoughArgsError()");
|
||||||
|
MOZ_ASSERT(!IsNotEnoughArgsError(), "Don't overwrite not enough args error");
|
||||||
mResult = rv;
|
mResult = rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +73,12 @@ public:
|
||||||
void ReportJSException(JSContext* cx);
|
void ReportJSException(JSContext* cx);
|
||||||
bool IsJSException() const { return ErrorCode() == NS_ERROR_DOM_JS_EXCEPTION; }
|
bool IsJSException() const { return ErrorCode() == NS_ERROR_DOM_JS_EXCEPTION; }
|
||||||
|
|
||||||
|
void ThrowNotEnoughArgsError() { mResult = NS_ERROR_XPC_NOT_ENOUGH_ARGS; }
|
||||||
|
void ReportNotEnoughArgsError(JSContext* cx,
|
||||||
|
const char* ifaceName,
|
||||||
|
const char* memberName);
|
||||||
|
bool IsNotEnoughArgsError() const { return ErrorCode() == NS_ERROR_XPC_NOT_ENOUGH_ARGS; }
|
||||||
|
|
||||||
// StealJSException steals the JS Exception from the object. This method must
|
// StealJSException steals the JS Exception from the object. This method must
|
||||||
// be called only if IsJSException() returns true. This method also resets the
|
// be called only if IsJSException() returns true. This method also resets the
|
||||||
// ErrorCode() to NS_OK.
|
// ErrorCode() to NS_OK.
|
||||||
|
@ -101,6 +109,8 @@ public:
|
||||||
MOZ_ASSERT(!IsTypeError(), "Don't overwite TypeError");
|
MOZ_ASSERT(!IsTypeError(), "Don't overwite TypeError");
|
||||||
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
|
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
|
||||||
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
|
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
|
||||||
|
MOZ_ASSERT(rv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "Use ThrowNotEnoughArgsError()");
|
||||||
|
MOZ_ASSERT(!IsNotEnoughArgsError(), "Don't overwrite not enough args error");
|
||||||
mResult = rv;
|
mResult = rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче