mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make throw_dom_exception take a &GlobalScope
This commit is contained in:
parent
ae6af5172b
commit
896d8d4781
3 changed files with 10 additions and 10 deletions
|
@ -826,7 +826,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
match Promise::Resolve(promiseGlobal.r(), cx, valueToResolve.handle()) {
|
match Promise::Resolve(promiseGlobal.r(), cx, valueToResolve.handle()) {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
throw_dom_exception(cx, promiseGlobal.r(), error);
|
throw_dom_exception(cx, promiseGlobal.r().as_global_scope(), error);
|
||||||
$*{exceptionCode}
|
$*{exceptionCode}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3168,16 +3168,15 @@ class CGCallGenerator(CGThing):
|
||||||
|
|
||||||
if isFallible:
|
if isFallible:
|
||||||
if static:
|
if static:
|
||||||
glob = ""
|
glob = "global.r().as_global_scope()"
|
||||||
else:
|
else:
|
||||||
glob = " let global = global_root_from_reflector(this);\n"
|
glob = "&global_scope_from_reflector(this)"
|
||||||
|
|
||||||
self.cgRoot.append(CGGeneric(
|
self.cgRoot.append(CGGeneric(
|
||||||
"let result = match result {\n"
|
"let result = match result {\n"
|
||||||
" Ok(result) => result,\n"
|
" Ok(result) => result,\n"
|
||||||
" Err(e) => {\n"
|
" Err(e) => {\n"
|
||||||
"%s"
|
" throw_dom_exception(cx, %s, e);\n"
|
||||||
" throw_dom_exception(cx, global.r(), e);\n"
|
|
||||||
" return%s;\n"
|
" return%s;\n"
|
||||||
" },\n"
|
" },\n"
|
||||||
"};" % (glob, errorResult)))
|
"};" % (glob, errorResult)))
|
||||||
|
@ -5504,6 +5503,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
||||||
'dom::bindings::global::global_root_from_object',
|
'dom::bindings::global::global_root_from_object',
|
||||||
'dom::bindings::global::global_root_from_object_maybe_wrapped',
|
'dom::bindings::global::global_root_from_object_maybe_wrapped',
|
||||||
'dom::bindings::global::global_root_from_reflector',
|
'dom::bindings::global::global_root_from_reflector',
|
||||||
|
'dom::bindings::global::global_scope_from_reflector',
|
||||||
'dom::bindings::interface::ConstructorClassHook',
|
'dom::bindings::interface::ConstructorClassHook',
|
||||||
'dom::bindings::interface::InterfaceConstructorBehavior',
|
'dom::bindings::interface::InterfaceConstructorBehavior',
|
||||||
'dom::bindings::interface::NonCallbackInterfaceObjectClass',
|
'dom::bindings::interface::NonCallbackInterfaceObjectClass',
|
||||||
|
|
|
@ -11,6 +11,7 @@ use dom::bindings::conversions::root_from_object;
|
||||||
use dom::bindings::global::{GlobalRef, global_root_from_context};
|
use dom::bindings::global::{GlobalRef, global_root_from_context};
|
||||||
use dom::bindings::str::USVString;
|
use dom::bindings::str::USVString;
|
||||||
use dom::domexception::{DOMErrorName, DOMException};
|
use dom::domexception::{DOMErrorName, DOMException};
|
||||||
|
use dom::globalscope::GlobalScope;
|
||||||
use js::error::{throw_range_error, throw_type_error};
|
use js::error::{throw_range_error, throw_type_error};
|
||||||
use js::jsapi::HandleObject;
|
use js::jsapi::HandleObject;
|
||||||
use js::jsapi::JSContext;
|
use js::jsapi::JSContext;
|
||||||
|
@ -87,7 +88,7 @@ pub type Fallible<T> = Result<T, Error>;
|
||||||
pub type ErrorResult = Fallible<()>;
|
pub type ErrorResult = Fallible<()>;
|
||||||
|
|
||||||
/// Set a pending exception for the given `result` on `cx`.
|
/// Set a pending exception for the given `result` on `cx`.
|
||||||
pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef, result: Error) {
|
pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: &GlobalScope, result: Error) {
|
||||||
let code = match result {
|
let code = match result {
|
||||||
Error::IndexSize => DOMErrorName::IndexSizeError,
|
Error::IndexSize => DOMErrorName::IndexSizeError,
|
||||||
Error::NotFound => DOMErrorName::NotFoundError,
|
Error::NotFound => DOMErrorName::NotFoundError,
|
||||||
|
@ -127,7 +128,7 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef, result:
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(!JS_IsExceptionPending(cx));
|
assert!(!JS_IsExceptionPending(cx));
|
||||||
let exception = DOMException::new(global.as_global_scope(), code);
|
let exception = DOMException::new(global, code);
|
||||||
rooted!(in(cx) let mut thrown = UndefinedValue());
|
rooted!(in(cx) let mut thrown = UndefinedValue());
|
||||||
exception.to_jsval(cx, thrown.handle_mut());
|
exception.to_jsval(cx, thrown.handle_mut());
|
||||||
JS_SetPendingException(cx, thrown.handle());
|
JS_SetPendingException(cx, thrown.handle());
|
||||||
|
@ -272,7 +273,7 @@ impl Error {
|
||||||
/// Convert this error value to a JS value, consuming it in the process.
|
/// Convert this error value to a JS value, consuming it in the process.
|
||||||
pub unsafe fn to_jsval(self, cx: *mut JSContext, global: GlobalRef, rval: MutableHandleValue) {
|
pub unsafe fn to_jsval(self, cx: *mut JSContext, global: GlobalRef, rval: MutableHandleValue) {
|
||||||
assert!(!JS_IsExceptionPending(cx));
|
assert!(!JS_IsExceptionPending(cx));
|
||||||
throw_dom_exception(cx, global, self);
|
throw_dom_exception(cx, global.as_global_scope(), self);
|
||||||
assert!(JS_IsExceptionPending(cx));
|
assert!(JS_IsExceptionPending(cx));
|
||||||
assert!(JS_GetPendingException(cx, rval));
|
assert!(JS_GetPendingException(cx, rval));
|
||||||
JS_ClearPendingException(cx);
|
JS_ClearPendingException(cx);
|
||||||
|
|
|
@ -973,9 +973,8 @@ impl XMLHttpRequest {
|
||||||
if self.ready_state.get() == XMLHttpRequestState::HeadersReceived {
|
if self.ready_state.get() == XMLHttpRequestState::HeadersReceived {
|
||||||
self.ready_state.set(XMLHttpRequestState::Loading);
|
self.ready_state.set(XMLHttpRequestState::Loading);
|
||||||
}
|
}
|
||||||
let global = self.global();
|
|
||||||
let event = Event::new(
|
let event = Event::new(
|
||||||
global.r().as_global_scope(),
|
&self.global_scope(),
|
||||||
atom!("readystatechange"),
|
atom!("readystatechange"),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue