Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Range::createContextualFragment #11496

Merged
merged 2 commits into from Jun 3, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Implement Range::createContextualFragment

  • Loading branch information
GuillaumeGomez committed Jun 2, 2016
commit 5ab7f54762bade4d5c67dca0103f8f9b115baa30
@@ -130,7 +130,6 @@ impl Element {
create_element(name, prefix, document, creator)
}


pub fn new_inherited(local_name: Atom,
namespace: Namespace, prefix: Option<DOMString>,
document: &Document) -> Element {
@@ -22,6 +22,9 @@ use dom::bindings::weakref::{WeakRef, WeakRefVec};
use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::documentfragment::DocumentFragment;
use dom::element::Element;
use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlscriptelement::HTMLScriptElement;
use dom::node::{Node, UnbindContext};
use dom::text::Text;
use heapsize::HeapSizeOf;
@@ -893,6 +896,44 @@ impl RangeMethods for Range {
// Step 6.
s
}

// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#extensions-to-the-range-interface
fn CreateContextualFragment(&self, fragment: DOMString) -> Fallible<Root<DocumentFragment>> {
// Step 1.
let node = self.StartContainer();
let element = match node.type_id() {
NodeTypeId::Document(_) | NodeTypeId::DocumentFragment => None,
NodeTypeId::Element(_) => Some(node),
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) |
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => node.GetParentNode(),
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) |
NodeTypeId::DocumentType => unreachable!(),
};

// Step 2.
let should_create_body = element.as_ref().map_or(true, |elem| {
let elem = elem.downcast::<Element>().unwrap();
elem.local_name() == &atom!("html") && elem.html_element_in_html_document()
});
let element: Root<Node> = if should_create_body {
Root::upcast(HTMLBodyElement::new(atom!("body"), None, &self.StartContainer().owner_doc()))
} else {
Root::upcast(element.unwrap())
};

// Step 3.
let fragment_node = try!(element.parse_fragment(fragment));

// Step 4.
for node in fragment_node.upcast::<Node>().traverse_preorder() {
if let Some(script) = node.downcast::<HTMLScriptElement>() {
script.set_already_started(false);
}
}

// Step 5.
Ok(fragment_node)
}
}

#[derive(JSTraceable)]
@@ -76,9 +76,9 @@ interface Range {

// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#extensions-to-the-range-interface
partial interface Range {
// [NewObject, Throws]
// DocumentFragment createContextualFragment(DOMString fragment);
};//
[NewObject, Throws]
DocumentFragment createContextualFragment(DOMString fragment);
};

// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-range-interface
partial interface Range {
@@ -1,35 +1,11 @@
[createContextualFragment.html]
type: testharness
[Must not throw INVALID_STATE_ERR for a detached node.]
expected: FAIL

[Simple test with paragraphs]
expected: FAIL

[Don't auto-create <body> when applied to <html>]
expected: FAIL
[<script>s should be run when appended to the document (but not before)]
expected: FAIL

[<html> and <body> must work the same, 1]
expected: FAIL
[<html> and <body> must work the same, 2]
expected: FAIL
[Implicit <body> creation]
expected: FAIL
[Namespace generally shouldn't matter]
expected: FAIL
[<html> in a different namespace shouldn't be special]
expected: FAIL

[null should be stringified]
expected: FAIL
[undefined should be stringified]
expected: FAIL
@@ -1,6 +1,6 @@
[load-events-networkState.html]
type: testharness
expected: TIMEOUT

[NETWORK_NO_SOURCE]
expected: TIMEOUT

@@ -2,3 +2,4 @@
type: testharness
[error]
expected: FAIL

This file was deleted.

@@ -1,4 +1,3 @@
[quickCheckAPI-G_I.html]
type: testharness
disabled: https://github.com/servo/servo/issues/10656

@@ -1,14 +1,19 @@
[copy-tex-image-2d-formats.html]
[WebGL test #3: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors]
expected: FAIL

[WebGL test #6: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors]
expected: FAIL

[WebGL test #9: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors]
expected: FAIL

[WebGL test #12: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors]
expected: FAIL

[WebGL test #15: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors]
expected: FAIL

[WebGL test #16: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -3,4 +3,3 @@
expected:
if os == "linux": CRASH
if os == "mac": TIMEOUT

@@ -1,6 +1,5 @@
[texture-npot.html]
type: testharness

[WebGL test #4: at (0, 0) expected: 0,0,0,255 was 192,0,128,64]
expected: FAIL

@@ -117,3 +116,4 @@

[WebGL test #83: getError expected: NO_ERROR. Was INVALID_ENUM : gl.generateMipmap with POT texture should return succeed]
expected: FAIL

@@ -3,4 +3,3 @@
expected:
if os == "linux": CRASH
if os == "mac": TIMEOUT

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.