diff options
11 files changed, 61 insertions, 22 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d9c2f6907e7..be1e0eca42e 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -145,10 +145,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(_) => 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, diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index fca829c9904..4203d0e724c 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -339,13 +339,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: u32) { let metadata = time::TimerMetadata { url: if filename.is_empty() { self.get_url().as_str().into() @@ -367,7 +367,7 @@ impl GlobalScope { let _ac = JSAutoCompartment::new(cx, globalhandle.get()); let _aes = AutoEntryScript::new(self); - let options = CompileOptionsWrapper::new(cx, filename.as_ptr(), 1); + let options = CompileOptionsWrapper::new(cx, filename.as_ptr(), line_number); unsafe { if !Evaluate2(cx, options.ptr, code.as_ptr(), code.len() as libc::size_t, diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 3466fa10dab..8f5d530769a 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -59,7 +59,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), pending_loads: Cell::new(0), diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 8273aab31f0..52935e32dcf 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -60,6 +60,9 @@ pub struct HTMLScriptElement { /// Document of the parser that created this element parser_document: JS<Document>, + + /// Track line line_number + line_number: u64, } impl HTMLScriptElement { @@ -69,10 +72,11 @@ 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), parser_document: JS::from_ref(document), + line_number: creator.return_line_number(), } } @@ -508,7 +512,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 as u32); // Step 6. document.set_current_script(old_script.r()); diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index 97fd6591de8..35da9bb6368 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -50,8 +50,8 @@ impl HTMLStyleElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), stylesheet: DOMRefCell::new(None), cssom_stylesheet: MutNullableJS::new(None), - parser_inserted: Cell::new(creator == ElementCreator::ParserCreated), - in_stack_of_open_elements: Cell::new(creator == ElementCreator::ParserCreated), + parser_inserted: Cell::new(creator.is_parser_created()), + in_stack_of_open_elements: Cell::new(creator.is_parser_created()), pending_loads: Cell::new(0), any_failed_load: Cell::new(false), } diff --git a/components/script/dom/servoparser/html.rs b/components/script/dom/servoparser/html.rs index d4b53175b49..1e53cea8341 100644 --- a/components/script/dom/servoparser/html.rs +++ b/components/script/dom/servoparser/html.rs @@ -52,6 +52,7 @@ impl Tokenizer { let sink = Sink { base_url: url, document: JS::from_ref(document), + current_line: 1, }; let options = TreeBuilderOpts { @@ -122,6 +123,7 @@ unsafe impl JSTraceable for HtmlTokenizer<TreeBuilder<JS<Node>, Sink>> { struct Sink { base_url: ServoUrl, document: JS<Document>, + current_line: u64, } impl TreeSink for Sink { @@ -156,7 +158,7 @@ impl 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); @@ -234,6 +236,10 @@ impl TreeSink for Sink { } } + fn set_current_line(&mut self, line_number: u64) { + self.current_line = line_number; + } + fn pop(&mut self, node: JS<Node>) { let node = Root::from_ref(&*node); vtable_for(&node).pop(); diff --git a/components/script/dom/servoparser/xml.rs b/components/script/dom/servoparser/xml.rs index 4a62be75cff..96de50f293d 100644 --- a/components/script/dom/servoparser/xml.rs +++ b/components/script/dom/servoparser/xml.rs @@ -134,8 +134,9 @@ impl 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 { diff --git a/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/window-onerror-parse-error.html.ini b/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/window-onerror-parse-error.html.ini deleted file mode 100644 index 7a06f9dc035..00000000000 --- a/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/window-onerror-parse-error.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[window-onerror-parse-error.html] - type: testharness - [correct line number passed to window.onerror] - expected: FAIL - diff --git a/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/window-onerror-runtime-error.html.ini b/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/window-onerror-runtime-error.html.ini deleted file mode 100644 index eae9e05c0bf..00000000000 --- a/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/window-onerror-runtime-error.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[window-onerror-runtime-error.html] - type: testharness - [correct line number passed to window.onerror] - expected: FAIL - diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 5b3faa75be7..d49d2d362d1 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -15200,6 +15200,12 @@ "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", diff --git a/tests/wpt/mozilla/tests/mozilla/track_line.html b/tests/wpt/mozilla/tests/mozilla/track_line.html new file mode 100644 index 00000000000..1e6b12e5cad --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/track_line.html @@ -0,0 +1,17 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Test that errors from inline scripts report meaningful line numbers</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> |