Switch to synchronous script loading

This removes the old code for asyncronously loading scripts during HTML
parsing and then executing them afterward.

Fixes #3356.
This commit is contained in:
Matt Brubeck 2014-10-17 09:48:31 -07:00
parent 65a0d1fe9a
commit fe123ad07c
39 changed files with 284 additions and 1006 deletions

View file

@ -16,7 +16,6 @@ use dom::bindings::conversions::{FromJSValConvertible, Empty};
use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable};
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::Reflectable;
use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap};
use dom::document::{Document, HTMLDocument, DocumentHelpers, FromParser};
use dom::element::{Element, HTMLButtonElementTypeId, HTMLInputElementTypeId};
@ -29,7 +28,7 @@ use dom::node::{ElementNodeTypeId, Node, NodeHelpers};
use dom::window::{Window, WindowHelpers};
use dom::worker::{Worker, TrustedWorkerAddress};
use dom::xmlhttprequest::{TrustedXHRAddress, XMLHttpRequest, XHRProgress};
use parse::html::{InputString, InputUrl, HtmlParserResult, HtmlDiscoveredScript, parse_html};
use parse::html::{InputString, InputUrl, parse_html};
use layout_interface::{ScriptLayoutChan, LayoutChan, ReflowForDisplay};
use layout_interface;
use page::{Page, IterablePage, Frame};
@ -62,7 +61,6 @@ use js::jsapi::{JSContext, JSRuntime, JSTracer};
use js::jsapi::{JS_SetGCParameter, JSGC_MAX_BYTES};
use js::jsapi::{JS_SetGCCallback, JSGCStatus, JSGC_BEGIN, JSGC_END};
use js::rust::{Cx, RtUtils};
use js::rust::with_compartment;
use js;
use url::Url;
@ -797,13 +795,6 @@ impl ScriptTask {
InputString(strval.unwrap_or("".to_string()))
};
// Parse HTML.
//
// Note: We can parse the next document in parallel with any previous documents.
let HtmlParserResult { discovery_port }
= parse_html(&*page, *document, parser_input, self.resource_task.clone(),
Some(load_data));
{
// Create the root frame.
let mut frame = page.mut_frame();
@ -813,18 +804,9 @@ impl ScriptTask {
});
}
document.set_ready_state(DocumentReadyStateValues::Interactive);
parse_html(&*page, *document, parser_input, self.resource_task.clone(), Some(load_data));
let mut js_scripts = None;
loop {
match discovery_port.recv_opt() {
Ok(HtmlDiscoveredScript(scripts)) => {
assert!(js_scripts.is_none());
js_scripts = Some(scripts);
}
Err(()) => break
}
}
document.set_ready_state(DocumentReadyStateValues::Interactive);
// Kick off the initial reflow of the page.
debug!("kicking off initial reflow of {}", url);
@ -841,31 +823,6 @@ impl ScriptTask {
*page_url = Some((url.clone(), false));
}
// Receive the JavaScript scripts.
assert!(js_scripts.is_some());
let js_scripts = js_scripts.take().unwrap();
debug!("js_scripts: {:?}", js_scripts);
with_compartment((**cx).ptr, window.reflector().get_jsobject(), || {
// Evaluate every script in the document.
for file in js_scripts.iter() {
let global_obj = window.reflector().get_jsobject();
let filename = match file.url {
None => String::new(),
Some(ref url) => url.serialize(),
};
//FIXME: this should have some kind of error handling, or explicitly
// drop an exception on the floor.
match cx.evaluate_script(global_obj, file.data.clone(), filename, 1) {
Ok(_) => (),
Err(_) => println!("evaluate_script failed")
}
window.flush_layout(ReflowForDisplay);
}
});
// https://html.spec.whatwg.org/multipage/#the-end step 4
let event = Event::new(&global::Window(*window), "DOMContentLoaded".to_string(),
DoesNotBubble, NotCancelable).root();