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

Code before:
    }

    fn WebdriverElement(&self, id: DOMString) -> Option<DomRoot<Element>> {
        find_node_by_unique_id_in_document(&self.Document(), id.into()).and_then(Root::downcast)
    }

    fn WebdriverFrame(&self, browsing_context_id: DOMString) -> Option<DomRoot<WindowProxy>> {
        self.Document()
            .iframes()
            .iter()
            .find(|iframe| {
                iframe
                    .browsing_context_id()
                    .as_ref()
                    .map(BrowsingContextId::to_string) ==
                    Some(browsing_context_id.to_string())
            })
            .and_then(|iframe| iframe.GetContentWindow())
    }

    fn WebdriverWindow(&self, webview_id: DOMString) -> DomRoot<WindowProxy> {
        let window_proxy = &self
            .window_proxy
            .get()
            .expect("Should always have a WindowProxy when calling WebdriverWindow");
        assert!(window_proxy.is_top_level(), "Window must be top level browsing context.");
        assert!(self.webview_id().to_string() == webview_id);
        DomRoot::from_ref(window_proxy)
    }

    fn WebdriverShadowRoot(&self, id: DOMString) -> Option<DomRoot<ShadowRoot>> {
        find_node_by_unique_id_in_document(&self.Document(), id.into()).and_then(Root::downcast)
    }

    /// <https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle>
    fn GetComputedStyle(
        &self,
        element: &Element,
        pseudo: Option<DOMString>,
    ) -> DomRoot<CSSStyleDeclaration> {
        // Step 2: Let obj be elt.
        // We don't store CSSStyleOwner directly because it stores a `Dom` which must be
        // rooted. This avoids the rooting the value temporarily.
        let mut is_null = false;

        // Step 3: If pseudoElt is provided, is not the empty string, and starts with a colon, then:
        // Step 3.1: Parse pseudoElt as a <pseudo-element-selector>, and let type be the result.
        let pseudo = pseudo.map(|mut s| {
            s.make_ascii_lowercase();
            s
        });

Review comment (suggestion):
```suggestion
        assert!(self.is_top_level(), "Window must be top level browsing context.");
```

Code after:

    fn WebdriverElement(&self, id: DOMString) -> Option<DomRoot<Element>> {
        find_node_by_unique_id_in_document(&self.Document(), id.into()).and_then(Root::downcast)
    }

    fn WebdriverFrame(&self, browsing_context_id: DOMString) -> Option<DomRoot<WindowProxy>> {
        self.Document()
            .iframes()
            .iter()
            .find(|iframe| {
                iframe
                    .browsing_context_id()
                    .as_ref()
                    .map(BrowsingContextId::to_string) ==
                    Some(browsing_context_id.to_string())
            })
            .and_then(|iframe| iframe.GetContentWindow())
    }

    fn WebdriverWindow(&self, webview_id: DOMString) -> DomRoot<WindowProxy> {
        let window_proxy = &self
            .window_proxy
            .get()
            .expect("Should always have a WindowProxy when calling WebdriverWindow");
        assert!(
            self.is_top_level(),
            "Window must be top level browsing context."
        );
        assert!(self.webview_id().to_string() == webview_id);
        DomRoot::from_ref(window_proxy)
    }

    fn WebdriverShadowRoot(&self, id: DOMString) -> Option<DomRoot<ShadowRoot>> {
        find_node_by_unique_id_in_document(&self.Document(), id.into()).and_then(Root::downcast)
    }

    /// <https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle>
    fn GetComputedStyle(
        &self,
        element: &Element,
        pseudo: Option<DOMString>,
    ) -> DomRoot<CSSStyleDeclaration> {
        // Step 2: Let obj be elt.
        // We don't store CSSStyleOwner directly because it stores a `Dom` which must be
        // rooted. This avoids the rooting the value temporarily.
        let mut is_null = false;

        // Step 3: If pseudoElt is provided, is not the empty string, and starts with a colon, then:
        // Step 3.1: Parse pseudoElt as a <pseudo-element-selector>, and let type be the result.
        let pseudo = pseudo.map(|mut s| {
            s.make_ascii_lowercase();