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