auto merge of #1929 : saneyuki/servo/const, r=Ms2ger

We can use `TConstants` instead of by #1914 fixed.
This commit is contained in:
bors-servo 2014-03-16 04:35:14 -04:00
commit caf1ed9446
4 changed files with 54 additions and 46 deletions

View file

@ -2994,7 +2994,7 @@ class CGConstant(CGThing):
def stringDecl(const):
name = const.identifier.name
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()

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::DOMExceptionBinding;
use dom::bindings::codegen::DOMExceptionBinding::DOMExceptionConstants;
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
@ -11,26 +12,26 @@ use servo_util::str::DOMString;
#[repr(uint)]
#[deriving(ToStr, Encodable)]
enum DOMErrorName {
IndexSizeError = 1,
HierarchyRequestError = 3,
WrongDocumentError = 4,
InvalidCharacterError = 5,
NoModificationAllowedError = 7,
NotFoundError = 8,
NotSupportedError = 9,
InvalidStateError = 11,
SyntaxError = 12,
InvalidModificationError = 13,
NamespaceError = 14,
InvalidAccessError = 15,
SecurityError = 18,
NetworkError = 19,
AbortError = 20,
URLMismatchError = 21,
QuotaExceededError = 22,
TimeoutError = 23,
InvalidNodeTypeError = 24,
DataCloneError = 25,
IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR,
HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR,
WrongDocumentError = DOMExceptionConstants::WRONG_DOCUMENT_ERR,
InvalidCharacterError = DOMExceptionConstants::INVALID_CHARACTER_ERR,
NoModificationAllowedError = DOMExceptionConstants::NO_MODIFICATION_ALLOWED_ERR,
NotFoundError = DOMExceptionConstants::NOT_FOUND_ERR,
NotSupportedError = DOMExceptionConstants::NOT_SUPPORTED_ERR,
InvalidStateError = DOMExceptionConstants::INVALID_STATE_ERR,
SyntaxError = DOMExceptionConstants::SYNTAX_ERR,
InvalidModificationError = DOMExceptionConstants::INVALID_MODIFICATION_ERR,
NamespaceError = DOMExceptionConstants::NAMESPACE_ERR,
InvalidAccessError = DOMExceptionConstants::INVALID_ACCESS_ERR,
SecurityError = DOMExceptionConstants::SECURITY_ERR,
NetworkError = DOMExceptionConstants::NETWORK_ERR,
AbortError = DOMExceptionConstants::ABORT_ERR,
URLMismatchError = DOMExceptionConstants::URL_MISMATCH_ERR,
QuotaExceededError = DOMExceptionConstants::QUOTA_EXCEEDED_ERR,
TimeoutError = DOMExceptionConstants::TIMEOUT_ERR,
InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
EncodingError
}

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::EventBinding;
use dom::bindings::codegen::EventBinding::EventConstants;
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::{Fallible, ErrorResult};
@ -23,10 +24,10 @@ pub enum Event_ {
#[deriving(Encodable)]
pub enum EventPhase {
Phase_None = 0,
Phase_Capturing,
Phase_At_Target,
Phase_Bubbling
Phase_None = EventConstants::NONE,
Phase_Capturing = EventConstants::CAPTURING_PHASE,
Phase_At_Target = EventConstants::AT_TARGET,
Phase_Bubbling = EventConstants::BUBBLING_PHASE,
}
#[deriving(Eq, Encodable)]

View file

@ -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::{CharacterDataCast, NodeBase, NodeDerived};
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
use dom::bindings::codegen::NodeBinding::NodeConstants;
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest};
@ -817,13 +818,13 @@ impl Node {
// http://dom.spec.whatwg.org/#dom-node-nodetype
pub fn NodeType(&self) -> u16 {
match self.type_id {
ElementNodeTypeId(_) => 1,
TextNodeTypeId => 3,
ProcessingInstructionNodeTypeId => 7,
CommentNodeTypeId => 8,
DocumentNodeTypeId => 9,
DoctypeNodeTypeId => 10,
DocumentFragmentNodeTypeId => 11,
ElementNodeTypeId(_) => NodeConstants::ELEMENT_NODE,
TextNodeTypeId => NodeConstants::TEXT_NODE,
ProcessingInstructionNodeTypeId => NodeConstants::PROCESSING_INSTRUCTION_NODE,
CommentNodeTypeId => NodeConstants::COMMENT_NODE,
DocumentNodeTypeId => NodeConstants::DOCUMENT_NODE,
DoctypeNodeTypeId => NodeConstants::DOCUMENT_TYPE_NODE,
DocumentFragmentNodeTypeId => NodeConstants::DOCUMENT_FRAGMENT_NODE,
}
}
@ -1659,45 +1660,50 @@ impl Node {
}
// http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
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 {
// step 2.
0
} else {
let mut lastself = abstract_self.clone();
let mut lastother = other.clone();
for ancestor in abstract_self.ancestors() {
if &ancestor == other {
return DOCUMENT_POSITION_CONTAINS + DOCUMENT_POSITION_PRECEDING;
// step 4.
return NodeConstants::DOCUMENT_POSITION_CONTAINS +
NodeConstants::DOCUMENT_POSITION_PRECEDING;
}
lastself = ancestor;
}
for ancestor in other.ancestors() {
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;
}
if lastself != lastother {
let random = if ptr::to_unsafe_ptr(abstract_self.get()) < ptr::to_unsafe_ptr(other.get()) {
DOCUMENT_POSITION_FOLLOWING
NodeConstants::DOCUMENT_POSITION_FOLLOWING
} 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() {
if &child == other {
return DOCUMENT_POSITION_PRECEDING;
// step 6.
return NodeConstants::DOCUMENT_POSITION_PRECEDING;
}
if &child == abstract_self {
return DOCUMENT_POSITION_FOLLOWING;
// step 7.
return NodeConstants::DOCUMENT_POSITION_FOLLOWING;
}
}
unreachable!()