mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
3e21182565
commit
aaa34e9bd3
@ -23,6 +23,7 @@
|
||||
#include "xpcprivate.h"
|
||||
#include "XPCQuickStubs.h"
|
||||
#include "XrayWrapper.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
#include "mozilla/dom/HTMLObjectElement.h"
|
||||
#include "mozilla/dom/HTMLObjectElementBinding.h"
|
||||
@ -196,6 +197,17 @@ ErrorResult::StealJSException(JSContext* cx,
|
||||
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 {
|
||||
|
||||
bool
|
||||
|
@ -84,8 +84,8 @@ Throw(JSContext* cx, nsresult rv)
|
||||
template<bool mainThread>
|
||||
inline bool
|
||||
ThrowMethodFailedWithDetails(JSContext* cx, ErrorResult& rv,
|
||||
const char* /* ifaceName */,
|
||||
const char* /* memberName */)
|
||||
const char* ifaceName,
|
||||
const char* memberName)
|
||||
{
|
||||
if (rv.IsTypeError()) {
|
||||
rv.ReportTypeError(cx);
|
||||
@ -95,6 +95,9 @@ ThrowMethodFailedWithDetails(JSContext* cx, ErrorResult& rv,
|
||||
rv.ReportJSException(cx);
|
||||
return false;
|
||||
}
|
||||
if (rv.IsNotEnoughArgsError()) {
|
||||
rv.ReportNotEnoughArgsError(cx, ifaceName, memberName);
|
||||
}
|
||||
return Throw<mainThread>(cx, rv.ErrorCode());
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
MOZ_ASSERT(!IsTypeError(), "Don't overwite TypeError");
|
||||
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
|
||||
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;
|
||||
}
|
||||
|
||||
@ -71,6 +73,12 @@ public:
|
||||
void ReportJSException(JSContext* cx);
|
||||
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
|
||||
// be called only if IsJSException() returns true. This method also resets the
|
||||
// ErrorCode() to NS_OK.
|
||||
@ -101,6 +109,8 @@ public:
|
||||
MOZ_ASSERT(!IsTypeError(), "Don't overwite TypeError");
|
||||
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user