diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/document.rs | 14 | ||||
-rw-r--r-- | components/script/dom/htmlscriptelement.rs | 19 | ||||
-rw-r--r-- | components/script/dom/webidls/Document.webidl | 1 |
3 files changed, 24 insertions, 10 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| { diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index fc7220cb452..853d6709fcb 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -7,6 +7,7 @@ use std::ascii::AsciiExt; use dom::attr::Attr; use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; +use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; @@ -14,15 +15,15 @@ use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived, HTMLScriptE use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::EventTargetCast; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{JSRef, Temporary, OptionalRootable}; +use dom::bindings::js::{JSRef, Temporary, OptionalRootable, RootedReference}; use dom::bindings::refcounted::Trusted; -use dom::document::Document; +use dom::document::{Document, DocumentHelpers}; use dom::element::{Element, AttributeHandlers, ElementCreator}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; use dom::element::ElementTypeId; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node, CloneChildrenFlag}; +use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node, CloneChildrenFlag}; use dom::virtualmethods::VirtualMethods; use dom::window::ScriptHelpers; use script_task::{ScriptMsg, Runnable}; @@ -313,13 +314,12 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { // document. Let neutralised doc be that Document. // Step 2.b.4. - // TODO: Let old script element be the value to which the script - // element's node document's currentScript object was most recently - // initialised. + let document = document_from_node(self).root(); + let document = document.r(); + let old_script = document.GetCurrentScript().root(); // Step 2.b.5. - // TODO: Initialise the script element's node document's currentScript - // object to the script element. + document.set_current_script(Some(self)); // Step 2.b.6. // TODO: Create a script... @@ -328,8 +328,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { &*url.serialize()); // Step 2.b.7. - // TODO: Initialise the script element's node document's currentScript - // object to old script element. + document.set_current_script(old_script.r()); // Step 2.b.8. // TODO: Decrement the ignore-destructive-writes counter of neutralised diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index 26d2fa03163..a591057fa1d 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -83,6 +83,7 @@ partial interface Document { readonly attribute HTMLCollection anchors; readonly attribute HTMLCollection applets; NodeList getElementsByName(DOMString elementName); + readonly attribute HTMLScriptElement? currentScript; // special event handler IDL attributes that only apply to Document objects [LenientThis] attribute EventHandler onreadystatechange; |