Skip to main content

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