diff options
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 5e29dd60e46..c369b8f1d74 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -45,6 +45,7 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; +use dom::htmlscriptelement::HTMLScriptElement; use dom::location::Location; use dom::mouseevent::MouseEvent; use dom::keyboardevent::KeyboardEvent; @@ -116,6 +117,8 @@ pub struct Document { possibly_focused: MutNullableJS<Element>, /// The element that currently has the document focus context. focused: MutNullableJS<Element>, + /// The script element that is currently executing. + current_script: MutNullableJS<HTMLScriptElement>, } impl DocumentDerived for EventTarget { @@ -206,6 +209,7 @@ pub trait DocumentHelpers<'a> { fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D<f32>); fn dispatch_key_event(self, key: Key, state: KeyState, modifiers: KeyModifiers, compositor: &mut Box<ScriptListener+'static>); + fn set_current_script(self, script: Option<JSRef<HTMLScriptElement>>); } impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { @@ -535,6 +539,10 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { window.r().flush_layout(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery); } + + fn set_current_script(self, script: Option<JSRef<HTMLScriptElement>>) { + self.current_script.assign(script); + } } #[derive(PartialEq)] @@ -601,6 +609,7 @@ impl Document { ready_state: Cell::new(ready_state), possibly_focused: Default::default(), focused: Default::default(), + current_script: Default::default(), } } @@ -1002,6 +1011,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { }) } + // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-currentscript + fn GetCurrentScript(self) -> Option<Temporary<HTMLScriptElement>> { + self.current_script.get() + } + // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body fn GetBody(self) -> Option<Temporary<HTMLElement>> { self.get_html_element().and_then(|root| { |