Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move EventTargetTypeId/NodeTypeId to DOMClass #6615

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1394,6 +1394,8 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
Some(NodeTypeId::Document) => {
(display::T::none, float::T::none, position::T::static_)
}
Some(NodeTypeId::Node) => unreachable!(),
Some(NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData)) => unreachable!(),
};

debug!("building flow for node: {:?} {:?} {:?} {:?}", display, float, positioning, node.type_id());
@@ -1543,6 +1545,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLObjectElement))) => self.has_object_data(),
Some(NodeTypeId::Element(_)) => false,
Some(NodeTypeId::Node) => unreachable!(),
}
}

@@ -1764,6 +1764,25 @@ def build(namespaces, child, public=False):
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
@@ -1776,7 +1795,8 @@ def DOMClass(descriptor):
DOMClass {
interface_chain: [ %s ],
native_hooks: &sNativePropertyHooks,
}""" % prototypeChainString
type_id: %s,
}""" % (prototypeChainString, EventTargetEnum(descriptor))


class CGDOMJSClass(CGThing):
@@ -225,8 +225,9 @@ def addIndexedOrNamedOperation(operation, m):
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,20 +645,20 @@ 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;

let clasp = JS_GetClass(obj);
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");
return Err(());
@@ -14,6 +14,7 @@ use dom::bindings::error::throw_type_error;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root;
use dom::bindings::trace::trace_object;
use dom::eventtarget::EventTargetTypeId;
use dom::browsercontext;
use dom::window;
use util::mem::HeapSizeOf;
@@ -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,
}
@@ -151,8 +151,10 @@ impl<'a> CharacterDataMethods for &'a 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,
@@ -116,8 +116,7 @@ impl DedicatedWorkerGlobalScope {
-> DedicatedWorkerGlobalScope {
DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope::new_inherited(
WorkerGlobalScopeTypeId::DedicatedGlobalScope, init, worker_url,
runtime, devtools_port),
init, worker_url, runtime, devtools_port),
id: id,
receiver: receiver,
own_sender: own_sender,
@@ -375,7 +374,7 @@ impl<'a> DedicatedWorkerGlobalScopeMethods for &'a 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
}
}
@@ -120,7 +120,7 @@ impl PartialEq for Element {
}
}

#[derive(JSTraceable, Copy, Clone, PartialEq, Debug, HeapSizeOf)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum ElementTypeId {
HTMLElement(HTMLElementTypeId),
Element,
@@ -4,6 +4,7 @@

use dom::bindings::callback::CallbackContainer;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::conversions::get_dom_class;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
@@ -43,9 +44,10 @@ pub enum ListenerPhase {
Bubbling,
}

#[derive(JSTraceable, Copy, Clone)]
#[derive(HeapSizeOf)]
#[derive(Copy, Clone)]
pub enum EventTargetTypeId {
EventTarget,

Node(NodeTypeId),
WebSocket,
Window,
@@ -124,15 +126,13 @@ pub struct EventListenerEntry {
#[derive(HeapSizeOf)]
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()),
}
}
@@ -151,9 +151,15 @@ impl EventTarget {
})
}

#[inline]
#[allow(unsafe_code)]
pub fn type_id<'a>(&'a self) -> &'a EventTargetTypeId {
&self.type_id
let domclass = unsafe {
get_dom_class(self.reflector_.get_jsobject().get()).unwrap()
};
match domclass.type_id {
Some(ref type_id) => type_id,
None => unreachable!(),
}
}
}

@@ -13,7 +13,7 @@ use dom::bindings::js::{Root, JS, MutNullableHeap};
use dom::bindings::refcounted::Trusted;
use dom::bindings::utils::{reflect_dom_object, Reflectable};
use dom::event::{EventHelpers, EventCancelable, EventBubbles};
use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId};
use dom::eventtarget::{EventTarget, EventTargetHelpers};
use dom::blob::{Blob, BlobHelpers};
use dom::domexception::{DOMException, DOMErrorName};
use dom::progressevent::ProgressEvent;
@@ -100,7 +100,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),
@@ -366,7 +366,7 @@ impl<'a> VirtualMethods for &'a 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,
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.