forked from mirrors/gecko-dev
		
	Servo currently uses `heapsize`, but Stylo/Gecko use `malloc_size_of`. `malloc_size_of` is better -- it handles various cases that `heapsize` does not -- so this patch changes Servo to use `malloc_size_of`. This patch makes the following changes to the `malloc_size_of` crate. - Adds `MallocSizeOf` trait implementations for numerous types, some built-in (e.g. `VecDeque`), some external and Servo-only (e.g. `string_cache`). - Makes `enclosing_size_of_op` optional, because vanilla jemalloc doesn't support that operation. - For `HashSet`/`HashMap`, falls back to a computed estimate when `enclosing_size_of_op` isn't available. - Adds an extern "C" `malloc_size_of` function that does the actual heap measurement; this is based on the same functions from the `heapsize` crate. This patch makes the following changes elsewhere. - Converts all the uses of `heapsize` to instead use `malloc_size_of`. - Disables the "heapsize"/"heap_size" feature for the external crates that provide it. - Removes the `HeapSizeOf` implementation from `hashglobe`. - Adds `ignore` annotations to a few `Rc`/`Arc`, because `malloc_size_of` doesn't derive those types, unlike `heapsize`. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1409255 <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because testing is on the Gecko side. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 4c538b642e4bdfbf42c522c5a59c258a6d14546e --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : f9a6feed1088d0b0be2b55d7f0c2ec9c594ac33b
		
			
				
	
	
		
			106 lines
		
	
	
	
		
			5.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
	
		
			5.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
/* This Source Code Form is subject to the terms of the Mozilla Public
 | 
						|
 * 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/. */
 | 
						|
 | 
						|
use dom::bindings::codegen::Bindings::DOMExceptionBinding;
 | 
						|
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionConstants;
 | 
						|
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionMethods;
 | 
						|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
 | 
						|
use dom::bindings::root::DomRoot;
 | 
						|
use dom::bindings::str::DOMString;
 | 
						|
use dom::globalscope::GlobalScope;
 | 
						|
use dom_struct::dom_struct;
 | 
						|
 | 
						|
#[repr(u16)]
 | 
						|
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf)]
 | 
						|
pub enum DOMErrorName {
 | 
						|
    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,
 | 
						|
    InUseAttributeError = DOMExceptionConstants::INUSE_ATTRIBUTE_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,
 | 
						|
    TypeMismatchError = DOMExceptionConstants::TYPE_MISMATCH_ERR,
 | 
						|
    QuotaExceededError = DOMExceptionConstants::QUOTA_EXCEEDED_ERR,
 | 
						|
    TimeoutError = DOMExceptionConstants::TIMEOUT_ERR,
 | 
						|
    InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
 | 
						|
    DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
 | 
						|
}
 | 
						|
 | 
						|
#[dom_struct]
 | 
						|
pub struct DOMException {
 | 
						|
    reflector_: Reflector,
 | 
						|
    code: DOMErrorName,
 | 
						|
}
 | 
						|
 | 
						|
impl DOMException {
 | 
						|
    fn new_inherited(code: DOMErrorName) -> DOMException {
 | 
						|
        DOMException {
 | 
						|
            reflector_: Reflector::new(),
 | 
						|
            code: code,
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    pub fn new(global: &GlobalScope, code: DOMErrorName) -> DomRoot<DOMException> {
 | 
						|
        reflect_dom_object(Box::new(DOMException::new_inherited(code)),
 | 
						|
                           global,
 | 
						|
                           DOMExceptionBinding::Wrap)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl DOMExceptionMethods for DOMException {
 | 
						|
    // https://heycam.github.io/webidl/#dfn-DOMException
 | 
						|
    fn Code(&self) -> u16 {
 | 
						|
        self.code as u16
 | 
						|
    }
 | 
						|
 | 
						|
    // https://heycam.github.io/webidl/#idl-DOMException-error-names
 | 
						|
    fn Name(&self) -> DOMString {
 | 
						|
        DOMString::from(format!("{:?}", self.code))
 | 
						|
    }
 | 
						|
 | 
						|
    // https://heycam.github.io/webidl/#error-names
 | 
						|
    fn Message(&self) -> DOMString {
 | 
						|
        let message = match self.code {
 | 
						|
            DOMErrorName::IndexSizeError => "The index is not in the allowed range.",
 | 
						|
            DOMErrorName::HierarchyRequestError => "The operation would yield an incorrect node tree.",
 | 
						|
            DOMErrorName::WrongDocumentError => "The object is in the wrong document.",
 | 
						|
            DOMErrorName::InvalidCharacterError => "The string contains invalid characters.",
 | 
						|
            DOMErrorName::NoModificationAllowedError => "The object can not be modified.",
 | 
						|
            DOMErrorName::NotFoundError => "The object can not be found here.",
 | 
						|
            DOMErrorName::NotSupportedError => "The operation is not supported.",
 | 
						|
            DOMErrorName::InUseAttributeError => "The attribute already in use.",
 | 
						|
            DOMErrorName::InvalidStateError => "The object is in an invalid state.",
 | 
						|
            DOMErrorName::SyntaxError => "The string did not match the expected pattern.",
 | 
						|
            DOMErrorName::InvalidModificationError => "The object can not be modified in this way.",
 | 
						|
            DOMErrorName::NamespaceError => "The operation is not allowed by Namespaces in XML.",
 | 
						|
            DOMErrorName::InvalidAccessError => "The object does not support the operation or argument.",
 | 
						|
            DOMErrorName::SecurityError => "The operation is insecure.",
 | 
						|
            DOMErrorName::NetworkError => "A network error occurred.",
 | 
						|
            DOMErrorName::AbortError => "The operation was aborted.",
 | 
						|
            DOMErrorName::TypeMismatchError => "The given type does not match any expected type.",
 | 
						|
            DOMErrorName::QuotaExceededError => "The quota has been exceeded.",
 | 
						|
            DOMErrorName::TimeoutError => "The operation timed out.",
 | 
						|
            DOMErrorName::InvalidNodeTypeError =>
 | 
						|
                "The supplied node is incorrect or has an incorrect ancestor for this operation.",
 | 
						|
            DOMErrorName::DataCloneError => "The object can not be cloned.",
 | 
						|
        };
 | 
						|
 | 
						|
        DOMString::from(message)
 | 
						|
    }
 | 
						|
 | 
						|
    // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.tostring
 | 
						|
    fn Stringifier(&self) -> DOMString {
 | 
						|
        DOMString::from(format!("{}: {}", self.Name(), self.Message()))
 | 
						|
    }
 | 
						|
}
 |