script/dom/
fetchlaterresult.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::sync::{Arc, Mutex};
6
7use dom_struct::dom_struct;
8
9use crate::dom::bindings::codegen::Bindings::FetchLaterResultBinding::FetchLaterResultMethods;
10use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::window::Window;
13use crate::fetch::DeferredFetchRecord;
14use crate::script_runtime::CanGc;
15
16/// <https://fetch.spec.whatwg.org/#fetchlaterresult>
17#[dom_struct]
18pub(crate) struct FetchLaterResult {
19    reflector_: Reflector,
20
21    /// <https://fetch.spec.whatwg.org/#fetchlaterresult-activated-getter-steps>
22    #[conditional_malloc_size_of]
23    #[no_trace]
24    activated_getter_steps: Arc<Mutex<DeferredFetchRecord>>,
25}
26
27impl FetchLaterResult {
28    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
29    fn new_inherited(activated_getter_steps: Arc<Mutex<DeferredFetchRecord>>) -> FetchLaterResult {
30        FetchLaterResult {
31            reflector_: Reflector::new(),
32            activated_getter_steps,
33        }
34    }
35
36    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
37    pub(crate) fn new(
38        window: &Window,
39        activated_getter_steps: Arc<Mutex<DeferredFetchRecord>>,
40        can_gc: CanGc,
41    ) -> DomRoot<FetchLaterResult> {
42        reflect_dom_object(
43            Box::new(FetchLaterResult::new_inherited(activated_getter_steps)),
44            window,
45            can_gc,
46        )
47    }
48}
49
50impl FetchLaterResultMethods<crate::DomTypeHolder> for FetchLaterResult {
51    /// <https://fetch.spec.whatwg.org/#dom-fetchlaterresult-activated>
52    fn Activated(&self) -> bool {
53        // The activated getter steps are to return the result of running this’s activated getter steps.
54        self.activated_getter_steps
55            .lock()
56            .expect("Activated getter not accessible")
57            .activated_getter_steps()
58    }
59}