mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Introduce rejectionhandled event
This commit is contained in:
parent
b1a2b6b5bf
commit
23a4d646ce
5 changed files with 40 additions and 18 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -2213,7 +2213,7 @@ dependencies = [
|
|||
"hyper 0.12.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozjs 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozjs 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.20.0",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2435,7 +2435,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mozjs"
|
||||
version = "0.9.3"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3213,7 +3213,7 @@ dependencies = [
|
|||
"mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozjs 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozjs 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -4938,7 +4938,7 @@ dependencies = [
|
|||
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
||||
"checksum mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f"
|
||||
"checksum mozangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "45a8a18a41cfab0fde25cc2f43ea89064d211a0fbb33225b8ff93ab20406e0e7"
|
||||
"checksum mozjs 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bd0bdded611cb03c8ca638e0b663befe67eb7fbcb1fe2dfd25061656ee4ff365"
|
||||
"checksum mozjs 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2c7319f00f7847cca3290f7af7cef5947110f62fe5c792a6c4cb9a4518076d96"
|
||||
"checksum mozjs_sys 0.61.2 (registry+https://github.com/rust-lang/crates.io-index)" = "28276d28cc79226f3a26c790f00c8ce74459d097d3698f17df05ab9f683c1e52"
|
||||
"checksum msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aad9dfe950c057b1bfe9c1f2aa51583a8468ef2a5baba2ebbe06d775efeb7729"
|
||||
"checksum muldiv 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "451a9a05d2a32c566c897835e0ea95cf79ed2fdfe957924045a1721a36c9980f"
|
||||
|
|
|
@ -65,6 +65,7 @@ radio
|
|||
range
|
||||
readystatechange
|
||||
reftest-wait
|
||||
rejectionhandled
|
||||
reset
|
||||
resize
|
||||
right
|
||||
|
|
|
@ -32,7 +32,7 @@ hashglobe = { path = "../hashglobe" }
|
|||
hyper = { version = "0.12", optional = true }
|
||||
hyper_serde = { version = "0.9", optional = true }
|
||||
keyboard-types = {version = "0.4.3", optional = true}
|
||||
mozjs = { version = "0.9.3", optional = true }
|
||||
mozjs = { version = "0.9.4", optional = true }
|
||||
selectors = { path = "../selectors" }
|
||||
serde = { version = "1.0.27", optional = true }
|
||||
serde_bytes = { version = "0.10", optional = true }
|
||||
|
|
|
@ -63,7 +63,7 @@ hyper_serde = "0.9"
|
|||
image = "0.19"
|
||||
ipc-channel = "0.11"
|
||||
itertools = "0.7.6"
|
||||
js = {package = "mozjs", version = "0.9.3"}
|
||||
js = {package = "mozjs", version = "0.9.4"}
|
||||
jstraceable_derive = {path = "../jstraceable_derive"}
|
||||
keyboard-types = "0.4.3"
|
||||
lazy_static = "1"
|
||||
|
|
|
@ -41,6 +41,7 @@ use js::jsapi::{SetBuildIdOp, SetEnqueuePromiseJobCallback, SetPromiseRejectionT
|
|||
use js::panic::wrap_panic;
|
||||
use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult};
|
||||
use js::rust::Handle;
|
||||
use js::rust::IntoHandle;
|
||||
use js::rust::Runtime as RustRuntime;
|
||||
use malloc_size_of::MallocSizeOfOps;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
|
@ -152,7 +153,7 @@ unsafe extern "C" fn enqueue_job(
|
|||
)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[allow(unsafe_code, unrooted_must_root)]
|
||||
/// https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation
|
||||
unsafe extern "C" fn promise_rejection_tracker(
|
||||
cx: *mut JSContext,
|
||||
|
@ -190,14 +191,38 @@ unsafe extern "C" fn promise_rejection_tracker(
|
|||
.borrow()
|
||||
.contains(&Heap::boxed(promise.get()))
|
||||
{
|
||||
global.add_consumed_rejection(promise);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 5-3.
|
||||
global.remove_consumed_rejection(promise);
|
||||
|
||||
// TODO: Step 5-4 - Queue a task to fire `rejectionhandled` event
|
||||
let target = Trusted::new(global.upcast::<EventTarget>());
|
||||
let promise = Promise::new_with_js_promise(Handle::from_raw(promise), cx);
|
||||
let trusted_promise = TrustedPromise::new(promise.clone());
|
||||
|
||||
// Step 5-4.
|
||||
global.dom_manipulation_task_source().queue(
|
||||
task!(rejection_handled_event: move || {
|
||||
let target = target.root();
|
||||
let cx = target.global().get_cx();
|
||||
let root_promise = trusted_promise.root();
|
||||
|
||||
rooted!(in(cx) let reason = GetPromiseResult(root_promise.reflector().get_jsobject()));
|
||||
|
||||
let event = PromiseRejectionEvent::new(
|
||||
&target.global(),
|
||||
atom!("rejectionhandled"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
root_promise,
|
||||
reason.handle()
|
||||
);
|
||||
|
||||
event.upcast::<Event>().fire(&target);
|
||||
}),
|
||||
global.upcast(),
|
||||
).unwrap();
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
@ -254,7 +279,7 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) {
|
|||
atom!("unhandledrejection"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
promise,
|
||||
promise.clone(),
|
||||
reason.handle()
|
||||
);
|
||||
|
||||
|
@ -265,19 +290,15 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) {
|
|||
// TODO: The promise rejection is not handled; we need to add it back to the list.
|
||||
}
|
||||
|
||||
// TODO: Step 4-4 - If [[PromiseIsHandled]] is false, add promise to consumed_rejections
|
||||
// Step 4-4.
|
||||
if !promise_is_handled {
|
||||
target.global().add_consumed_rejection(promise.reflector().get_jsobject().into_handle());
|
||||
}
|
||||
}
|
||||
}),
|
||||
global.upcast(),
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
if global.get_consumed_rejections().borrow().len() > 0 {
|
||||
// FIXME(cybai): Implement `rejectionhandled` event instead of clearing the whole
|
||||
// consumed rejections
|
||||
// https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation
|
||||
global.get_consumed_rejections().borrow_mut().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue