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
@@ -143,10 +143,25 @@ impl fmt::Debug for Element {

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

impl ElementCreator {
pub fn is_parser_created(&self) -> bool {
match *self {
ElementCreator::ParserCreated(l) => true,
ElementCreator::ScriptCreated => false,
}
}
pub fn return_line_number(&self) -> u64 {
match *self {
ElementCreator::ParserCreated(l) => l,
ElementCreator::ScriptCreated => 1,
}
}
}

pub enum AdjacentPosition {
BeforeBegin,
AfterEnd,
@@ -338,13 +338,13 @@ impl GlobalScope {
/// Evaluate JS code on this global scope.
pub fn evaluate_js_on_global_with_result(
&self, code: &str, rval: MutableHandleValue) {
self.evaluate_script_on_global_with_result(code, "", rval)
self.evaluate_script_on_global_with_result(code, "", rval, 1)
}

/// Evaluate a JS script on this global scope.
#[allow(unsafe_code)]
pub fn evaluate_script_on_global_with_result(
&self, code: &str, filename: &str, rval: MutableHandleValue) {
&self, code: &str, filename: &str, rval: MutableHandleValue, line_number: u64) {
let metadata = time::TimerMetadata {
url: if filename.is_empty() {
self.get_url().as_str().into()
@@ -365,7 +365,7 @@ impl GlobalScope {
let filename = CString::new(filename).unwrap();

let _ac = JSAutoCompartment::new(cx, globalhandle.get());
let options = CompileOptionsWrapper::new(cx, filename.as_ptr(), 1);
let options = CompileOptionsWrapper::new(cx, filename.as_ptr(), line_number as u32);
unsafe {
if !Evaluate2(cx, options.ptr, code.as_ptr(),
code.len() as libc::size_t,
@@ -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.is_parser_created()),
stylesheet: DOMRefCell::new(None),
cssom_stylesheet: MutNullableJS::new(None),
}
@@ -64,6 +64,9 @@ pub struct HTMLScriptElement {

/// The source this script was loaded from
load: DOMRefCell<Option<Result<ScriptOrigin, NetworkError>>>,

/// Track line line_number
line_number: u64,
}

impl HTMLScriptElement {
@@ -73,11 +76,12 @@ 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.is_parser_created()),
non_blocking: Cell::new(!creator.is_parser_created()),
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),
line_number: creator.return_line_number(),
}
}

@@ -495,7 +499,7 @@ impl HTMLScriptElement {
let window = window_from_node(self);
rooted!(in(window.get_cx()) let mut rval = UndefinedValue());
window.upcast::<GlobalScope>().evaluate_script_on_global_with_result(
&script.text, script.url.as_str(), rval.handle_mut());
&script.text, script.url.as_str(), rval.handle_mut(), self.line_number);

// Step 6.
document.set_current_script(old_script.r());
@@ -51,6 +51,7 @@ impl Tokenizer {
let sink = Sink {
base_url: url,
document: JS::from_ref(document),
current_line: 1,
};

let options = TreeBuilderOpts {
@@ -121,6 +122,7 @@ unsafe impl JSTraceable for HtmlTokenizer<TreeBuilder<JS<Node>, Sink>> {
struct Sink {
base_url: ServoUrl,
document: JS<Document>,
current_line: u64,
}

impl<'a> TreeSink for Sink {
@@ -155,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);
ElementCreator::ParserCreated(self.current_line));

for attr in attrs {
elem.set_attribute_from_parser(attr.name, DOMString::from(String::from(attr.value)), None);
@@ -229,6 +231,10 @@ impl<'a> TreeSink for Sink {
}

}

fn set_current_line(&mut self, line_number: u64) {
self.current_line = line_number;
}
}

fn insert(parent: &Node, reference_child: Option<&Node>, child: NodeOrText<JS<Node>>) {
@@ -128,8 +128,9 @@ impl<'a> TreeSink for Sink {
ns: name.namespace_url,
local: name.local,
};
//TODO: Add ability to track lines to API of xml5ever
let elem = Element::create(name, prefix, &*self.document,
ElementCreator::ParserCreated);
ElementCreator::ParserCreated(1));

for attr in attrs {
let name = QualName {
"url": "/_mozilla/mozilla/trace_null.html"
}
],
"mozilla/track_line.html": [
{
"path": "mozilla/track_line.html",
"url": "/_mozilla/mozilla/track_line.html"
}
],
"mozilla/union.html": [
{
"path": "mozilla/union.html",
@@ -0,0 +1,17 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception:true});
var t = async_test("error event has proper line number");
window.addEventListener('error', t.step_func(function(e) {
assert_true(e instanceof ErrorEvent);
assert_equals(e.lineno, 16);
t.done();
}), true);
</script>
<script>
this_is_a_js_error
</script>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.