mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
auto merge of #1929 : saneyuki/servo/const, r=Ms2ger
We can use `TConstants` instead of by #1914 fixed.
This commit is contained in:
commit
caf1ed9446
4 changed files with 54 additions and 46 deletions
|
@ -2994,7 +2994,7 @@ class CGConstant(CGThing):
|
||||||
def stringDecl(const):
|
def stringDecl(const):
|
||||||
name = const.identifier.name
|
name = const.identifier.name
|
||||||
value = convertConstIDLValueToRust(const.value)
|
value = convertConstIDLValueToRust(const.value)
|
||||||
return CGGeneric("static %s: %s = %s;\n" % (name, builtinNames[const.value.type.tag()], value))
|
return CGGeneric("pub static %s: %s = %s;\n" % (name, builtinNames[const.value.type.tag()], value))
|
||||||
|
|
||||||
return CGIndenter(CGList(stringDecl(m) for m in self.constants)).define()
|
return CGIndenter(CGList(stringDecl(m) for m in self.constants)).define()
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::DOMExceptionBinding;
|
use dom::bindings::codegen::DOMExceptionBinding;
|
||||||
|
use dom::bindings::codegen::DOMExceptionBinding::DOMExceptionConstants;
|
||||||
use dom::bindings::js::JS;
|
use dom::bindings::js::JS;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
@ -11,26 +12,26 @@ use servo_util::str::DOMString;
|
||||||
#[repr(uint)]
|
#[repr(uint)]
|
||||||
#[deriving(ToStr, Encodable)]
|
#[deriving(ToStr, Encodable)]
|
||||||
enum DOMErrorName {
|
enum DOMErrorName {
|
||||||
IndexSizeError = 1,
|
IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR,
|
||||||
HierarchyRequestError = 3,
|
HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR,
|
||||||
WrongDocumentError = 4,
|
WrongDocumentError = DOMExceptionConstants::WRONG_DOCUMENT_ERR,
|
||||||
InvalidCharacterError = 5,
|
InvalidCharacterError = DOMExceptionConstants::INVALID_CHARACTER_ERR,
|
||||||
NoModificationAllowedError = 7,
|
NoModificationAllowedError = DOMExceptionConstants::NO_MODIFICATION_ALLOWED_ERR,
|
||||||
NotFoundError = 8,
|
NotFoundError = DOMExceptionConstants::NOT_FOUND_ERR,
|
||||||
NotSupportedError = 9,
|
NotSupportedError = DOMExceptionConstants::NOT_SUPPORTED_ERR,
|
||||||
InvalidStateError = 11,
|
InvalidStateError = DOMExceptionConstants::INVALID_STATE_ERR,
|
||||||
SyntaxError = 12,
|
SyntaxError = DOMExceptionConstants::SYNTAX_ERR,
|
||||||
InvalidModificationError = 13,
|
InvalidModificationError = DOMExceptionConstants::INVALID_MODIFICATION_ERR,
|
||||||
NamespaceError = 14,
|
NamespaceError = DOMExceptionConstants::NAMESPACE_ERR,
|
||||||
InvalidAccessError = 15,
|
InvalidAccessError = DOMExceptionConstants::INVALID_ACCESS_ERR,
|
||||||
SecurityError = 18,
|
SecurityError = DOMExceptionConstants::SECURITY_ERR,
|
||||||
NetworkError = 19,
|
NetworkError = DOMExceptionConstants::NETWORK_ERR,
|
||||||
AbortError = 20,
|
AbortError = DOMExceptionConstants::ABORT_ERR,
|
||||||
URLMismatchError = 21,
|
URLMismatchError = DOMExceptionConstants::URL_MISMATCH_ERR,
|
||||||
QuotaExceededError = 22,
|
QuotaExceededError = DOMExceptionConstants::QUOTA_EXCEEDED_ERR,
|
||||||
TimeoutError = 23,
|
TimeoutError = DOMExceptionConstants::TIMEOUT_ERR,
|
||||||
InvalidNodeTypeError = 24,
|
InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
|
||||||
DataCloneError = 25,
|
DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
|
||||||
EncodingError
|
EncodingError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::EventBinding;
|
use dom::bindings::codegen::EventBinding;
|
||||||
|
use dom::bindings::codegen::EventBinding::EventConstants;
|
||||||
use dom::bindings::js::JS;
|
use dom::bindings::js::JS;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::bindings::error::{Fallible, ErrorResult};
|
use dom::bindings::error::{Fallible, ErrorResult};
|
||||||
|
@ -23,10 +24,10 @@ pub enum Event_ {
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub enum EventPhase {
|
pub enum EventPhase {
|
||||||
Phase_None = 0,
|
Phase_None = EventConstants::NONE,
|
||||||
Phase_Capturing,
|
Phase_Capturing = EventConstants::CAPTURING_PHASE,
|
||||||
Phase_At_Target,
|
Phase_At_Target = EventConstants::AT_TARGET,
|
||||||
Phase_Bubbling
|
Phase_Bubbling = EventConstants::BUBBLING_PHASE,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable)]
|
#[deriving(Eq, Encodable)]
|
||||||
|
|
|
@ -9,6 +9,7 @@ use dom::bindings::codegen::InheritTypes::{CommentCast, DocumentCast, DocumentTy
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast};
|
use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast};
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived};
|
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived};
|
||||||
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
|
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
|
||||||
|
use dom::bindings::codegen::NodeBinding::NodeConstants;
|
||||||
use dom::bindings::js::JS;
|
use dom::bindings::js::JS;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest};
|
use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest};
|
||||||
|
@ -817,13 +818,13 @@ impl Node {
|
||||||
// http://dom.spec.whatwg.org/#dom-node-nodetype
|
// http://dom.spec.whatwg.org/#dom-node-nodetype
|
||||||
pub fn NodeType(&self) -> u16 {
|
pub fn NodeType(&self) -> u16 {
|
||||||
match self.type_id {
|
match self.type_id {
|
||||||
ElementNodeTypeId(_) => 1,
|
ElementNodeTypeId(_) => NodeConstants::ELEMENT_NODE,
|
||||||
TextNodeTypeId => 3,
|
TextNodeTypeId => NodeConstants::TEXT_NODE,
|
||||||
ProcessingInstructionNodeTypeId => 7,
|
ProcessingInstructionNodeTypeId => NodeConstants::PROCESSING_INSTRUCTION_NODE,
|
||||||
CommentNodeTypeId => 8,
|
CommentNodeTypeId => NodeConstants::COMMENT_NODE,
|
||||||
DocumentNodeTypeId => 9,
|
DocumentNodeTypeId => NodeConstants::DOCUMENT_NODE,
|
||||||
DoctypeNodeTypeId => 10,
|
DoctypeNodeTypeId => NodeConstants::DOCUMENT_TYPE_NODE,
|
||||||
DocumentFragmentNodeTypeId => 11,
|
DocumentFragmentNodeTypeId => NodeConstants::DOCUMENT_FRAGMENT_NODE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1659,45 +1660,50 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
|
// http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
|
||||||
|
|
||||||
pub fn CompareDocumentPosition(&self, abstract_self: &JS<Node>, other: &JS<Node>) -> u16 {
|
pub fn CompareDocumentPosition(&self, abstract_self: &JS<Node>, other: &JS<Node>) -> u16 {
|
||||||
static DOCUMENT_POSITION_DISCONNECTED: u16 = 0x01u16;
|
|
||||||
static DOCUMENT_POSITION_PRECEDING: u16 = 0x02u16;
|
|
||||||
static DOCUMENT_POSITION_FOLLOWING: u16 = 0x04u16;
|
|
||||||
static DOCUMENT_POSITION_CONTAINS: u16 = 0x08u16;
|
|
||||||
static DOCUMENT_POSITION_CONTAINED_BY: u16 = 0x10u16;
|
|
||||||
static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: u16 = 0x20u16;
|
|
||||||
if abstract_self == other {
|
if abstract_self == other {
|
||||||
|
// step 2.
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
let mut lastself = abstract_self.clone();
|
let mut lastself = abstract_self.clone();
|
||||||
let mut lastother = other.clone();
|
let mut lastother = other.clone();
|
||||||
for ancestor in abstract_self.ancestors() {
|
for ancestor in abstract_self.ancestors() {
|
||||||
if &ancestor == other {
|
if &ancestor == other {
|
||||||
return DOCUMENT_POSITION_CONTAINS + DOCUMENT_POSITION_PRECEDING;
|
// step 4.
|
||||||
|
return NodeConstants::DOCUMENT_POSITION_CONTAINS +
|
||||||
|
NodeConstants::DOCUMENT_POSITION_PRECEDING;
|
||||||
}
|
}
|
||||||
lastself = ancestor;
|
lastself = ancestor;
|
||||||
}
|
}
|
||||||
for ancestor in other.ancestors() {
|
for ancestor in other.ancestors() {
|
||||||
if &ancestor == abstract_self {
|
if &ancestor == abstract_self {
|
||||||
return DOCUMENT_POSITION_CONTAINED_BY + DOCUMENT_POSITION_FOLLOWING;
|
// step 5.
|
||||||
|
return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY +
|
||||||
|
NodeConstants::DOCUMENT_POSITION_FOLLOWING;
|
||||||
}
|
}
|
||||||
lastother = ancestor;
|
lastother = ancestor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if lastself != lastother {
|
if lastself != lastother {
|
||||||
let random = if ptr::to_unsafe_ptr(abstract_self.get()) < ptr::to_unsafe_ptr(other.get()) {
|
let random = if ptr::to_unsafe_ptr(abstract_self.get()) < ptr::to_unsafe_ptr(other.get()) {
|
||||||
DOCUMENT_POSITION_FOLLOWING
|
NodeConstants::DOCUMENT_POSITION_FOLLOWING
|
||||||
} else {
|
} else {
|
||||||
DOCUMENT_POSITION_PRECEDING
|
NodeConstants::DOCUMENT_POSITION_PRECEDING
|
||||||
};
|
};
|
||||||
return random + DOCUMENT_POSITION_DISCONNECTED + DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
|
// step 3.
|
||||||
|
return random +
|
||||||
|
NodeConstants::DOCUMENT_POSITION_DISCONNECTED +
|
||||||
|
NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for child in lastself.traverse_preorder() {
|
for child in lastself.traverse_preorder() {
|
||||||
if &child == other {
|
if &child == other {
|
||||||
return DOCUMENT_POSITION_PRECEDING;
|
// step 6.
|
||||||
|
return NodeConstants::DOCUMENT_POSITION_PRECEDING;
|
||||||
}
|
}
|
||||||
if &child == abstract_self {
|
if &child == abstract_self {
|
||||||
return DOCUMENT_POSITION_FOLLOWING;
|
// step 7.
|
||||||
|
return NodeConstants::DOCUMENT_POSITION_FOLLOWING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue