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

Make script load event asynchronous for internal scripts #4540

Merged
merged 3 commits into from Jan 16, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Add the enum to describe the script origin.

  • Loading branch information
tetsuharuohzeki committed Jan 10, 2015
commit f627b35ef6e40e5a87a2e9173309af75f6322310
@@ -112,6 +112,11 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[
"text/x-javascript",
];

enum ScriptOrigin {
Internal,
External,
}

impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
fn prepare(self) {
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script
@@ -175,7 +180,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
let page = window.page();
let base_url = page.get_url();

let (source, url) = match element.get_attribute(ns!(""), &atom!("src")).root() {
let (origin, source, url) = match element.get_attribute(ns!(""), &atom!("src")).root() {
Some(src) => {
if src.r().Value().is_empty() {
// TODO: queue a task to fire a simple event named `error` at the element
@@ -191,7 +196,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
Ok((metadata, bytes)) => {
// TODO: use the charset from step 13.
let source = UTF_8.decode(bytes.as_slice(), DecoderTrap::Replace).unwrap();
(source, metadata.final_url)
(ScriptOrigin::External, source, metadata.final_url)
}
Err(_) => {
error!("error loading script {}", src.r().Value());
@@ -206,7 +211,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
}
}
}
None => (text, base_url)
None => (ScriptOrigin::Internal, text, base_url)
};

window.evaluate_script_on_global_with_result(source.as_slice(), url.serialize().as_slice());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.