mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Make script load event asynchronous for internal scripts
This commit is contained in:
parent
f627b35ef6
commit
b984815b98
1 changed files with 28 additions and 0 deletions
|
@ -15,6 +15,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCas
|
|||
use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JSRef, Temporary, OptionalRootable};
|
||||
use dom::bindings::refcounted::Trusted;
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, AttributeHandlers, ElementCreator};
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId, EventTargetHelpers};
|
||||
|
@ -24,6 +25,7 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
|||
use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node, CloneChildrenFlag};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::window::ScriptHelpers;
|
||||
use script_task::{ScriptMsg, Runnable};
|
||||
|
||||
use encoding::all::UTF_8;
|
||||
use encoding::types::{Encoding, DecoderTrap};
|
||||
|
@ -89,6 +91,9 @@ pub trait HTMLScriptElementHelpers {
|
|||
|
||||
/// Set the "already started" flag (<https://whatwg.org/html/#already-started>)
|
||||
fn mark_already_started(self);
|
||||
|
||||
/// Dispatch load event.
|
||||
fn dispatch_load_event(self);
|
||||
}
|
||||
|
||||
/// Supported script types as defined by
|
||||
|
@ -216,6 +221,23 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
|||
|
||||
window.evaluate_script_on_global_with_result(source.as_slice(), url.serialize().as_slice());
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block
|
||||
// step 2, substep 10
|
||||
match origin {
|
||||
ScriptOrigin::External => {
|
||||
self.dispatch_load_event();
|
||||
}
|
||||
ScriptOrigin::Internal => {
|
||||
let chan = window.script_chan();
|
||||
let handler = Trusted::new(window.get_cx(), self, chan.clone());
|
||||
chan.send(ScriptMsg::RunnableMsg(box handler));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn dispatch_load_event(self) {
|
||||
let window = window_from_node(self).root();
|
||||
let window = window.r();
|
||||
let event = Event::new(GlobalRef::Window(window),
|
||||
"load".into_string(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
|
@ -336,3 +358,9 @@ impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Runnable for Trusted<HTMLScriptElement> {
|
||||
fn handler(&self) {
|
||||
let target = self.to_temporary().root();
|
||||
target.r().dispatch_load_event();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue