mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Introduce [Abstract] to mark non-leaf interfaces
Some interfaces like Node, CharacterData and HTMLTableCellElement are never instantiated directly, only their descendant interfaces are. Those are marked with [Abstract] to set their type_id to None instead of having dummy values in the TypeId enums.
This commit is contained in:
parent
941f7dc04b
commit
c25085f68a
21 changed files with 26 additions and 48 deletions
|
@ -1430,8 +1430,6 @@ 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());
|
||||
|
@ -1587,7 +1585,6 @@ 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!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1724,7 +1724,7 @@ class CGNamespace(CGWrapper):
|
|||
|
||||
def EventTargetEnum(desc):
|
||||
protochain = desc.prototypeChain
|
||||
if protochain[0] != "EventTarget":
|
||||
if protochain[0] != "EventTarget" or desc.interface.getExtendedAttribute("Abstract"):
|
||||
return "None"
|
||||
|
||||
inner = ""
|
||||
|
|
|
@ -1357,7 +1357,8 @@ class IDLInterface(IDLObjectWithScope, IDLExposureMixins):
|
|||
identifier == "ChromeOnly" or
|
||||
identifier == "Unforgeable" or
|
||||
identifier == "UnsafeInPrerendering" or
|
||||
identifier == "LegacyEventInit"):
|
||||
identifier == "LegacyEventInit" or
|
||||
identifier == "Abstract"):
|
||||
# Known extended attributes that do not take values
|
||||
if not attr.noArguments():
|
||||
raise WebIDLError("[%s] must take no arguments" % identifier,
|
||||
|
|
12
components/script/dom/bindings/codegen/parser/abstract.patch
Normal file
12
components/script/dom/bindings/codegen/parser/abstract.patch
Normal file
|
@ -0,0 +1,12 @@
|
|||
--- WebIDL.py
|
||||
+++ WebIDL.py
|
||||
@@ -1357,7 +1357,8 @@ class IDLInterface(IDLObjectWithScope, IDLExposureMixins):
|
||||
identifier == "ChromeOnly" or
|
||||
identifier == "Unforgeable" or
|
||||
identifier == "UnsafeInPrerendering" or
|
||||
- identifier == "LegacyEventInit"):
|
||||
+ identifier == "LegacyEventInit" or
|
||||
+ identifier == "Abstract"):
|
||||
# Known extended attributes that do not take values
|
||||
if not attr.noArguments():
|
||||
raise WebIDLError("[%s] must take no arguments" % identifier,
|
|
@ -1,3 +1,4 @@
|
|||
wget https://mxr.mozilla.org/mozilla-central/source/dom/bindings/parser/WebIDL.py?raw=1 -O WebIDL.py
|
||||
patch < external.patch
|
||||
patch < module.patch
|
||||
patch < abstract.patch
|
||||
|
|
|
@ -160,8 +160,6 @@ impl CharacterDataMethods for CharacterData {
|
|||
/// The different types of CharacterData.
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum CharacterDataTypeId {
|
||||
CharacterData,
|
||||
|
||||
Comment,
|
||||
Text,
|
||||
ProcessingInstruction,
|
||||
|
|
|
@ -48,8 +48,6 @@ pub enum ListenerPhase {
|
|||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum EventTargetTypeId {
|
||||
EventTarget,
|
||||
|
||||
Node(NodeTypeId),
|
||||
WebSocket,
|
||||
Window,
|
||||
|
|
|
@ -43,8 +43,6 @@ impl HTMLMediaElement {
|
|||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum HTMLMediaElementTypeId {
|
||||
HTMLMediaElement = -1,
|
||||
|
||||
HTMLAudioElement = 0,
|
||||
HTMLVideoElement = 1,
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ const DEFAULT_COLSPAN: u32 = 1;
|
|||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum HTMLTableCellElementTypeId {
|
||||
HTMLTableCellElement = -1,
|
||||
|
||||
HTMLTableDataCellElement = 0,
|
||||
HTMLTableHeaderCellElement = 1,
|
||||
}
|
||||
|
|
|
@ -283,8 +283,6 @@ impl LayoutDataRef {
|
|||
/// The different types of nodes.
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum NodeTypeId {
|
||||
Node,
|
||||
|
||||
CharacterData(CharacterDataTypeId),
|
||||
DocumentType,
|
||||
DocumentFragment,
|
||||
|
@ -1456,8 +1454,6 @@ 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);
|
||||
|
@ -1540,7 +1536,7 @@ impl Node {
|
|||
}
|
||||
},
|
||||
NodeTypeId::CharacterData(_) => (),
|
||||
NodeTypeId::Document | NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::Document => unreachable!(),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1700,8 +1696,6 @@ 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(),
|
||||
|
@ -1894,8 +1888,6 @@ impl NodeMethods for Node {
|
|||
// https://dom.spec.whatwg.org/#dom-node-nodetype
|
||||
fn NodeType(&self) -> u16 {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData) => unreachable!(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) =>
|
||||
NodeConstants::TEXT_NODE,
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) =>
|
||||
|
@ -1916,12 +1908,10 @@ impl NodeMethods for Node {
|
|||
// https://dom.spec.whatwg.org/#dom-node-nodename
|
||||
fn NodeName(&self) -> DOMString {
|
||||
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 =
|
||||
|
@ -1946,7 +1936,6 @@ impl NodeMethods for Node {
|
|||
// https://dom.spec.whatwg.org/#dom-node-ownerdocument
|
||||
fn GetOwnerDocument(&self) -> Option<Root<Document>> {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::CharacterData(..) |
|
||||
NodeTypeId::Element(..) |
|
||||
NodeTypeId::DocumentType |
|
||||
|
@ -2025,7 +2014,6 @@ impl NodeMethods for Node {
|
|||
// https://dom.spec.whatwg.org/#dom-node-textcontent
|
||||
fn GetTextContent(&self) -> Option<DOMString> {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => {
|
||||
let content = Node::collect_text_contents(self.traverse_preorder());
|
||||
|
@ -2046,7 +2034,6 @@ impl NodeMethods for Node {
|
|||
fn SetTextContent(&self, value: Option<DOMString>) {
|
||||
let value = value.unwrap_or(String::new());
|
||||
match self.type_id() {
|
||||
NodeTypeId::Node => unreachable!(),
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => {
|
||||
// Step 1-2.
|
||||
|
@ -2106,7 +2093,6 @@ 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),
|
||||
|
@ -2170,7 +2156,7 @@ impl NodeMethods for Node {
|
|||
}
|
||||
},
|
||||
NodeTypeId::CharacterData(..) => (),
|
||||
NodeTypeId::Document | NodeTypeId::Node => unreachable!()
|
||||
NodeTypeId::Document => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
[Abstract]
|
||||
interface CharacterData : Node {
|
||||
[TreatNullAs=EmptyString] attribute DOMString data;
|
||||
readonly attribute unsigned long length;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* https://dom.spec.whatwg.org/#interface-eventtarget
|
||||
*/
|
||||
|
||||
[Abstract]
|
||||
interface EventTarget {
|
||||
void addEventListener(DOMString type,
|
||||
EventListener? listener,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
// https://www.whatwg.org/html/#htmlmediaelement
|
||||
//enum CanPlayTypeResult { "" /* empty string */, "maybe", "probably" };
|
||||
[Abstract]
|
||||
interface HTMLMediaElement : HTMLElement {
|
||||
|
||||
// error state
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://www.whatwg.org/html/#htmltablecellelement
|
||||
[Abstract]
|
||||
interface HTMLTableCellElement : HTMLElement {
|
||||
attribute unsigned long colSpan;
|
||||
// attribute unsigned long rowSpan;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* https://dom.spec.whatwg.org/#interface-node
|
||||
*/
|
||||
|
||||
[Abstract]
|
||||
interface Node : EventTarget {
|
||||
const unsigned short ELEMENT_NODE = 1;
|
||||
const unsigned short ATTRIBUTE_NODE = 2; // historical
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://www.whatwg.org/html/#workerglobalscope
|
||||
//[Exposed=Worker]
|
||||
// https://html.spec.whatwg.org/multipage/#workerglobalscope
|
||||
[Abstract/*, Exposed=Worker*/]
|
||||
interface WorkerGlobalScope : EventTarget {
|
||||
[BinaryName="Self_"] readonly attribute WorkerGlobalScope self;
|
||||
readonly attribute WorkerLocation location;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
|
||||
*/
|
||||
|
||||
//[Exposed=(Window,Worker)]
|
||||
[Abstract/*, Exposed=(Window,Worker)*/]
|
||||
interface XMLHttpRequestEventTarget : EventTarget {
|
||||
// event handlers
|
||||
attribute EventHandler onloadstart;
|
||||
|
|
|
@ -38,8 +38,6 @@ use std::sync::mpsc::Receiver;
|
|||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum WorkerGlobalScopeTypeId {
|
||||
WorkerGlobalScope,
|
||||
|
||||
DedicatedWorkerGlobalScope,
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
|||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum XMLHttpRequestEventTargetTypeId {
|
||||
XMLHttpRequestEventTarget,
|
||||
|
||||
XMLHttpRequest,
|
||||
XMLHttpRequestUpload,
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@ use dom::element::ElementTypeId;
|
|||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::htmlelement::HTMLElementTypeId;
|
||||
use dom::htmlmediaelement::HTMLMediaElementTypeId::HTMLAudioElement;
|
||||
use dom::htmlmediaelement::HTMLMediaElementTypeId::HTMLMediaElement;
|
||||
use dom::htmlmediaelement::HTMLMediaElementTypeId::HTMLVideoElement;
|
||||
use dom::htmltablecellelement::HTMLTableCellElementTypeId::HTMLTableCellElement;
|
||||
use dom::htmltablecellelement::HTMLTableCellElementTypeId::HTMLTableDataCellElement;
|
||||
use dom::htmltablecellelement::HTMLTableCellElementTypeId::HTMLTableHeaderCellElement;
|
||||
use dom::node::NodeTypeId;
|
||||
|
@ -249,13 +247,5 @@ pub fn heap_size_of_eventtarget(target: &EventTarget) -> usize {
|
|||
heap_size_of_self_and_children(DocumentTypeCast::to_ref(target).unwrap()),
|
||||
&EventTargetTypeId::Node(NodeTypeId::DocumentFragment) =>
|
||||
heap_size_of_self_and_children(DocumentFragmentCast::to_ref(target).unwrap()),
|
||||
&EventTargetTypeId::EventTarget |
|
||||
&EventTargetTypeId::Node(NodeTypeId::Node) |
|
||||
&EventTargetTypeId::Node(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||
HTMLElementTypeId::HTMLMediaElement(HTMLMediaElement)))) |
|
||||
&EventTargetTypeId::Node(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||
HTMLElementTypeId::HTMLTableCellElement(HTMLTableCellElement)))) => {
|
||||
unreachable!()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,8 +184,6 @@ impl<'a> Serializable for &'a Node {
|
|||
traversal_scope: TraversalScope) -> io::Result<()> {
|
||||
let node = *self;
|
||||
match (traversal_scope, node.type_id()) {
|
||||
(_, NodeTypeId::Node) => unreachable!(),
|
||||
(_, NodeTypeId::CharacterData(CharacterDataTypeId::CharacterData)) => unreachable!(),
|
||||
(_, NodeTypeId::Element(..)) => {
|
||||
let elem = ElementCast::to_ref(node).unwrap();
|
||||
let name = QualName::new(elem.namespace().clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue