mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move EventTargetTypeId/NodeTypeId to DOMClass
This commit is contained in:
parent
8d7ba12f28
commit
941f7dc04b
24 changed files with 149 additions and 74 deletions
|
@ -1722,6 +1722,25 @@ class CGNamespace(CGWrapper):
|
|||
return CGNamespace(namespaces[0], inner, public=public)
|
||||
|
||||
|
||||
def EventTargetEnum(desc):
|
||||
protochain = desc.prototypeChain
|
||||
if protochain[0] != "EventTarget":
|
||||
return "None"
|
||||
|
||||
inner = ""
|
||||
name = desc.interface.identifier.name
|
||||
if desc.interface.getUserData("hasConcreteDescendant", False):
|
||||
inner = "(::dom::%s::%sTypeId::%s)" % (name.lower(), name, name)
|
||||
prev_proto = ""
|
||||
for proto in reversed(protochain):
|
||||
if prev_proto != "":
|
||||
inner = "(::dom::%s::%sTypeId::%s%s)" % (proto.lower(), proto, prev_proto, inner)
|
||||
prev_proto = proto
|
||||
if inner == "":
|
||||
return "None"
|
||||
return "Some%s" % inner
|
||||
|
||||
|
||||
def DOMClass(descriptor):
|
||||
protoList = ['PrototypeList::ID::' + proto for proto in descriptor.prototypeChain]
|
||||
# Pad out the list to the right length with ID::Count so we
|
||||
|
@ -1734,7 +1753,8 @@ def DOMClass(descriptor):
|
|||
DOMClass {
|
||||
interface_chain: [ %s ],
|
||||
native_hooks: &sNativePropertyHooks,
|
||||
}""" % prototypeChainString
|
||||
type_id: %s,
|
||||
}""" % (prototypeChainString, EventTargetEnum(descriptor))
|
||||
|
||||
|
||||
class CGDOMJSClass(CGThing):
|
||||
|
|
|
@ -223,8 +223,9 @@ class Descriptor(DescriptorProvider):
|
|||
if m.isDeleter():
|
||||
addIndexedOrNamedOperation('Deleter', m)
|
||||
|
||||
iface.setUserData('hasConcreteDescendant', True)
|
||||
iface = iface.parent
|
||||
if iface:
|
||||
iface.setUserData('hasConcreteDescendant', True)
|
||||
|
||||
if self.proxy:
|
||||
iface = self.interface
|
||||
|
|
|
@ -645,7 +645,7 @@ pub unsafe fn native_from_reflector<T>(obj: *mut JSObject) -> *const T {
|
|||
}
|
||||
|
||||
/// Get the `DOMClass` from `obj`, or `Err(())` if `obj` is not a DOM object.
|
||||
unsafe fn get_dom_class(obj: *mut JSObject) -> Result<DOMClass, ()> {
|
||||
pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()> {
|
||||
use dom::bindings::utils::DOMJSClass;
|
||||
use js::glue::GetProxyHandlerExtra;
|
||||
|
||||
|
@ -653,12 +653,12 @@ unsafe fn get_dom_class(obj: *mut JSObject) -> Result<DOMClass, ()> {
|
|||
if is_dom_class(&*clasp) {
|
||||
debug!("plain old dom object");
|
||||
let domjsclass: *const DOMJSClass = clasp as *const DOMJSClass;
|
||||
return Ok((*domjsclass).dom_class);
|
||||
return Ok(&(&*domjsclass).dom_class);
|
||||
}
|
||||
if is_dom_proxy(obj) {
|
||||
debug!("proxy dom object");
|
||||
let dom_class: *const DOMClass = GetProxyHandlerExtra(obj) as *const DOMClass;
|
||||
return Ok(*dom_class);
|
||||
return Ok(&*dom_class);
|
||||
}
|
||||
debug!("not a dom object");
|
||||
Err(())
|
||||
|
|
|
@ -15,6 +15,7 @@ use dom::bindings::global::GlobalRef;
|
|||
use dom::bindings::js::Root;
|
||||
use dom::bindings::trace::trace_object;
|
||||
use dom::browsercontext;
|
||||
use dom::eventtarget::EventTargetTypeId;
|
||||
use dom::window;
|
||||
use util::mem::HeapSizeOf;
|
||||
use util::str::DOMString;
|
||||
|
@ -157,6 +158,9 @@ pub struct DOMClass {
|
|||
/// derivedness.
|
||||
pub interface_chain: [PrototypeList::ID; MAX_PROTO_CHAIN_LENGTH],
|
||||
|
||||
/// The EventTarget type, if this is derived from an EventTarget.
|
||||
pub type_id: Option<EventTargetTypeId>,
|
||||
|
||||
/// The NativePropertyHooks for the interface associated with this class.
|
||||
pub native_hooks: &'static NativePropertyHooks,
|
||||
}
|
||||
|
|
|
@ -158,8 +158,10 @@ impl CharacterDataMethods for CharacterData {
|
|||
}
|
||||
|
||||
/// The different types of CharacterData.
|
||||
#[derive(JSTraceable, Copy, Clone, PartialEq, Debug, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum CharacterDataTypeId {
|
||||
CharacterData,
|
||||
|
||||
Comment,
|
||||
Text,
|
||||
ProcessingInstruction,
|
||||
|
|
|
@ -163,8 +163,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
-> DedicatedWorkerGlobalScope {
|
||||
DedicatedWorkerGlobalScope {
|
||||
workerglobalscope: WorkerGlobalScope::new_inherited(
|
||||
WorkerGlobalScopeTypeId::DedicatedGlobalScope, init, worker_url,
|
||||
runtime, from_devtools_receiver),
|
||||
init, worker_url, runtime, from_devtools_receiver),
|
||||
id: id,
|
||||
receiver: receiver,
|
||||
own_sender: own_sender,
|
||||
|
@ -364,7 +363,7 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
|
|||
impl DedicatedWorkerGlobalScopeDerived for EventTarget {
|
||||
fn is_dedicatedworkerglobalscope(&self) -> bool {
|
||||
match *self.type_id() {
|
||||
EventTargetTypeId::WorkerGlobalScope(WorkerGlobalScopeTypeId::DedicatedGlobalScope) => true,
|
||||
EventTargetTypeId::WorkerGlobalScope(WorkerGlobalScopeTypeId::DedicatedWorkerGlobalScope) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ impl PartialEq for Element {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone, PartialEq, Debug, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum ElementTypeId {
|
||||
HTMLElement(HTMLElementTypeId),
|
||||
Element,
|
||||
|
|
|
@ -7,6 +7,7 @@ use dom::bindings::cell::DOMRefCell;
|
|||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
|
||||
use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
|
||||
use dom::bindings::conversions::get_dom_class;
|
||||
use dom::bindings::error::Error::InvalidState;
|
||||
use dom::bindings::error::{Fallible, report_pending_exception};
|
||||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
|
@ -45,9 +46,10 @@ pub enum ListenerPhase {
|
|||
Bubbling,
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone)]
|
||||
#[derive(HeapSizeOf)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum EventTargetTypeId {
|
||||
EventTarget,
|
||||
|
||||
Node(NodeTypeId),
|
||||
WebSocket,
|
||||
Window,
|
||||
|
@ -132,15 +134,13 @@ pub struct EventListenerEntry {
|
|||
#[dom_struct]
|
||||
pub struct EventTarget {
|
||||
reflector_: Reflector,
|
||||
type_id: EventTargetTypeId,
|
||||
handlers: DOMRefCell<HashMap<DOMString, Vec<EventListenerEntry>, DefaultState<FnvHasher>>>,
|
||||
}
|
||||
|
||||
impl EventTarget {
|
||||
pub fn new_inherited(type_id: EventTargetTypeId) -> EventTarget {
|
||||
pub fn new_inherited() -> EventTarget {
|
||||
EventTarget {
|
||||
reflector_: Reflector::new(),
|
||||
type_id: type_id,
|
||||
handlers: DOMRefCell::new(Default::default()),
|
||||
}
|
||||
}
|
||||
|
@ -159,9 +159,12 @@ impl EventTarget {
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn type_id(&self) -> &EventTargetTypeId {
|
||||
&self.type_id
|
||||
let domclass = unsafe {
|
||||
get_dom_class(self.reflector_.get_jsobject().get()).unwrap()
|
||||
};
|
||||
domclass.type_id.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn dispatch_event_with_target(&self,
|
||||
|
|
|
@ -15,7 +15,7 @@ use dom::bindings::utils::{reflect_dom_object, Reflectable};
|
|||
use dom::blob::Blob;
|
||||
use dom::domexception::{DOMException, DOMErrorName};
|
||||
use dom::event::{EventCancelable, EventBubbles};
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::progressevent::ProgressEvent;
|
||||
use encoding::all::UTF_8;
|
||||
use encoding::label::encoding_from_whatwg_label;
|
||||
|
@ -80,7 +80,7 @@ pub struct FileReader {
|
|||
impl FileReader {
|
||||
pub fn new_inherited(global: GlobalRef) -> FileReader {
|
||||
FileReader {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::FileReader),//?
|
||||
eventtarget: EventTarget::new_inherited(),//?
|
||||
global: GlobalField::from_rooted(&global),
|
||||
ready_state: Cell::new(FileReaderReadyState::Empty),
|
||||
error: MutNullableHeap::new(None),
|
||||
|
|
|
@ -344,7 +344,7 @@ impl VirtualMethods for HTMLElement {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone, Debug, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum HTMLElementTypeId {
|
||||
HTMLElement,
|
||||
|
||||
|
|
|
@ -41,8 +41,10 @@ impl HTMLMediaElement {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone, Debug, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum HTMLMediaElementTypeId {
|
||||
HTMLMediaElement = -1,
|
||||
|
||||
HTMLAudioElement = 0,
|
||||
HTMLVideoElement = 1,
|
||||
}
|
||||
|
|
|
@ -22,8 +22,10 @@ use std::cmp::max;
|
|||
|
||||
const DEFAULT_COLSPAN: u32 = 1;
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone, Debug, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum HTMLTableCellElementTypeId {
|
||||
HTMLTableCellElement = -1,
|
||||
|
||||
HTMLTableDataCellElement = 0,
|
||||
HTMLTableHeaderCellElement = 1,
|
||||
}
|
||||
|
|
|
@ -81,9 +81,6 @@ pub struct Node {
|
|||
/// The JavaScript reflector for this node.
|
||||
eventtarget: EventTarget,
|
||||
|
||||
/// The type of node that this is.
|
||||
type_id: NodeTypeId,
|
||||
|
||||
/// The parent of this node.
|
||||
parent_node: MutNullableHeap<JS<Node>>,
|
||||
|
||||
|
@ -284,9 +281,10 @@ impl LayoutDataRef {
|
|||
}
|
||||
|
||||
/// The different types of nodes.
|
||||
#[derive(JSTraceable, Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(HeapSizeOf)]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum NodeTypeId {
|
||||
Node,
|
||||
|
||||
CharacterData(CharacterDataTypeId),
|
||||
DocumentType,
|
||||
DocumentFragment,
|
||||
|
@ -452,7 +450,7 @@ impl Node {
|
|||
|
||||
/// Returns a string that describes this node.
|
||||
pub fn debug_str(&self) -> String {
|
||||
format!("{:?}", self.type_id)
|
||||
format!("{:?}", self.type_id())
|
||||
}
|
||||
|
||||
pub fn is_in_doc(&self) -> bool {
|
||||
|
@ -461,12 +459,15 @@ impl Node {
|
|||
|
||||
/// Returns the type ID of this node. Fails if this node is borrowed mutably.
|
||||
pub fn type_id(&self) -> NodeTypeId {
|
||||
self.type_id
|
||||
match *self.eventtarget.type_id() {
|
||||
EventTargetTypeId::Node(type_id) => type_id,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-length
|
||||
pub fn len(&self) -> u32 {
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::DocumentType => 0,
|
||||
NodeTypeId::CharacterData(_) => {
|
||||
CharacterDataCast::to_ref(self).unwrap().Length()
|
||||
|
@ -486,12 +487,12 @@ impl Node {
|
|||
|
||||
#[inline]
|
||||
pub fn is_anchor_element(&self) -> bool {
|
||||
self.type_id == NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement))
|
||||
self.type_id() == NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_doctype(&self) -> bool {
|
||||
self.type_id == NodeTypeId::DocumentType
|
||||
self.type_id() == NodeTypeId::DocumentType
|
||||
}
|
||||
|
||||
pub fn get_flag(&self, flag: NodeFlags) -> bool {
|
||||
|
@ -1026,7 +1027,7 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
|
|||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn type_id_for_layout(&self) -> NodeTypeId {
|
||||
(*self.unsafe_get()).type_id
|
||||
(*self.unsafe_get()).type_id()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1393,8 +1394,7 @@ impl Node {
|
|||
|
||||
fn new_(type_id: NodeTypeId, doc: Option<&Document>) -> Node {
|
||||
Node {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::Node(type_id)),
|
||||
type_id: type_id,
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
|
||||
parent_node: Default::default(),
|
||||
first_child: Default::default(),
|
||||
|
@ -1456,6 +1456,8 @@ impl Node {
|
|||
|
||||
// Step 4-5.
|
||||
match node.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData) => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
|
||||
if parent.is_document() {
|
||||
return Err(HierarchyRequest);
|
||||
|
@ -1538,7 +1540,7 @@ impl Node {
|
|||
}
|
||||
},
|
||||
NodeTypeId::CharacterData(_) => (),
|
||||
NodeTypeId::Document => unreachable!(),
|
||||
NodeTypeId::Document | NodeTypeId::Node => unreachable!(),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1698,6 +1700,8 @@ impl Node {
|
|||
// Step 2.
|
||||
// XXXabinader: clone() for each node as trait?
|
||||
let copy: Root<Node> = match node.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData) => unreachable!(),
|
||||
NodeTypeId::DocumentType => {
|
||||
let doctype: &DocumentType = DocumentTypeCast::to_ref(node).unwrap();
|
||||
let doctype = DocumentType::new(doctype.name().clone(),
|
||||
|
@ -1833,7 +1837,7 @@ impl Node {
|
|||
}
|
||||
}
|
||||
|
||||
match node.type_id {
|
||||
match node.type_id() {
|
||||
NodeTypeId::Element(_) => {
|
||||
let element = ElementCast::to_ref(node).unwrap();
|
||||
// Step 1.
|
||||
|
@ -1889,7 +1893,9 @@ impl Node {
|
|||
impl NodeMethods for Node {
|
||||
// https://dom.spec.whatwg.org/#dom-node-nodetype
|
||||
fn NodeType(&self) -> u16 {
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData) => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) =>
|
||||
NodeConstants::TEXT_NODE,
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) =>
|
||||
|
@ -1909,11 +1915,13 @@ impl NodeMethods for Node {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-node-nodename
|
||||
fn NodeName(&self) -> DOMString {
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::Element(..) => {
|
||||
let elem: &Element = ElementCast::to_ref(self).unwrap();
|
||||
elem.TagName()
|
||||
}
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData) => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
||||
let processing_instruction: &ProcessingInstruction =
|
||||
|
@ -1937,7 +1945,8 @@ impl NodeMethods for Node {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-node-ownerdocument
|
||||
fn GetOwnerDocument(&self) -> Option<Root<Document>> {
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(..) |
|
||||
NodeTypeId::Element(..) |
|
||||
NodeTypeId::DocumentType |
|
||||
|
@ -1992,19 +2001,31 @@ impl NodeMethods for Node {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-node-nodevalue
|
||||
fn GetNodeValue(&self) -> Option<DOMString> {
|
||||
CharacterDataCast::to_ref(self).map(|c| c.Data())
|
||||
match self.type_id() {
|
||||
NodeTypeId::CharacterData(..) => {
|
||||
let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
|
||||
Some(chardata.Data())
|
||||
}
|
||||
_ => {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-nodevalue
|
||||
fn SetNodeValue(&self, val: Option<DOMString>) {
|
||||
if let NodeTypeId::CharacterData(..) = self.type_id {
|
||||
self.SetTextContent(val)
|
||||
match self.type_id() {
|
||||
NodeTypeId::CharacterData(..) => {
|
||||
self.SetTextContent(val)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-textcontent
|
||||
fn GetTextContent(&self) -> Option<DOMString> {
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => {
|
||||
let content = Node::collect_text_contents(self.traverse_preorder());
|
||||
|
@ -2024,7 +2045,8 @@ impl NodeMethods for Node {
|
|||
// https://dom.spec.whatwg.org/#dom-node-textcontent
|
||||
fn SetTextContent(&self, value: Option<DOMString>) {
|
||||
let value = value.unwrap_or(String::new());
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => {
|
||||
// Step 1-2.
|
||||
|
@ -2065,7 +2087,7 @@ impl NodeMethods for Node {
|
|||
fn ReplaceChild(&self, node: &Node, child: &Node) -> Fallible<Root<Node>> {
|
||||
|
||||
// Step 1.
|
||||
match self.type_id {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Document |
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => (),
|
||||
|
@ -2084,6 +2106,7 @@ impl NodeMethods for Node {
|
|||
|
||||
// Step 4-5.
|
||||
match node.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is_document() =>
|
||||
return Err(HierarchyRequest),
|
||||
NodeTypeId::DocumentType if !self.is_document() => return Err(HierarchyRequest),
|
||||
|
@ -2147,7 +2170,7 @@ impl NodeMethods for Node {
|
|||
}
|
||||
},
|
||||
NodeTypeId::CharacterData(..) => (),
|
||||
NodeTypeId::Document => unreachable!()
|
||||
NodeTypeId::Document | NodeTypeId::Node => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use dom::bindings::utils::{reflect_dom_object, Reflectable};
|
|||
use dom::blob::Blob;
|
||||
use dom::closeevent::CloseEvent;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::messageevent::MessageEvent;
|
||||
use script_task::ScriptTaskEventCategory::WebSocketEvent;
|
||||
use script_task::{Runnable, CommonScriptMsg};
|
||||
|
@ -110,7 +110,7 @@ fn establish_a_websocket_connection(resource_url: &Url, net_url: (Host, String,
|
|||
impl WebSocket {
|
||||
fn new_inherited(global: GlobalRef, url: Url) -> WebSocket {
|
||||
WebSocket {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::WebSocket),
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
url: url,
|
||||
global: GlobalField::from_rooted(&global),
|
||||
ready_state: Cell::new(WebSocketRequestState::Connecting),
|
||||
|
|
|
@ -1288,7 +1288,7 @@ impl Window {
|
|||
};
|
||||
|
||||
let win = box Window {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::Window),
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
script_chan: script_chan,
|
||||
image_cache_chan: image_cache_chan,
|
||||
control_chan: control_chan,
|
||||
|
|
|
@ -17,7 +17,7 @@ use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
|||
use dom::dedicatedworkerglobalscope::{DedicatedWorkerGlobalScope, WorkerScriptMsg};
|
||||
use dom::errorevent::ErrorEvent;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::messageevent::MessageEvent;
|
||||
use dom::workerglobalscope::WorkerGlobalScopeInit;
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl Worker {
|
|||
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>)
|
||||
-> Worker {
|
||||
Worker {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::Worker),
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
global: GlobalField::from_rooted(&global),
|
||||
sender: sender,
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use dom::bindings::js::{JS, Root, MutNullableHeap};
|
|||
use dom::bindings::utils::Reflectable;
|
||||
use dom::console::Console;
|
||||
use dom::crypto::Crypto;
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::window::{base64_atob, base64_btoa};
|
||||
use dom::workerlocation::WorkerLocation;
|
||||
use dom::workernavigator::WorkerNavigator;
|
||||
|
@ -36,9 +36,11 @@ use std::default::Default;
|
|||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone, PartialEq, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum WorkerGlobalScopeTypeId {
|
||||
DedicatedGlobalScope,
|
||||
WorkerGlobalScope,
|
||||
|
||||
DedicatedWorkerGlobalScope,
|
||||
}
|
||||
|
||||
pub struct WorkerGlobalScopeInit {
|
||||
|
@ -90,14 +92,13 @@ pub struct WorkerGlobalScope {
|
|||
}
|
||||
|
||||
impl WorkerGlobalScope {
|
||||
pub fn new_inherited(type_id: WorkerGlobalScopeTypeId,
|
||||
init: WorkerGlobalScopeInit,
|
||||
pub fn new_inherited(init: WorkerGlobalScopeInit,
|
||||
worker_url: Url,
|
||||
runtime: Rc<Runtime>,
|
||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>)
|
||||
-> WorkerGlobalScope {
|
||||
WorkerGlobalScope {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::WorkerGlobalScope(type_id)),
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
next_worker_id: Cell::new(WorkerId(0)),
|
||||
worker_id: init.worker_id,
|
||||
worker_url: worker_url,
|
||||
|
|
|
@ -155,7 +155,7 @@ pub struct XMLHttpRequest {
|
|||
impl XMLHttpRequest {
|
||||
fn new_inherited(global: GlobalRef) -> XMLHttpRequest {
|
||||
XMLHttpRequest {
|
||||
eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestEventTargetTypeId::XMLHttpRequest),
|
||||
eventtarget: XMLHttpRequestEventTarget::new_inherited(),
|
||||
ready_state: Cell::new(XMLHttpRequestState::Unsent),
|
||||
timeout: Cell::new(0u32),
|
||||
with_credentials: Cell::new(false),
|
||||
|
|
|
@ -8,8 +8,10 @@ use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
|||
use dom::bindings::codegen::InheritTypes::XMLHttpRequestEventTargetDerived;
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
|
||||
#[derive(JSTraceable, Copy, Clone, PartialEq, HeapSizeOf)]
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum XMLHttpRequestEventTargetTypeId {
|
||||
XMLHttpRequestEventTarget,
|
||||
|
||||
XMLHttpRequest,
|
||||
XMLHttpRequestUpload,
|
||||
}
|
||||
|
@ -20,9 +22,9 @@ pub struct XMLHttpRequestEventTarget {
|
|||
}
|
||||
|
||||
impl XMLHttpRequestEventTarget {
|
||||
pub fn new_inherited(type_id: XMLHttpRequestEventTargetTypeId) -> XMLHttpRequestEventTarget {
|
||||
pub fn new_inherited() -> XMLHttpRequestEventTarget {
|
||||
XMLHttpRequestEventTarget {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::XMLHttpRequestEventTarget(type_id))
|
||||
eventtarget: EventTarget::new_inherited()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@ pub struct XMLHttpRequestUpload {
|
|||
impl XMLHttpRequestUpload {
|
||||
fn new_inherited() -> XMLHttpRequestUpload {
|
||||
XMLHttpRequestUpload {
|
||||
eventtarget: XMLHttpRequestEventTarget::new_inherited(
|
||||
XMLHttpRequestEventTargetTypeId::XMLHttpRequestUpload)
|
||||
eventtarget: XMLHttpRequestEventTarget::new_inherited(),
|
||||
}
|
||||
}
|
||||
pub fn new(global: GlobalRef) -> Root<XMLHttpRequestUpload> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue