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

Code before:
        if !matches_name_production(&target.str()) {
            return Err(Error::InvalidCharacter(None));
        }

        // Step 2.
        if data.contains("?>") {
            return Err(Error::InvalidCharacter(None));
        }

        // Step 3.
        Ok(ProcessingInstruction::new(target, data, self, can_gc))
    }

    /// <https://dom.spec.whatwg.org/#dom-document-importnode>
    fn ImportNode(
        &self,
        node: &Node,
        options: BooleanOrImportNodeOptions,
        can_gc: CanGc,
    ) -> Fallible<DomRoot<Node>> {
        // Step 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException.
        if node.is::<Document>() || node.is::<ShadowRoot>() {
            return Err(Error::NotSupported(None));
        }
        // Step 2. Let subtree be false.
        let (sub_tree, registry) = match options {
            // Step 3. Let registry be null.
            // Step 4. If options is a boolean, then set subtree to options.
            BooleanOrImportNodeOptions::Boolean(boolean) => (boolean.into(), None),
            // Step 5. Otherwise:
            BooleanOrImportNodeOptions::ImportNodeOptions(options) => {
                // Step 5.1. Set subtree to the negation of options["selfOnly"].
                let sub_tree = (!options.selfOnly).into();
                // Step 5.2. If options["customElementRegistry"] exists, then set registry to it.
                let registry = options.customElementRegistry;
                // Step 5.3. If registry’s is scoped is false and registry
                // is not this’s custom element registry, then throw a "NotSupportedError" DOMException.
                // TODO
                (sub_tree, registry)
            },
        };
        // Step 6. If registry is null, then set registry to the
        // result of looking up a custom element registry given this.
        let registry = registry
            .or_else(|| CustomElementRegistry::lookup_a_custom_element_registry(self.upcast()));

        // Step 7. Return the result of cloning a node given node with
        // document set to this, subtree set to subtree, and fallbackRegistry set to registry.
        Ok(Node::clone(node, Some(self), sub_tree, registry, can_gc))
    }


Review comment (suggestion):
Nit: "subtree" is usually a single word. Not sure why:


```suggestion
        let (subtree, registry) = match options {
```

Code after:
        if !matches_name_production(&target.str()) {
            return Err(Error::InvalidCharacter(None));
        }

        // Step 2.
        if data.contains("?>") {
            return Err(Error::InvalidCharacter(None));
        }

        // Step 3.
        Ok(ProcessingInstruction::new(target, data, self, can_gc))
    }

    /// <https://dom.spec.whatwg.org/#dom-document-importnode>
    fn ImportNode(
        &self,
        node: &Node,
        options: BooleanOrImportNodeOptions,
        can_gc: CanGc,
    ) -> Fallible<DomRoot<Node>> {
        // Step 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException.
        if node.is::<Document>() || node.is::<ShadowRoot>() {
            return Err(Error::NotSupported(None));
        }
        // Step 2. Let subtree be false.
        let (subtree, registry) = match options {
            // Step 3. Let registry be null.
            // Step 4. If options is a boolean, then set subtree to options.
            BooleanOrImportNodeOptions::Boolean(boolean) => (boolean.into(), None),
            // Step 5. Otherwise:
            BooleanOrImportNodeOptions::ImportNodeOptions(options) => {
                // Step 5.1. Set subtree to the negation of options["selfOnly"].
                let subtree = (!options.selfOnly).into();
                // Step 5.2. If options["customElementRegistry"] exists, then set registry to it.
                let registry = options.customElementRegistry;
                // Step 5.3. If registry’s is scoped is false and registry
                // is not this’s custom element registry, then throw a "NotSupportedError" DOMException.
                // TODO
                (subtree, registry)
            },
        };
        // Step 6. If registry is null, then set registry to the
        // result of looking up a custom element registry given this.
        let registry = registry
            .or_else(|| CustomElementRegistry::lookup_a_custom_element_registry(self.upcast()));

        // Step 7. Return the result of cloning a node given node with
        // document set to this, subtree set to subtree, and fallbackRegistry set to registry.
        Ok(Node::clone(node, Some(self), subtree, registry, can_gc))
    }