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 dom_struct::dom_struct;
6
7use crate::dom::bindings::codegen::Bindings::FetchLaterResultBinding::FetchLaterResultMethods;
8use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
9use crate::dom::bindings::root::DomRoot;
10use crate::dom::window::Window;
11use crate::fetch::DeferredFetchRecordId;
12use crate::script_runtime::CanGc;
13
14/// <https://fetch.spec.whatwg.org/#fetchlaterresult>
15#[dom_struct]
16pub(crate) struct FetchLaterResult {
17    reflector_: Reflector,
18
19    /// <https://fetch.spec.whatwg.org/#fetchlaterresult-activated-getter-steps>
20    #[no_trace]
21    deferred_record_id: DeferredFetchRecordId,
22}
23
24impl FetchLaterResult {
25    fn new_inherited(deferred_record_id: DeferredFetchRecordId) -> FetchLaterResult {
26        FetchLaterResult {
27            reflector_: Reflector::new(),
28            deferred_record_id,
29        }
30    }
31
32    pub(crate) fn new(
33        window: &Window,
34        deferred_record_id: DeferredFetchRecordId,
35        can_gc: CanGc,
36    ) -> DomRoot<FetchLaterResult> {
37        reflect_dom_object(
38            Box::new(FetchLaterResult::new_inherited(deferred_record_id)),
39            window,
40            can_gc,
41        )
42    }
43}
44
45impl FetchLaterResultMethods<crate::DomTypeHolder> for FetchLaterResult {
46    /// <https://fetch.spec.whatwg.org/#dom-fetchlaterresult-activated>
47    fn Activated(&self) -> bool {
48        // The activated getter steps are to return the result of running this’s activated getter steps.
49        self.global()
50            .deferred_fetch_record_for_id(&self.deferred_record_id)
51            .activated_getter_steps()
52    }
53}