Make throw_dom_exception take a &GlobalScope

This commit is contained in:
Anthony Ramine 2016-10-01 18:21:06 +02:00
parent ae6af5172b
commit 896d8d4781
3 changed files with 10 additions and 10 deletions

View file

@ -826,7 +826,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
match Promise::Resolve(promiseGlobal.r(), cx, valueToResolve.handle()) {
Ok(value) => value,
Err(error) => {
throw_dom_exception(cx, promiseGlobal.r(), error);
throw_dom_exception(cx, promiseGlobal.r().as_global_scope(), error);
$*{exceptionCode}
}
}
@ -3168,16 +3168,15 @@ class CGCallGenerator(CGThing):
if isFallible:
if static:
glob = ""
glob = "global.r().as_global_scope()"
else:
glob = " let global = global_root_from_reflector(this);\n"
glob = "&global_scope_from_reflector(this)"
self.cgRoot.append(CGGeneric(
"let result = match result {\n"
" Ok(result) => result,\n"
" Err(e) => {\n"
"%s"
" throw_dom_exception(cx, global.r(), e);\n"
" throw_dom_exception(cx, %s, e);\n"
" return%s;\n"
" },\n"
"};" % (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_maybe_wrapped',
'dom::bindings::global::global_root_from_reflector',
'dom::bindings::global::global_scope_from_reflector',
'dom::bindings::interface::ConstructorClassHook',
'dom::bindings::interface::InterfaceConstructorBehavior',
'dom::bindings::interface::NonCallbackInterfaceObjectClass',

View file

@ -11,6 +11,7 @@ use dom::bindings::conversions::root_from_object;
use dom::bindings::global::{GlobalRef, global_root_from_context};
use dom::bindings::str::USVString;
use dom::domexception::{DOMErrorName, DOMException};
use dom::globalscope::GlobalScope;
use js::error::{throw_range_error, throw_type_error};
use js::jsapi::HandleObject;
use js::jsapi::JSContext;
@ -87,7 +88,7 @@ pub type Fallible<T> = Result<T, Error>;
pub type ErrorResult = Fallible<()>;
/// 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 {
Error::IndexSize => DOMErrorName::IndexSizeError,
Error::NotFound => DOMErrorName::NotFoundError,
@ -127,7 +128,7 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef, result:
};
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());
exception.to_jsval(cx, thrown.handle_mut());
JS_SetPendingException(cx, thrown.handle());
@ -272,7 +273,7 @@ impl Error {
/// 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) {
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_GetPendingException(cx, rval));
JS_ClearPendingException(cx);

View file

@ -973,9 +973,8 @@ impl XMLHttpRequest {
if self.ready_state.get() == XMLHttpRequestState::HeadersReceived {
self.ready_state.set(XMLHttpRequestState::Loading);
}
let global = self.global();
let event = Event::new(
global.r().as_global_scope(),
&self.global_scope(),
atom!("readystatechange"),
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable);