Nacre/vendor/servo-script/dom/serviceworker/extendableevent.rs
astar76 0ecfd0f573 S031: root due timers in vendored servo-script (R5-01 SIGSEGV), crash-adblock regression smoke
fire_timer moved due timers into an unrooted Vec; a GC inside one callback swept
the functions of the timers still waiting. Heavy-web reruns and cargo test still pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 20:38:47 -06:00

103 lines
3.1 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use js::context::JSContext;
use js::rust::{HandleObject, HandleValue};
use script_bindings::reflector::reflect_dom_object_with_proto;
use stylo_atoms::Atom;
use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use crate::dom::bindings::codegen::Bindings::ExtendableEventBinding::{
ExtendableEventInit, ExtendableEventMethods,
};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
use crate::dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
// https://w3c.github.io/ServiceWorker/#extendable-event
#[dom_struct]
pub(crate) struct ExtendableEvent {
event: Event,
extensions_allowed: bool,
}
impl ExtendableEvent {
pub(crate) fn new_inherited() -> ExtendableEvent {
ExtendableEvent {
event: Event::new_inherited(),
extensions_allowed: true,
}
}
pub(crate) fn new(
cx: &mut JSContext,
worker: &ServiceWorkerGlobalScope,
type_: Atom,
bubbles: bool,
cancelable: bool,
) -> DomRoot<ExtendableEvent> {
Self::new_with_proto(cx, worker, None, type_, bubbles, cancelable)
}
fn new_with_proto(
cx: &mut JSContext,
worker: &ServiceWorkerGlobalScope,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
cancelable: bool,
) -> DomRoot<ExtendableEvent> {
let ev = reflect_dom_object_with_proto(
cx,
Box::new(ExtendableEvent::new_inherited()),
worker,
proto,
);
{
let event = ev.upcast::<Event>();
event.init_event(type_, bubbles, cancelable);
}
ev
}
}
impl ExtendableEventMethods<crate::DomTypeHolder> for ExtendableEvent {
/// <https://w3c.github.io/ServiceWorker/#dom-extendableevent-extendableevent>
fn Constructor(
cx: &mut JSContext,
worker: &ServiceWorkerGlobalScope,
proto: Option<HandleObject>,
type_: DOMString,
init: &ExtendableEventInit,
) -> Fallible<DomRoot<ExtendableEvent>> {
Ok(ExtendableEvent::new_with_proto(
cx,
worker,
proto,
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
))
}
/// <https://w3c.github.io/ServiceWorker/#wait-until-method>
fn WaitUntil(&self, _val: HandleValue) -> ErrorResult {
// Step 1
if !self.extensions_allowed {
return Err(Error::InvalidState(None));
}
// Step 2
// TODO add a extended_promises array to enqueue the `val`
Ok(())
}
/// <https://dom.spec.whatwg.org/#dom-event-istrusted>
fn IsTrusted(&self) -> bool {
self.event.IsTrusted()
}
}