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

Added current_line variable to track current line #14661

Closed
wants to merge 6 commits into from

Removed line_number parameter from create function and added argument…

… to ParserCreated. Added comment to xml.rs
  • Loading branch information
karenher committed Dec 24, 2016
commit 3a0f9fa98a512a55f0983b9302d1d60dd7ee9368
@@ -276,8 +276,7 @@ fn create_html_element(name: QualName,
pub fn create_element(name: QualName,
prefix: Option<Prefix>,
document: &Document,
creator: ElementCreator,
line_number: u64)
creator: ElementCreator)
-> Root<Element> {
// FIXME(ajeffrey): Convert directly from Prefix to DOMString.

@@ -2427,7 +2427,7 @@ impl DocumentMethods for Document {
local_name.make_ascii_lowercase();
}
let name = QualName::new(ns!(html), LocalName::from(local_name));
Ok(Element::create(name, None, self, ElementCreator::ScriptCreated, 1))
Ok(Element::create(name, None, self, ElementCreator::ScriptCreated))
}

// https://dom.spec.whatwg.org/#dom-document-createelementns
@@ -2438,7 +2438,7 @@ impl DocumentMethods for Document {
let (namespace, prefix, local_name) = try!(validate_and_extract(namespace,
&qualified_name));
let name = QualName::new(namespace, local_name);
Ok(Element::create(name, prefix, self, ElementCreator::ScriptCreated, 1))
Ok(Element::create(name, prefix, self, ElementCreator::ScriptCreated))
}

// https://dom.spec.whatwg.org/#dom-document-createattribute
@@ -2691,7 +2691,7 @@ impl DocumentMethods for Document {
Some(elem) => Root::upcast::<Node>(elem),
None => {
let name = QualName::new(ns!(svg), local_name!("title"));
let elem = Element::create(name, None, self, ElementCreator::ScriptCreated, 1);
let elem = Element::create(name, None, self, ElementCreator::ScriptCreated);
let parent = root.upcast::<Node>();
let child = elem.upcast::<Node>();
parent.InsertBefore(child, parent.GetFirstChild().r())
@@ -2711,7 +2711,7 @@ impl DocumentMethods for Document {
let elem = Element::create(name,
None,
self,
ElementCreator::ScriptCreated, 1);
ElementCreator::ScriptCreated);
head.upcast::<Node>()
.AppendChild(elem.upcast())
.unwrap()
@@ -143,7 +143,7 @@ impl fmt::Debug for Element {

#[derive(PartialEq, HeapSizeOf)]
pub enum ElementCreator {
ParserCreated,
ParserCreated(u64),
ScriptCreated,
}

@@ -173,9 +173,9 @@ impl<'a> TryFrom<&'a str> for AdjacentPosition {
//
impl Element {
pub fn create(name: QualName, prefix: Option<Prefix>,
document: &Document, creator: ElementCreator, line_number: u64)
document: &Document, creator: ElementCreator)
-> Root<Element> {
create_element(name, prefix, document, creator, line_number)
create_element(name, prefix, document, creator)
}

pub fn new_inherited(local_name: LocalName,
@@ -1884,7 +1884,7 @@ impl ElementMethods for Element {
NodeTypeId::DocumentFragment => {
let body_elem = Element::create(QualName::new(ns!(html), local_name!("body")),
None, &context_document,
ElementCreator::ScriptCreated, 1);
ElementCreator::ScriptCreated);
Root::upcast(body_elem)
},
_ => context_node.GetParentElement().unwrap()
@@ -70,7 +70,7 @@ impl HTMLLinkElement {
HTMLLinkElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
rel_list: Default::default(),
parser_inserted: Cell::new(creator == ElementCreator::ParserCreated),
parser_inserted: Cell::new(creator == ElementCreator::ParserCreated(1)),

This comment has been minimized.

Copy link
@jdm

jdm Dec 24, 2016

Member

Let's add a is_parser_created method to the ElementCreator type (impl ParserCreated) that performs a match. As written, this will cause incorrect results in cases where the element is not on line 1 of the HTML file it's created from.

stylesheet: DOMRefCell::new(None),
cssom_stylesheet: MutNullableJS::new(None),
}
@@ -73,8 +73,8 @@ impl HTMLScriptElement {
htmlelement:
HTMLElement::new_inherited(local_name, prefix, document),
already_started: Cell::new(false),
parser_inserted: Cell::new(creator == ElementCreator::ParserCreated),
non_blocking: Cell::new(creator != ElementCreator::ParserCreated),
parser_inserted: Cell::new(creator == ElementCreator::ParserCreated(1)),
non_blocking: Cell::new(creator != ElementCreator::ParserCreated(1)),

This comment has been minimized.

Copy link
@jdm

jdm Dec 24, 2016

Member

We should add a new line_number member to HTMLScriptElement and initialize it with the line number from the creator argument here (we can use 1 in the non-ParserCreated case).

ready_to_be_parser_executed: Cell::new(false),

This comment has been minimized.

Copy link
@jdm

jdm Dec 25, 2016

Member

The checks for ParserCeated on the previous line (and elsewhere in this PR) are still incorrect.

parser_document: JS::from_ref(document),
load: DOMRefCell::new(None),
@@ -1737,7 +1737,7 @@ impl Node {
};
let element = Element::create(name,
element.prefix().map(|p| Prefix::from(&**p)),
&document, ElementCreator::ScriptCreated, 1);
&document, ElementCreator::ScriptCreated);
Root::upcast::<Node>(element)
},
};
@@ -157,7 +157,7 @@ impl<'a> TreeSink for Sink {
fn create_element(&mut self, name: QualName, attrs: Vec<Attribute>)
-> JS<Node> {
let elem = Element::create(name, None, &*self.document,
ElementCreator::ParserCreated, 1);
ElementCreator::ParserCreated(self.current_line));

for attr in attrs {
elem.set_attribute_from_parser(attr.name, DOMString::from(String::from(attr.value)), None);
@@ -100,6 +100,7 @@ struct Sink {
script: MutNullableJS<HTMLScriptElement>,
}

//TODO: Add ability to track lines to API of xml5ever

This comment has been minimized.

Copy link
@jdm

jdm Dec 24, 2016

Member

Let's move this next to the code where we fake the line number instead.

impl<'a> TreeSink for Sink {
type Handle = JS<Node>;

@@ -129,7 +130,7 @@ impl<'a> TreeSink for Sink {
local: name.local,
};
let elem = Element::create(name, prefix, &*self.document,
ElementCreator::ParserCreated, 1);
ElementCreator::ParserCreated(1));

for attr in attrs {
let name = QualName {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.