mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Compile JS strings when setting inline event handlers via element attributes.
This commit is contained in:
parent
33955f0ab2
commit
04931adf70
4 changed files with 76 additions and 14 deletions
|
@ -3,14 +3,16 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLBodyElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived;
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
|
||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::document::Document;
|
||||
use dom::element::HTMLBodyElementTypeId;
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId, EventTargetHelpers};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::window::WindowMethods;
|
||||
use js::jsapi::{JSContext, JSObject};
|
||||
use servo_util::str::DOMString;
|
||||
|
@ -115,3 +117,27 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> {
|
|||
win.SetOnunload(cx, listener)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let element: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||
Some(element as &mut VirtualMethods:)
|
||||
}
|
||||
|
||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||
match self.super_type() {
|
||||
Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if name.starts_with("on") {
|
||||
//XXXjdm This should only forward a subset of event handler names
|
||||
let mut window = window_from_node(self).root();
|
||||
let mut evtarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(&mut *window);
|
||||
let content: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
|
||||
evtarget.set_event_handler_uncompiled(content,
|
||||
name.slice_from(2).to_owned(),
|
||||
value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue