Repository: servo/servo
File: components/script/dom/window.rs (Rust)

Code before:
        self.performance.or_init(|| {
            Performance::new(
                self.as_global_scope(),
                self.navigation_start.get(),
                CanGc::note(),
            )
        })
    }

    // https://html.spec.whatwg.org/multipage/#globaleventhandlers
    global_event_handlers!();

    // https://html.spec.whatwg.org/multipage/#windoweventhandlers
    window_event_handlers!();

    /// <https://developer.mozilla.org/en-US/docs/Web/API/Window/screen>
    fn Screen(&self, can_gc: CanGc) -> DomRoot<Screen> {
        self.screen.or_init(|| Screen::new(self, can_gc))
    }

    /// <https://drafts.csswg.org/cssom-view/#dom-window-visualviewport>
    fn GetVisualViewport(&self, can_gc: CanGc) -> Option<DomRoot<VisualViewport>> {
        // > If the associated document is fully active, the visualViewport attribute must return the
        // > VisualViewport object associated with the Window object’s associated document. Otherwise,
        // > it must return null.
        if !self.has_fully_active_document() {
            return None;
        }

        // TODO(#41341): we are only initializing the visual viewport here, but it is never updated.
        Some(self.visual_viewport.or_init(|| {
            VisualViewport::new_from_layout_viewport(self, self.viewport_details().size, can_gc)
        }))
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-windowbase64-btoa>
    fn Btoa(&self, btoa: DOMString) -> Fallible<DOMString> {
        base64_btoa(btoa)
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-windowbase64-atob>
    fn Atob(&self, atob: DOMString) -> Fallible<DOMString> {
        base64_atob(atob)
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe>
    fn RequestAnimationFrame(&self, callback: Rc<FrameRequestCallback>) -> u32 {
        self.Document()
            .request_animation_frame(AnimationFrameCallback::FrameRequestCallback { callback })
    }


Review comment (suggestion):
```suggestion
        if !self.Document().is_fully_active() {
```

Code after:
        self.performance.or_init(|| {
            Performance::new(
                self.as_global_scope(),
                self.navigation_start.get(),
                CanGc::note(),
            )
        })
    }

    // https://html.spec.whatwg.org/multipage/#globaleventhandlers
    global_event_handlers!();

    // https://html.spec.whatwg.org/multipage/#windoweventhandlers
    window_event_handlers!();

    /// <https://developer.mozilla.org/en-US/docs/Web/API/Window/screen>
    fn Screen(&self, can_gc: CanGc) -> DomRoot<Screen> {
        self.screen.or_init(|| Screen::new(self, can_gc))
    }

    /// <https://drafts.csswg.org/cssom-view/#dom-window-visualviewport>
    fn GetVisualViewport(&self, can_gc: CanGc) -> Option<DomRoot<VisualViewport>> {
        // > If the associated document is fully active, the visualViewport attribute must return the
        // > VisualViewport object associated with the Window object’s associated document. Otherwise,
        // > it must return null.
        if !self.Document().is_fully_active() {
            return None;
        }

        // TODO(#41341): we are only initializing the visual viewport here, but it is never updated.
        Some(self.visual_viewport.or_init(|| {
            VisualViewport::new_from_layout_viewport(self, self.viewport_details().size, can_gc)
        }))
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-windowbase64-btoa>
    fn Btoa(&self, btoa: DOMString) -> Fallible<DOMString> {
        base64_btoa(btoa)
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-windowbase64-atob>
    fn Atob(&self, atob: DOMString) -> Fallible<DOMString> {
        base64_atob(atob)
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe>
    fn RequestAnimationFrame(&self, callback: Rc<FrameRequestCallback>) -> u32 {
        self.Document()
            .request_animation_frame(AnimationFrameCallback::FrameRequestCallback { callback })
    }