mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
auto merge of #5099 : Ms2ger/servo/exceptions, r=saneyuki
This commit is contained in:
commit
5eaf1144c3
6 changed files with 60 additions and 64 deletions
|
@ -4643,7 +4643,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::codegen::{PrototypeList, RegisterBindings, UnionTypes}',
|
||||
'dom::bindings::codegen::Bindings::*',
|
||||
'dom::bindings::error::{Fallible, Error, ErrorResult}',
|
||||
'dom::bindings::error::Error::FailureUnknown',
|
||||
'dom::bindings::error::Error::JSFailed',
|
||||
'dom::bindings::error::throw_dom_exception',
|
||||
'dom::bindings::error::throw_type_error',
|
||||
'dom::bindings::proxyhandler',
|
||||
|
@ -4812,14 +4812,14 @@ class CGCallback(CGClass):
|
|||
|
||||
setupCall = ("let s = CallSetup::new(self, aExceptionHandling);\n"
|
||||
"if s.get_context().is_null() {\n"
|
||||
" return Err(FailureUnknown);\n"
|
||||
" return Err(JSFailed);\n"
|
||||
"}\n")
|
||||
|
||||
bodyWithThis = string.Template(
|
||||
setupCall+
|
||||
"let thisObjJS = wrap_call_this_object(s.get_context(), thisObj);\n"
|
||||
"if thisObjJS.is_null() {\n"
|
||||
" return Err(FailureUnknown);\n"
|
||||
" return Err(JSFailed);\n"
|
||||
"}\n"
|
||||
"return ${methodName}(${callArgs});").substitute({
|
||||
"callArgs" : ", ".join(argnamesWithThis),
|
||||
|
@ -4948,7 +4948,7 @@ class CallbackMember(CGNativeMember):
|
|||
jsObjectsArePtr=True)
|
||||
# We have to do all the generation of our body now, because
|
||||
# the caller relies on us throwing if we can't manage it.
|
||||
self.exceptionCode= "return Err(FailureUnknown);"
|
||||
self.exceptionCode = "return Err(JSFailed);"
|
||||
self.body = self.getImpl()
|
||||
|
||||
def getImpl(self):
|
||||
|
@ -5078,7 +5078,7 @@ class CallbackMember(CGNativeMember):
|
|||
"CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling);\n"
|
||||
"JSContext* cx = s.get_context();\n"
|
||||
"if (!cx) {\n"
|
||||
" return Err(FailureUnknown);\n"
|
||||
" return Err(JSFailed);\n"
|
||||
"}\n")
|
||||
|
||||
def getArgcDecl(self):
|
||||
|
@ -5123,7 +5123,7 @@ class CallbackMethod(CallbackMember):
|
|||
" ${argc}, ${argv}, &mut rval)\n"
|
||||
"};\n"
|
||||
"if ok == 0 {\n"
|
||||
" return Err(FailureUnknown);\n"
|
||||
" return Err(JSFailed);\n"
|
||||
"}\n").substitute(replacements)
|
||||
|
||||
class CallCallback(CallbackMethod):
|
||||
|
@ -5160,7 +5160,7 @@ class CallbackOperationBase(CallbackMethod):
|
|||
}
|
||||
getCallableFromProp = string.Template(
|
||||
'match self.parent.get_callable_property(cx, "${methodName}") {\n'
|
||||
' Err(_) => return Err(FailureUnknown),\n'
|
||||
' Err(_) => return Err(JSFailed),\n'
|
||||
' Ok(callable) => callable,\n'
|
||||
'}').substitute(replacements)
|
||||
if not self.singleOperation:
|
||||
|
@ -5204,7 +5204,7 @@ class CallbackGetter(CallbackMember):
|
|||
}
|
||||
return string.Template(
|
||||
'if (!JS_GetProperty(cx, mCallback, "${attrName}", &rval)) {\n'
|
||||
' return Err(FailureUnknown);\n'
|
||||
' return Err(JSFailed);\n'
|
||||
'}\n').substitute(replacements);
|
||||
|
||||
class CallbackSetter(CallbackMember):
|
||||
|
@ -5230,7 +5230,7 @@ class CallbackSetter(CallbackMember):
|
|||
return string.Template(
|
||||
'MOZ_ASSERT(argv.length() == 1);\n'
|
||||
'if (!JS_SetProperty(cx, mCallback, "${attrName}", ${argv})) {\n'
|
||||
' return Err(FailureUnknown);\n'
|
||||
' return Err(JSFailed);\n'
|
||||
'}\n').substitute(replacements)
|
||||
|
||||
def getArgcDecl(self):
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
use dom::bindings::conversions::ToJSValConvertible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::domexception::DOMException;
|
||||
use dom::domexception::{DOMException, DOMErrorName};
|
||||
|
||||
use util::str::DOMString;
|
||||
|
||||
use js::jsapi::{JSContext, JSBool, JSObject};
|
||||
use js::jsapi::{JS_IsExceptionPending, JS_SetPendingException, JS_ReportPendingException};
|
||||
|
@ -22,38 +24,42 @@ use std::ptr;
|
|||
/// DOM exceptions that can be thrown by a native DOM method.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Error {
|
||||
/// IndexSizeError
|
||||
/// IndexSizeError DOMException
|
||||
IndexSize,
|
||||
/// NotFoundError
|
||||
/// NotFoundError DOMException
|
||||
NotFound,
|
||||
/// HierarchyRequestError
|
||||
/// HierarchyRequestError DOMException
|
||||
HierarchyRequest,
|
||||
/// InvalidCharacterError
|
||||
/// InvalidCharacterError DOMException
|
||||
InvalidCharacter,
|
||||
/// NotSupportedError
|
||||
/// NotSupportedError DOMException
|
||||
NotSupported,
|
||||
/// InvalidStateError
|
||||
/// InvalidStateError DOMException
|
||||
InvalidState,
|
||||
/// SyntaxError
|
||||
/// SyntaxError DOMException
|
||||
Syntax,
|
||||
/// NamespaceError
|
||||
/// NamespaceError DOMException
|
||||
NamespaceError,
|
||||
/// InvalidAccessError
|
||||
/// InvalidAccessError DOMException
|
||||
InvalidAccess,
|
||||
/// SecurityError
|
||||
/// SecurityError DOMException
|
||||
Security,
|
||||
/// NetworkError
|
||||
/// NetworkError DOMException
|
||||
Network,
|
||||
/// AbortError
|
||||
/// AbortError DOMException
|
||||
Abort,
|
||||
/// TimeoutError
|
||||
/// TimeoutError DOMException
|
||||
Timeout,
|
||||
/// DataCloneError
|
||||
/// DataCloneError DOMException
|
||||
DataClone,
|
||||
/// NoModificationAllowedError
|
||||
/// NoModificationAllowedError DOMException
|
||||
NoModificationAllowedError,
|
||||
/// Unknown failure
|
||||
FailureUnknown,
|
||||
|
||||
/// TypeError JavaScript Error
|
||||
TypeError(DOMString),
|
||||
|
||||
/// A JavaScript exception is already pending.
|
||||
JSFailed,
|
||||
}
|
||||
|
||||
/// The return type for IDL operations that can throw DOM exceptions.
|
||||
|
@ -67,7 +73,29 @@ pub type ErrorResult = Fallible<()>;
|
|||
pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
|
||||
result: Error) {
|
||||
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
|
||||
let exception = DOMException::new_from_error(global, result).root();
|
||||
let code = match result {
|
||||
Error::IndexSize => DOMErrorName::IndexSizeError,
|
||||
Error::NotFound => DOMErrorName::NotFoundError,
|
||||
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
|
||||
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
|
||||
Error::NotSupported => DOMErrorName::NotSupportedError,
|
||||
Error::InvalidState => DOMErrorName::InvalidStateError,
|
||||
Error::Syntax => DOMErrorName::SyntaxError,
|
||||
Error::NamespaceError => DOMErrorName::NamespaceError,
|
||||
Error::InvalidAccess => DOMErrorName::InvalidAccessError,
|
||||
Error::Security => DOMErrorName::SecurityError,
|
||||
Error::Network => DOMErrorName::NetworkError,
|
||||
Error::Abort => DOMErrorName::AbortError,
|
||||
Error::Timeout => DOMErrorName::TimeoutError,
|
||||
Error::DataClone => DOMErrorName::DataCloneError,
|
||||
Error::NoModificationAllowedError => DOMErrorName::NoModificationAllowedError,
|
||||
Error::TypeError(message) => {
|
||||
throw_type_error(cx, &message);
|
||||
return;
|
||||
}
|
||||
Error::JSFailed => panic!(),
|
||||
};
|
||||
let exception = DOMException::new(global, code).root();
|
||||
let thrown = exception.to_jsval(cx);
|
||||
unsafe {
|
||||
JS_SetPendingException(cx, thrown);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use dom::bindings::codegen::Bindings::DOMExceptionBinding;
|
||||
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionConstants;
|
||||
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionMethods;
|
||||
use dom::bindings::error::Error;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
|
@ -40,29 +39,6 @@ pub enum DOMErrorName {
|
|||
EncodingError
|
||||
}
|
||||
|
||||
impl DOMErrorName {
|
||||
fn from_error(error: Error) -> DOMErrorName {
|
||||
match error {
|
||||
Error::IndexSize => DOMErrorName::IndexSizeError,
|
||||
Error::NotFound => DOMErrorName::NotFoundError,
|
||||
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
|
||||
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
|
||||
Error::NotSupported => DOMErrorName::NotSupportedError,
|
||||
Error::InvalidState => DOMErrorName::InvalidStateError,
|
||||
Error::Syntax => DOMErrorName::SyntaxError,
|
||||
Error::NamespaceError => DOMErrorName::NamespaceError,
|
||||
Error::InvalidAccess => DOMErrorName::InvalidAccessError,
|
||||
Error::Security => DOMErrorName::SecurityError,
|
||||
Error::Network => DOMErrorName::NetworkError,
|
||||
Error::Abort => DOMErrorName::AbortError,
|
||||
Error::Timeout => DOMErrorName::TimeoutError,
|
||||
Error::DataClone => DOMErrorName::DataCloneError,
|
||||
Error::NoModificationAllowedError => DOMErrorName::NoModificationAllowedError,
|
||||
Error::FailureUnknown => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
pub struct DOMException {
|
||||
reflector_: Reflector,
|
||||
|
@ -80,10 +56,6 @@ impl DOMException {
|
|||
pub fn new(global: GlobalRef, code: DOMErrorName) -> Temporary<DOMException> {
|
||||
reflect_dom_object(box DOMException::new_inherited(code), global, DOMExceptionBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn new_from_error(global: GlobalRef, code: Error) -> Temporary<DOMException> {
|
||||
DOMException::new(global, DOMErrorName::from_error(code))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> {
|
||||
|
|
|
@ -7,7 +7,6 @@ use dom::bindings::codegen::Bindings::DOMParserBinding;
|
|||
use dom::bindings::codegen::Bindings::DOMParserBinding::DOMParserMethods;
|
||||
use dom::bindings::codegen::Bindings::DOMParserBinding::SupportedType::{Text_html, Text_xml};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::error::Error::FailureUnknown;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
|
@ -69,9 +68,6 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
|
|||
Some(content_type),
|
||||
DocumentSource::NotFromParser))
|
||||
}
|
||||
_ => {
|
||||
Err(FailureUnknown)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
enum SupportedType {
|
||||
"text/html",
|
||||
"text/xml",
|
||||
"text/xml"/*,
|
||||
"application/xml",
|
||||
"application/xhtml+xml",
|
||||
"image/svg+xml"
|
||||
"image/svg+xml"*/
|
||||
};
|
||||
|
||||
[Constructor]
|
||||
|
|
|
@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
|||
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
||||
use dom::bindings::codegen::InheritTypes::DedicatedWorkerGlobalScopeCast;
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::Error::{Syntax, Network, FailureUnknown};
|
||||
use dom::bindings::error::Error::{Syntax, Network, JSFailed};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{MutNullableJS, JSRef, Temporary};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
|
@ -118,7 +118,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
|||
Ok(_) => (),
|
||||
Err(_) => {
|
||||
println!("evaluate_script failed");
|
||||
return Err(FailureUnknown);
|
||||
return Err(JSFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue