mirror of
https://github.com/servo/servo.git
synced 2025-06-20 07:08:59 +01:00
auto merge of #1622 : brunoabinader/servo/document-createprocessinginstruction, r=Ms2ger
PR #1620 adds ProcessingInstruction DOM interface. Spec: http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction This is a sub-task for #1428.
This commit is contained in:
commit
ae6af1c0d1
4 changed files with 39 additions and 2 deletions
|
@ -154,6 +154,7 @@ DOMInterfaces = {
|
||||||
'createComment',
|
'createComment',
|
||||||
'createDocumentFragment',
|
'createDocumentFragment',
|
||||||
'createElement',
|
'createElement',
|
||||||
|
'createProcessingInstruction',
|
||||||
'createTextNode',
|
'createTextNode',
|
||||||
'title',
|
'title',
|
||||||
'body',
|
'body',
|
||||||
|
|
|
@ -18,6 +18,7 @@ use dom::htmldocument::HTMLDocument;
|
||||||
use dom::mouseevent::MouseEvent;
|
use dom::mouseevent::MouseEvent;
|
||||||
use dom::node::{AbstractNode, Node, ElementNodeTypeId, DocumentNodeTypeId};
|
use dom::node::{AbstractNode, Node, ElementNodeTypeId, DocumentNodeTypeId};
|
||||||
use dom::text::Text;
|
use dom::text::Text;
|
||||||
|
use dom::processinginstruction::ProcessingInstruction;
|
||||||
use dom::uievent::UIEvent;
|
use dom::uievent::UIEvent;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom::htmltitleelement::HTMLTitleElement;
|
use dom::htmltitleelement::HTMLTitleElement;
|
||||||
|
@ -276,6 +277,23 @@ impl Document {
|
||||||
Comment::new(data, abstract_self)
|
Comment::new(data, abstract_self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
|
||||||
|
pub fn CreateProcessingInstruction(&self, abstract_self: AbstractDocument, target: DOMString,
|
||||||
|
data: DOMString) -> Fallible<AbstractNode> {
|
||||||
|
// Step 1.
|
||||||
|
if xml_name_type(target) == InvalidXMLName {
|
||||||
|
return Err(InvalidCharacter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
|
if data.contains("?>") {
|
||||||
|
return Err(InvalidCharacter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3.
|
||||||
|
Ok(ProcessingInstruction::new(target, data, abstract_self))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn CreateEvent(&self, interface: DOMString) -> Fallible<AbstractEvent> {
|
pub fn CreateEvent(&self, interface: DOMString) -> Fallible<AbstractEvent> {
|
||||||
match interface.as_slice() {
|
match interface.as_slice() {
|
||||||
"UIEvents" => Ok(UIEvent::new(self.window)),
|
"UIEvents" => Ok(UIEvent::new(self.window)),
|
||||||
|
|
|
@ -50,8 +50,8 @@ interface Document : Node {
|
||||||
Text createTextNode(DOMString data);
|
Text createTextNode(DOMString data);
|
||||||
[Creator]
|
[Creator]
|
||||||
Comment createComment(DOMString data);
|
Comment createComment(DOMString data);
|
||||||
/*[Creator, Throws]
|
[Creator, Throws]
|
||||||
ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);*/
|
ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
|
||||||
|
|
||||||
/*[Throws]
|
/*[Throws]
|
||||||
Node importNode(Node node, optional boolean deep = true);
|
Node importNode(Node node, optional boolean deep = true);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="harness.js"></script>
|
||||||
|
<script>
|
||||||
|
// test1: createProcessingInstruction
|
||||||
|
{
|
||||||
|
var pi = document.createProcessingInstruction("xml-stylesheet", "href=\"mycss.css\" type=\"text/css\"");
|
||||||
|
isnot(pi, null, "test1-0: createProcessingInstruction");
|
||||||
|
is_a(pi, ProcessingInstruction, "test1-1: createProcessingInstruction");
|
||||||
|
is(pi.target, "xml-stylesheet", "test1-2: createProcessingInstruction");
|
||||||
|
is(pi.data, "href=\"mycss.css\" type=\"text/css\"", "test1-3: createProcessingInstruction");
|
||||||
|
}
|
||||||
|
|
||||||
|
finish();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue