aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlscriptelement.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-02-26 01:06:51 -0700
committerbors-servo <metajack+bors@gmail.com>2015-02-26 01:06:51 -0700
commitc1645bd10ccd9a17e149d8bec56633ac06d8529f (patch)
tree4fbd57084344fe213d5ab995b7ef01d6022be4ef /components/script/dom/htmlscriptelement.rs
parenta8b55e821a10c5ed8e5942e88e88eb20d08ad43c (diff)
parent0b085df1bc14e4ab8d27f902796a3402f0fa92fb (diff)
downloadservo-c1645bd10ccd9a17e149d8bec56633ac06d8529f.tar.gz
servo-c1645bd10ccd9a17e149d8bec56633ac06d8529f.zip
auto merge of #5070 : luniv/servo/script-before-after-events, r=Ms2ger
Spec: https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block, sections 2.b.2 & 2.b.9
Diffstat (limited to 'components/script/dom/htmlscriptelement.rs')
-rw-r--r--components/script/dom/htmlscriptelement.rs73
1 files changed, 52 insertions, 21 deletions
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs
index 8a0c3483650..fc7220cb452 100644
--- a/components/script/dom/htmlscriptelement.rs
+++ b/components/script/dom/htmlscriptelement.rs
@@ -100,6 +100,12 @@ pub trait HTMLScriptElementHelpers {
// Queues error event
fn queue_error_event(self);
+ /// Dispatch beforescriptexecute event.
+ fn dispatch_before_script_execute_event(self) -> bool;
+
+ /// Dispatch afterscriptexecute event.
+ fn dispatch_after_script_execute_event(self);
+
/// Dispatch load event.
fn dispatch_load_event(self);
@@ -297,9 +303,9 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
};
// Step 2.b.2.
- // TODO: Fire a simple event named beforescriptexecute that bubbles and
- // is cancelable at the script element.
- // If the event is canceled, then abort these steps.
+ if !self.dispatch_before_script_execute_event() {
+ return;
+ }
// Step 2.b.3.
// TODO: If the script is from an external file, then increment the
@@ -330,8 +336,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
// doc, if it was incremented in the earlier step.
// Step 2.b.9.
- // TODO: Fire a simple event named afterscriptexecute that bubbles (but
- // is not cancelable) at the script element.
+ self.dispatch_after_script_execute_event();
// Step 2.b.10.
if external {
@@ -359,26 +364,28 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
chan.send(ScriptMsg::RunnableMsg(dispatcher)).unwrap();
}
+ fn dispatch_before_script_execute_event(self) -> bool {
+ self.dispatch_event("beforescriptexecute".to_owned(),
+ EventBubbles::Bubbles,
+ EventCancelable::Cancelable)
+ }
+
+ fn dispatch_after_script_execute_event(self) {
+ self.dispatch_event("afterscriptexecute".to_owned(),
+ EventBubbles::Bubbles,
+ EventCancelable::NotCancelable);
+ }
+
fn dispatch_load_event(self) {
- let window = window_from_node(self).root();
- let window = window.r();
- let event = Event::new(GlobalRef::Window(window),
- "load".to_owned(),
- EventBubbles::DoesNotBubble,
- EventCancelable::NotCancelable).root();
- let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
- event.r().fire(target);
+ self.dispatch_event("load".to_owned(),
+ EventBubbles::DoesNotBubble,
+ EventCancelable::NotCancelable);
}
fn dispatch_error_event(self) {
- let window = window_from_node(self).root();
- let window = window.r();
- let event = Event::new(GlobalRef::Window(window),
- "error".to_owned(),
- EventBubbles::DoesNotBubble,
- EventCancelable::NotCancelable).root();
- let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
- event.r().fire(target);
+ self.dispatch_event("error".to_owned(),
+ EventBubbles::DoesNotBubble,
+ EventCancelable::NotCancelable);
}
fn is_javascript(self) -> bool {
@@ -420,6 +427,30 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
}
}
+trait PrivateHTMLScriptElementHelpers {
+ fn dispatch_event(self,
+ type_: DOMString,
+ bubbles: EventBubbles,
+ cancelable: EventCancelable) -> bool;
+}
+
+impl<'a> PrivateHTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
+ fn dispatch_event(self,
+ type_: DOMString,
+ bubbles: EventBubbles,
+ cancelable: EventCancelable) -> bool {
+ let window = window_from_node(self).root();
+ let window = window.r();
+ let event = Event::new(GlobalRef::Window(window),
+ type_,
+ bubbles,
+ cancelable).root();
+ let event = event.r();
+ let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
+ event.fire(target)
+ }
+}
+
impl<'a> VirtualMethods for JSRef<'a, HTMLScriptElement> {
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);