зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1107592 part 1. Implement a DOMException constructor. r=peterv
This commit is contained in:
Родитель
58dedbbec6
Коммит
7af8dba16f
|
@ -676,6 +676,34 @@ DOMException::GetMessageMoz(nsString& retval)
|
|||
CopyUTF8toUTF16(mMessage, retval);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsRefPtr<DOMException> retval =
|
||||
new DOMException(exceptionResult,
|
||||
NS_ConvertUTF16toUTF8(aMessage),
|
||||
name,
|
||||
exceptionCode);
|
||||
return retval.forget();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
DOMException::WrapObject(JSContext* aCx)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,8 @@ class ErrorResult;
|
|||
|
||||
namespace dom {
|
||||
|
||||
class GlobalObject;
|
||||
|
||||
#define MOZILLA_EXCEPTION_IID \
|
||||
{ 0x55eda557, 0xeba0, 0x4fe3, \
|
||||
{ 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } }
|
||||
|
@ -136,6 +138,12 @@ public:
|
|||
virtual JSObject* WrapObject(JSContext* aCx)
|
||||
MOZ_OVERRIDE;
|
||||
|
||||
static already_AddRefed<DOMException>
|
||||
Constructor(GlobalObject& /* unused */,
|
||||
const nsAString& aMessage,
|
||||
const Optional<nsAString>& aName,
|
||||
ErrorResult& aError);
|
||||
|
||||
uint16_t Code() const {
|
||||
return mCode;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,23 @@ for (var i = 0; i < constants.length; ++i) {
|
|||
if (constant)
|
||||
is(DOMException[constant], i, constant)
|
||||
}
|
||||
|
||||
var ex = new DOMException();
|
||||
ise(ex.name, "Error",
|
||||
"Not passing a name should end up with 'Error' as the name");
|
||||
ise(ex.message, "",
|
||||
"Not passing a message should end up with empty string as the message");
|
||||
|
||||
ex = new DOMException("foo");
|
||||
ise(ex.name, "Error",
|
||||
"Not passing a name should still end up with 'Error' as the name");
|
||||
ise(ex.message, "foo", "Should be using passed-in message");
|
||||
|
||||
ex = new DOMException("bar", "NotSupportedError");
|
||||
ise(ex.name, "NotSupportedError", "Should be using the passed-in name");
|
||||
ise(ex.message, "bar", "Should still be using passed-in message");
|
||||
ise(ex.code, DOMException.NOT_SUPPORTED_ERR,
|
||||
"Should have the right exception code");
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -74,7 +74,8 @@ Exception implements ExceptionMembers;
|
|||
// XXXkhuey this is an 'exception', not an interface, but we don't have any
|
||||
// parser or codegen mechanisms for dealing with exceptions.
|
||||
[ExceptionClass,
|
||||
Exposed=(Window, Worker)]
|
||||
Exposed=(Window, Worker),
|
||||
Constructor(optional DOMString message = "", optional DOMString name)]
|
||||
interface DOMException {
|
||||
const unsigned short INDEX_SIZE_ERR = 1;
|
||||
const unsigned short DOMSTRING_SIZE_ERR = 2; // historical
|
||||
|
|
Загрузка…
Ссылка в новой задаче