mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #13100 - nox:better-getters, r=Ms2ger
Use Option<T> to return from getters <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13100) <!-- Reviewable:end -->
This commit is contained in:
commit
3649a356c8
32 changed files with 164 additions and 154 deletions
|
@ -18,6 +18,7 @@ from WebIDL import (
|
||||||
BuiltinTypes,
|
BuiltinTypes,
|
||||||
IDLBuiltinType,
|
IDLBuiltinType,
|
||||||
IDLNullValue,
|
IDLNullValue,
|
||||||
|
IDLNullableType,
|
||||||
IDLType,
|
IDLType,
|
||||||
IDLInterfaceMember,
|
IDLInterfaceMember,
|
||||||
IDLUndefinedValue,
|
IDLUndefinedValue,
|
||||||
|
@ -1349,7 +1350,10 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
|
||||||
if returnType.isAny():
|
if returnType.isAny():
|
||||||
return CGGeneric("JSVal")
|
return CGGeneric("JSVal")
|
||||||
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
||||||
return CGGeneric("*mut JSObject")
|
result = CGGeneric("NonZero<*mut JSObject>")
|
||||||
|
if returnType.nullable():
|
||||||
|
result = CGWrapper(result, pre="Option<", post=">")
|
||||||
|
return result
|
||||||
if returnType.isSequence():
|
if returnType.isSequence():
|
||||||
result = getRetvalDeclarationForType(innerSequenceType(returnType), descriptorProvider)
|
result = getRetvalDeclarationForType(innerSequenceType(returnType), descriptorProvider)
|
||||||
result = CGWrapper(result, pre="Vec<", post=">")
|
result = CGWrapper(result, pre="Vec<", post=">")
|
||||||
|
@ -4552,6 +4556,8 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
||||||
signature = operation.signatures()[0]
|
signature = operation.signatures()[0]
|
||||||
|
|
||||||
(returnType, arguments) = signature
|
(returnType, arguments) = signature
|
||||||
|
if operation.isGetter() and not returnType.nullable():
|
||||||
|
returnType = IDLNullableType(returnType.location, returnType)
|
||||||
|
|
||||||
# We pass len(arguments) as the final argument so that the
|
# We pass len(arguments) as the final argument so that the
|
||||||
# CGPerSignatureCall won't do any argument conversion of its own.
|
# CGPerSignatureCall won't do any argument conversion of its own.
|
||||||
|
@ -4574,8 +4580,6 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
||||||
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(
|
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(
|
||||||
template, templateValues, declType, argument.identifier.name))
|
template, templateValues, declType, argument.identifier.name))
|
||||||
self.cgRoot.prepend(CGGeneric("rooted!(in(cx) let value = desc.value);"))
|
self.cgRoot.prepend(CGGeneric("rooted!(in(cx) let value = desc.value);"))
|
||||||
elif operation.isGetter():
|
|
||||||
self.cgRoot.prepend(CGGeneric("let mut found = false;"))
|
|
||||||
|
|
||||||
def getArguments(self):
|
def getArguments(self):
|
||||||
def process(arg):
|
def process(arg):
|
||||||
|
@ -4584,10 +4588,6 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
||||||
argVal += ".r()"
|
argVal += ".r()"
|
||||||
return argVal
|
return argVal
|
||||||
args = [(a, process(a)) for a in self.arguments]
|
args = [(a, process(a)) for a in self.arguments]
|
||||||
if self.idlNode.isGetter():
|
|
||||||
args.append((FakeArgument(BuiltinTypes[IDLBuiltinType.Types.boolean],
|
|
||||||
self.idlNode),
|
|
||||||
"&mut found"))
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def wrap_return_value(self):
|
def wrap_return_value(self):
|
||||||
|
@ -4595,7 +4595,7 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
wrap = CGGeneric(wrapForType(**self.templateValues))
|
wrap = CGGeneric(wrapForType(**self.templateValues))
|
||||||
wrap = CGIfWrapper("found", wrap)
|
wrap = CGIfWrapper("let Some(result) = result", wrap)
|
||||||
return "\n" + wrap.define()
|
return "\n" + wrap.define()
|
||||||
|
|
||||||
|
|
||||||
|
@ -4971,7 +4971,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
" let this = &*this;\n" +
|
" let this = &*this;\n" +
|
||||||
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
|
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
|
||||||
" *bp = found;\n" +
|
" *bp = result.is_some();\n" +
|
||||||
" return true;\n" +
|
" return true;\n" +
|
||||||
"}\n\n")
|
"}\n\n")
|
||||||
else:
|
else:
|
||||||
|
@ -4987,7 +4987,7 @@ if RUST_JSID_IS_STRING(id) {
|
||||||
}
|
}
|
||||||
if !has_on_proto {
|
if !has_on_proto {
|
||||||
%s
|
%s
|
||||||
*bp = found;
|
*bp = result.is_some();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5271,7 +5271,9 @@ class CGInterfaceTrait(CGThing):
|
||||||
|
|
||||||
infallible = 'infallible' in descriptor.getExtendedAttributes(operation)
|
infallible = 'infallible' in descriptor.getExtendedAttributes(operation)
|
||||||
if operation.isGetter():
|
if operation.isGetter():
|
||||||
arguments = method_arguments(descriptor, rettype, arguments, trailing=("found", "&mut bool"))
|
if not rettype.nullable():
|
||||||
|
rettype = IDLNullableType(rettype.location, rettype)
|
||||||
|
arguments = method_arguments(descriptor, rettype, arguments)
|
||||||
|
|
||||||
# If this interface 'supports named properties', then we
|
# If this interface 'supports named properties', then we
|
||||||
# should be able to access 'supported property names'
|
# should be able to access 'supported property names'
|
||||||
|
@ -5323,6 +5325,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
||||||
enums = []
|
enums = []
|
||||||
|
|
||||||
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, [
|
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, [
|
||||||
|
'core::nonzero::NonZero',
|
||||||
'js',
|
'js',
|
||||||
'js::JSCLASS_GLOBAL_SLOT_COUNT',
|
'js::JSCLASS_GLOBAL_SLOT_COUNT',
|
||||||
'js::JSCLASS_IS_DOMJSCLASS',
|
'js::JSCLASS_IS_DOMJSCLASS',
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
//! Implementation of `iterable<...>` and `iterable<..., ...>` WebIDL declarations.
|
//! Implementation of `iterable<...>` and `iterable<..., ...>` WebIDL declarations.
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndValueResult;
|
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndValueResult;
|
||||||
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult;
|
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
|
@ -95,38 +96,41 @@ impl<T: Reflectable + JSTraceable + Iterable> IterableIterator<T> {
|
||||||
|
|
||||||
/// Return the next value from the iterable object.
|
/// Return the next value from the iterable object.
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn Next(&self, cx: *mut JSContext) -> Fallible<*mut JSObject> {
|
pub fn Next(&self, cx: *mut JSContext) -> Fallible<NonZero<*mut JSObject>> {
|
||||||
let index = self.index.get();
|
let index = self.index.get();
|
||||||
rooted!(in(cx) let mut value = UndefinedValue());
|
rooted!(in(cx) let mut value = UndefinedValue());
|
||||||
rooted!(in(cx) let mut rval = ptr::null_mut());
|
rooted!(in(cx) let mut rval = ptr::null_mut());
|
||||||
if index >= self.iterable.get_iterable_length() {
|
let result = if index >= self.iterable.get_iterable_length() {
|
||||||
return dict_return(cx, rval.handle_mut(), true, value.handle())
|
dict_return(cx, rval.handle_mut(), true, value.handle())
|
||||||
.map(|_| rval.handle().get());
|
} else {
|
||||||
}
|
match self.type_ {
|
||||||
let result = match self.type_ {
|
IteratorType::Keys => {
|
||||||
IteratorType::Keys => {
|
unsafe {
|
||||||
unsafe {
|
self.iterable.get_key_at_index(index).to_jsval(cx, value.handle_mut());
|
||||||
self.iterable.get_key_at_index(index).to_jsval(cx, value.handle_mut());
|
}
|
||||||
|
dict_return(cx, rval.handle_mut(), false, value.handle())
|
||||||
}
|
}
|
||||||
dict_return(cx, rval.handle_mut(), false, value.handle())
|
IteratorType::Values => {
|
||||||
}
|
unsafe {
|
||||||
IteratorType::Values => {
|
self.iterable.get_value_at_index(index).to_jsval(cx, value.handle_mut());
|
||||||
unsafe {
|
}
|
||||||
self.iterable.get_value_at_index(index).to_jsval(cx, value.handle_mut());
|
dict_return(cx, rval.handle_mut(), false, value.handle())
|
||||||
}
|
}
|
||||||
dict_return(cx, rval.handle_mut(), false, value.handle())
|
IteratorType::Entries => {
|
||||||
}
|
rooted!(in(cx) let mut key = UndefinedValue());
|
||||||
IteratorType::Entries => {
|
unsafe {
|
||||||
rooted!(in(cx) let mut key = UndefinedValue());
|
self.iterable.get_key_at_index(index).to_jsval(cx, key.handle_mut());
|
||||||
unsafe {
|
self.iterable.get_value_at_index(index).to_jsval(cx, value.handle_mut());
|
||||||
self.iterable.get_key_at_index(index).to_jsval(cx, key.handle_mut());
|
}
|
||||||
self.iterable.get_value_at_index(index).to_jsval(cx, value.handle_mut());
|
key_and_value_return(cx, rval.handle_mut(), key.handle(), value.handle())
|
||||||
}
|
}
|
||||||
key_and_value_return(cx, rval.handle_mut(), key.handle(), value.handle())
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.index.set(index + 1);
|
self.index.set(index + 1);
|
||||||
result.map(|_| rval.handle().get())
|
result.map(|_| {
|
||||||
|
assert!(!rval.is_null());
|
||||||
|
unsafe { NonZero::new(rval.get()) }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1100,7 +1100,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
dirtyY: Finite<f64>,
|
dirtyY: Finite<f64>,
|
||||||
dirtyWidth: Finite<f64>,
|
dirtyWidth: Finite<f64>,
|
||||||
dirtyHeight: Finite<f64>) {
|
dirtyHeight: Finite<f64>) {
|
||||||
let data = imagedata.get_data_array(&self.global().r());
|
let data = imagedata.get_data_array();
|
||||||
let offset = Point2D::new(*dx, *dy);
|
let offset = Point2D::new(*dx, *dy);
|
||||||
let image_data_size = Size2D::new(imagedata.Width() as f64, imagedata.Height() as f64);
|
let image_data_size = Size2D::new(imagedata.Width() as f64, imagedata.Height() as f64);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::CryptoBinding;
|
use dom::bindings::codegen::Bindings::CryptoBinding;
|
||||||
use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
|
use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
|
||||||
|
@ -43,7 +44,8 @@ impl CryptoMethods for Crypto {
|
||||||
fn GetRandomValues(&self,
|
fn GetRandomValues(&self,
|
||||||
_cx: *mut JSContext,
|
_cx: *mut JSContext,
|
||||||
input: *mut JSObject)
|
input: *mut JSObject)
|
||||||
-> Fallible<*mut JSObject> {
|
-> Fallible<NonZero<*mut JSObject>> {
|
||||||
|
assert!(!input.is_null());
|
||||||
let mut data = match unsafe { array_buffer_view_data::<u8>(input) } {
|
let mut data = match unsafe { array_buffer_view_data::<u8>(input) } {
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => {
|
None => {
|
||||||
|
@ -62,7 +64,7 @@ impl CryptoMethods for Crypto {
|
||||||
|
|
||||||
self.rng.borrow_mut().fill_bytes(&mut data);
|
self.rng.borrow_mut().fill_bytes(&mut data);
|
||||||
|
|
||||||
Ok(input)
|
Ok(unsafe { NonZero::new(input) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,18 +100,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-item
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-item
|
||||||
fn Item(&self, index: u32) -> DOMString {
|
fn Item(&self, index: u32) -> DOMString {
|
||||||
let index = index as usize;
|
self.IndexedGetter(index).unwrap_or_default()
|
||||||
let elem = self.owner.upcast::<Element>();
|
|
||||||
let style_attribute = elem.style_attribute().borrow();
|
|
||||||
style_attribute.as_ref().and_then(|declarations| {
|
|
||||||
declarations.declarations.get(index)
|
|
||||||
}).map(|&(ref declaration, importance)| {
|
|
||||||
let mut css = declaration.to_css_string();
|
|
||||||
if importance.important() {
|
|
||||||
css += " !important";
|
|
||||||
}
|
|
||||||
DOMString::from(css)
|
|
||||||
}).unwrap_or_else(DOMString::new)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||||
|
@ -333,10 +322,19 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
|
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> DOMString {
|
fn IndexedGetter(&self, index: u32) -> Option<DOMString> {
|
||||||
let rval = self.Item(index);
|
let index = index as usize;
|
||||||
*found = index < self.Length();
|
let elem = self.owner.upcast::<Element>();
|
||||||
rval
|
let style_attribute = elem.style_attribute().borrow();
|
||||||
|
style_attribute.as_ref().and_then(|declarations| {
|
||||||
|
declarations.declarations.get(index)
|
||||||
|
}).map(|&(ref declaration, importance)| {
|
||||||
|
let mut css = declaration.to_css_string();
|
||||||
|
if importance.important() {
|
||||||
|
css += " !important";
|
||||||
|
}
|
||||||
|
DOMString::from(css)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use document_loader::{DocumentLoader, LoadType};
|
use document_loader::{DocumentLoader, LoadType};
|
||||||
use dom::activation::{ActivationSource, synthetic_click_activation};
|
use dom::activation::{ActivationSource, synthetic_click_activation};
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
|
@ -116,7 +117,6 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use string_cache::{Atom, QualName};
|
use string_cache::{Atom, QualName};
|
||||||
|
@ -2710,8 +2710,9 @@ impl DocumentMethods for Document {
|
||||||
self.set_body_attribute(&atom!("text"), value)
|
self.set_body_attribute(&atom!("text"), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
||||||
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString, found: &mut bool) -> *mut JSObject {
|
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
||||||
#[derive(JSTraceable, HeapSizeOf)]
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
struct NamedElementFilter {
|
struct NamedElementFilter {
|
||||||
name: Atom,
|
name: Atom,
|
||||||
|
@ -2777,23 +2778,24 @@ impl DocumentMethods for Document {
|
||||||
.peekable();
|
.peekable();
|
||||||
if let Some(first) = elements.next() {
|
if let Some(first) = elements.next() {
|
||||||
if elements.peek().is_none() {
|
if elements.peek().is_none() {
|
||||||
*found = true;
|
|
||||||
// TODO: Step 2.
|
// TODO: Step 2.
|
||||||
// Step 3.
|
// Step 3.
|
||||||
return first.reflector().get_jsobject().get();
|
return unsafe {
|
||||||
|
Some(NonZero::new(first.reflector().get_jsobject().get()))
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*found = false;
|
return None;
|
||||||
return ptr::null_mut();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Step 4.
|
// Step 4.
|
||||||
*found = true;
|
|
||||||
let filter = NamedElementFilter {
|
let filter = NamedElementFilter {
|
||||||
name: name,
|
name: name,
|
||||||
};
|
};
|
||||||
let collection = HTMLCollection::create(self.window(), root, box filter);
|
let collection = HTMLCollection::create(self.window(), root, box filter);
|
||||||
collection.reflector().get_jsobject().get()
|
unsafe {
|
||||||
|
Some(NonZero::new(collection.reflector().get_jsobject().get()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
||||||
|
|
|
@ -52,8 +52,7 @@ impl DOMRectListMethods for DOMRectList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<DOMRect>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<DOMRect>> {
|
||||||
*found = index < self.rects.len() as u32;
|
|
||||||
self.Item(index)
|
self.Item(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,8 @@ impl DOMStringMapMethods for DOMStringMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-domstringmap-nameditem
|
// https://html.spec.whatwg.org/multipage/#dom-domstringmap-nameditem
|
||||||
fn NamedGetter(&self, name: DOMString, found: &mut bool) -> DOMString {
|
fn NamedGetter(&self, name: DOMString) -> Option<DOMString> {
|
||||||
let attr = self.element.get_custom_attr(name);
|
self.element.get_custom_attr(name)
|
||||||
*found = attr.is_some();
|
|
||||||
attr.unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#the-domstringmap-interface:supported-property-names
|
// https://html.spec.whatwg.org/multipage/#the-domstringmap-interface:supported-property-names
|
||||||
|
|
|
@ -171,9 +171,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<DOMString> {
|
fn IndexedGetter(&self, index: u32) -> Option<DOMString> {
|
||||||
let item = self.Item(index);
|
self.Item(index)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,7 @@ impl FileListMethods for FileList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<File>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<File>> {
|
||||||
let item = self.Item(index);
|
self.Item(index)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,11 +273,10 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let raw_data = match *self.context.borrow() {
|
let raw_data = match *self.context.borrow() {
|
||||||
Some(CanvasContext::Context2d(ref context)) => {
|
Some(CanvasContext::Context2d(ref context)) => {
|
||||||
let window = window_from_node(self);
|
|
||||||
let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64),
|
let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64),
|
||||||
Finite::wrap(self.Width() as f64),
|
Finite::wrap(self.Width() as f64),
|
||||||
Finite::wrap(self.Height() as f64)));
|
Finite::wrap(self.Height() as f64)));
|
||||||
image_data.get_data_array(&GlobalRef::Window(window.r()))
|
image_data.get_data_array()
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Each pixel is fully-transparent black.
|
// Each pixel is fully-transparent black.
|
||||||
|
|
|
@ -317,17 +317,13 @@ impl HTMLCollectionMethods for HTMLCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Element>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Element>> {
|
||||||
let maybe_elem = self.Item(index);
|
self.Item(index)
|
||||||
*found = maybe_elem.is_some();
|
|
||||||
maybe_elem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<Root<Element>> {
|
fn NamedGetter(&self, name: DOMString) -> Option<Root<Element>> {
|
||||||
let maybe_elem = self.NamedItem(name);
|
self.NamedItem(name)
|
||||||
*found = maybe_elem.is_some();
|
|
||||||
maybe_elem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#interface-htmlcollection
|
// https://dom.spec.whatwg.org/#interface-htmlcollection
|
||||||
|
|
|
@ -77,10 +77,8 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-htmlformcontrolscollection-nameditem
|
// https://html.spec.whatwg.org/multipage/#dom-htmlformcontrolscollection-nameditem
|
||||||
fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<RadioNodeListOrElement> {
|
fn NamedGetter(&self, name: DOMString) -> Option<RadioNodeListOrElement> {
|
||||||
let maybe_elem = self.NamedItem(name);
|
self.NamedItem(name)
|
||||||
*found = maybe_elem.is_some();
|
|
||||||
maybe_elem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#the-htmlformcontrolscollection-interface:supported-property-names
|
// https://html.spec.whatwg.org/multipage/#the-htmlformcontrolscollection-interface:supported-property-names
|
||||||
|
@ -93,7 +91,7 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
|
||||||
// https://github.com/servo/servo/issues/5875
|
// https://github.com/servo/servo/issues/5875
|
||||||
//
|
//
|
||||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Element>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Element>> {
|
||||||
self.collection.IndexedGetter(index, found)
|
self.collection.IndexedGetter(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,9 +230,9 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-form-item
|
// https://html.spec.whatwg.org/multipage/#dom-form-item
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Element>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Element>> {
|
||||||
let elements = self.Elements();
|
let elements = self.Elements();
|
||||||
elements.IndexedGetter(index, found)
|
elements.IndexedGetter(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use dom::bindings::codegen::Bindings::ImageDataBinding;
|
use dom::bindings::codegen::Bindings::ImageDataBinding;
|
||||||
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
|
@ -37,6 +38,7 @@ impl ImageData {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cx = global.get_cx();
|
let cx = global.get_cx();
|
||||||
let js_object: *mut JSObject = JS_NewUint8ClampedArray(cx, width * height * 4);
|
let js_object: *mut JSObject = JS_NewUint8ClampedArray(cx, width * height * 4);
|
||||||
|
assert!(!js_object.is_null());
|
||||||
|
|
||||||
if let Some(vec) = data {
|
if let Some(vec) = data {
|
||||||
let mut is_shared = false;
|
let mut is_shared = false;
|
||||||
|
@ -52,12 +54,13 @@ impl ImageData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn get_data_array(&self, global: &GlobalRef) -> Vec<u8> {
|
pub fn get_data_array(&self) -> Vec<u8> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cx = global.get_cx();
|
|
||||||
let mut is_shared = false;
|
let mut is_shared = false;
|
||||||
|
assert!(!self.data.get().is_null());
|
||||||
let data: *const uint8_t =
|
let data: *const uint8_t =
|
||||||
JS_GetUint8ClampedArrayData(self.Data(cx), &mut is_shared, ptr::null()) as *const uint8_t;
|
JS_GetUint8ClampedArrayData(self.data.get(), &mut is_shared, ptr::null()) as *const uint8_t;
|
||||||
|
assert!(!data.is_null());
|
||||||
assert!(!is_shared);
|
assert!(!is_shared);
|
||||||
let len = self.Width() * self.Height() * 4;
|
let len = self.Width() * self.Height() * 4;
|
||||||
slice::from_raw_parts(data, len as usize).to_vec()
|
slice::from_raw_parts(data, len as usize).to_vec()
|
||||||
|
@ -80,8 +83,10 @@ impl ImageDataMethods for ImageData {
|
||||||
self.height
|
self.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
|
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
|
||||||
fn Data(&self, _: *mut JSContext) -> *mut JSObject {
|
fn Data(&self, _: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
self.data.get()
|
assert!(!self.data.get().is_null());
|
||||||
|
unsafe { NonZero::new(self.data.get()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,12 @@ impl MimeTypeArrayMethods for MimeTypeArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-mimetypearray-item
|
// https://html.spec.whatwg.org/multipage/#dom-mimetypearray-item
|
||||||
fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Root<MimeType>> {
|
fn IndexedGetter(&self, _index: u32) -> Option<Root<MimeType>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn NamedGetter(&self, _name: DOMString, _found: &mut bool) -> Option<Root<MimeType>> {
|
fn NamedGetter(&self, _name: DOMString) -> Option<Root<MimeType>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,17 +85,13 @@ impl NamedNodeMapMethods for NamedNodeMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Attr>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Attr>> {
|
||||||
let item = self.Item(index);
|
self.Item(index)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<Root<Attr>> {
|
fn NamedGetter(&self, name: DOMString) -> Option<Root<Attr>> {
|
||||||
let item = self.GetNamedItem(name);
|
self.GetNamedItem(name)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://heycam.github.io/webidl/#dfn-supported-property-names
|
// https://heycam.github.io/webidl/#dfn-supported-property-names
|
||||||
|
|
|
@ -75,10 +75,8 @@ impl NodeListMethods for NodeList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nodelist-item
|
// https://dom.spec.whatwg.org/#dom-nodelist-item
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Node>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Node>> {
|
||||||
let item = self.Item(index);
|
self.Item(index)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,12 @@ impl PluginMethods for Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-plugin-item
|
// https://html.spec.whatwg.org/multipage/#dom-plugin-item
|
||||||
fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Root<MimeType>> {
|
fn IndexedGetter(&self, _index: u32) -> Option<Root<MimeType>> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn NamedGetter(&self, _name: DOMString, _found: &mut bool) -> Option<Root<MimeType>> {
|
fn NamedGetter(&self, _name: DOMString) -> Option<Root<MimeType>> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,12 +50,12 @@ impl PluginArrayMethods for PluginArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-pluginarray-item
|
// https://html.spec.whatwg.org/multipage/#dom-pluginarray-item
|
||||||
fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Root<Plugin>> {
|
fn IndexedGetter(&self, _index: u32) -> Option<Root<Plugin>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn NamedGetter(&self, _name: DOMString, _found: &mut bool) -> Option<Root<Plugin>> {
|
fn NamedGetter(&self, _name: DOMString) -> Option<Root<Plugin>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl RadioNodeListMethods for RadioNodeList {
|
||||||
// https://github.com/servo/servo/issues/5875
|
// https://github.com/servo/servo/issues/5875
|
||||||
//
|
//
|
||||||
// https://dom.spec.whatwg.org/#dom-nodelist-item
|
// https://dom.spec.whatwg.org/#dom-nodelist-item
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Node>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Node>> {
|
||||||
self.node_list.IndexedGetter(index, found)
|
self.node_list.IndexedGetter(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,10 +136,8 @@ impl StorageMethods for Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<DOMString> {
|
fn NamedGetter(&self, name: DOMString) -> Option<DOMString> {
|
||||||
let item = self.GetItem(name);
|
self.GetItem(name)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn NamedSetter(&self, name: DOMString, value: DOMString) -> ErrorResult {
|
fn NamedSetter(&self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||||
|
|
|
@ -46,9 +46,7 @@ impl StyleSheetListMethods for StyleSheetList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<StyleSheet>>{
|
fn IndexedGetter(&self, index: u32) -> Option<Root<StyleSheet>> {
|
||||||
let item = self.Item(index);
|
self.Item(index)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
|
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
|
||||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use dom::bindings::codegen::Bindings::TestBindingBinding;
|
use dom::bindings::codegen::Bindings::TestBindingBinding;
|
||||||
|
@ -26,6 +27,7 @@ use dom::bindings::weakref::MutableWeakRef;
|
||||||
use dom::blob::{Blob, BlobImpl};
|
use dom::blob::{Blob, BlobImpl};
|
||||||
use dom::url::URL;
|
use dom::url::URL;
|
||||||
use js::jsapi::{HandleObject, HandleValue, JSContext, JSObject};
|
use js::jsapi::{HandleObject, HandleValue, JSContext, JSObject};
|
||||||
|
use js::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray};
|
||||||
use js::jsval::{JSVal, NullValue};
|
use js::jsval::{JSVal, NullValue};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -137,10 +139,24 @@ impl TestBindingMethods for TestBinding {
|
||||||
ByteStringOrLong::ByteString(ByteString::new(vec!()))
|
ByteStringOrLong::ByteString(ByteString::new(vec!()))
|
||||||
}
|
}
|
||||||
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
||||||
fn ArrayAttribute(&self, _: *mut JSContext) -> *mut JSObject { NullValue().to_object_or_null() }
|
#[allow(unsafe_code)]
|
||||||
|
fn ArrayAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
|
unsafe {
|
||||||
|
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
||||||
|
assert!(!array.is_null());
|
||||||
|
NonZero::new(array.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
|
fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
|
||||||
fn ObjectAttribute(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
#[allow(unsafe_code)]
|
||||||
|
fn ObjectAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
|
unsafe {
|
||||||
|
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
||||||
|
assert!(!obj.is_null());
|
||||||
|
NonZero::new(obj.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
|
|
||||||
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
||||||
|
@ -193,7 +209,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
|
fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
|
||||||
self.url.set(url);
|
self.url.set(url);
|
||||||
}
|
}
|
||||||
fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
|
fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonZero<*mut JSObject>> { None }
|
||||||
fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
|
fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
|
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
|
||||||
Some(HTMLElementOrLong::Long(0))
|
Some(HTMLElementOrLong::Long(0))
|
||||||
|
@ -242,7 +258,9 @@ impl TestBindingMethods for TestBinding {
|
||||||
Blob::new(self.global().r(), BlobImpl::new_from_bytes(vec![]), "".to_owned())
|
Blob::new(self.global().r(), BlobImpl::new_from_bytes(vec![]), "".to_owned())
|
||||||
}
|
}
|
||||||
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
fn ReceiveObject(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
fn ReceiveObject(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
|
self.ObjectAttribute(cx)
|
||||||
|
}
|
||||||
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) }
|
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) }
|
||||||
fn ReceiveUnion2(&self) -> EventOrString { EventOrString::String(DOMString::new()) }
|
fn ReceiveUnion2(&self) -> EventOrString { EventOrString::String(DOMString::new()) }
|
||||||
fn ReceiveUnion3(&self) -> StringOrLongSequence { StringOrLongSequence::LongSequence(vec![]) }
|
fn ReceiveUnion3(&self) -> StringOrLongSequence { StringOrLongSequence::LongSequence(vec![]) }
|
||||||
|
@ -283,7 +301,9 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> {
|
fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> {
|
||||||
Some(Blob::new(self.global().r(), BlobImpl::new_from_bytes(vec![]), "".to_owned()))
|
Some(Blob::new(self.global().r(), BlobImpl::new_from_bytes(vec![]), "".to_owned()))
|
||||||
}
|
}
|
||||||
fn ReceiveNullableObject(&self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
|
fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonZero<*mut JSObject>> {
|
||||||
|
self.GetObjectAttributeNullable(cx)
|
||||||
|
}
|
||||||
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
|
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
|
||||||
Some(HTMLElementOrLong::Long(0))
|
Some(HTMLElementOrLong::Long(0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,8 @@ impl TestBindingIterable {
|
||||||
impl TestBindingIterableMethods for TestBindingIterable {
|
impl TestBindingIterableMethods for TestBindingIterable {
|
||||||
fn Add(&self, v: DOMString) { self.vals.borrow_mut().push(v); }
|
fn Add(&self, v: DOMString) { self.vals.borrow_mut().push(v); }
|
||||||
fn Length(&self) -> u32 { self.vals.borrow().len() as u32 }
|
fn Length(&self) -> u32 { self.vals.borrow().len() as u32 }
|
||||||
fn GetItem(&self, n: u32) -> DOMString { self.vals.borrow().get(n as usize).unwrap().clone() }
|
fn GetItem(&self, n: u32) -> DOMString { self.IndexedGetter(n).unwrap_or_default() }
|
||||||
fn IndexedGetter(&self, n: u32, found: &mut bool) -> DOMString {
|
fn IndexedGetter(&self, n: u32) -> Option<DOMString> {
|
||||||
let s = self.GetItem(n);
|
self.vals.borrow().get(n as usize).cloned()
|
||||||
*found = true;
|
|
||||||
s
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ impl TestBindingProxyMethods for TestBindingProxy {
|
||||||
fn SetItem(&self, _: u32, _: DOMString) -> () {}
|
fn SetItem(&self, _: u32, _: DOMString) -> () {}
|
||||||
fn RemoveItem(&self, _: DOMString) -> () {}
|
fn RemoveItem(&self, _: DOMString) -> () {}
|
||||||
fn Stringifier(&self) -> DOMString { DOMString::new() }
|
fn Stringifier(&self) -> DOMString { DOMString::new() }
|
||||||
fn IndexedGetter(&self, _: u32, _: &mut bool) -> DOMString { DOMString::new() }
|
fn IndexedGetter(&self, _: u32) -> Option<DOMString> { None }
|
||||||
fn NamedDeleter(&self, _: DOMString) -> () {}
|
fn NamedDeleter(&self, _: DOMString) -> () {}
|
||||||
fn IndexedSetter(&self, _: u32, _: DOMString) -> () {}
|
fn IndexedSetter(&self, _: u32, _: DOMString) -> () {}
|
||||||
fn NamedSetter(&self, _: DOMString, _: DOMString) -> () {}
|
fn NamedSetter(&self, _: DOMString, _: DOMString) -> () {}
|
||||||
fn NamedGetter(&self, _: DOMString, _: &mut bool) -> DOMString { DOMString::new() }
|
fn NamedGetter(&self, _: DOMString) -> Option<DOMString> { None }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use dom::bindings::codegen::Bindings::TextEncoderBinding;
|
use dom::bindings::codegen::Bindings::TextEncoderBinding;
|
||||||
use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods;
|
use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods;
|
||||||
use dom::bindings::error::{Error, Fallible};
|
use dom::bindings::error::{Error, Fallible};
|
||||||
|
@ -70,16 +71,17 @@ impl TextEncoderMethods for TextEncoder {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
|
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
|
||||||
fn Encode(&self, cx: *mut JSContext, input: USVString) -> *mut JSObject {
|
fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonZero<*mut JSObject> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let encoded = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
|
let encoded = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
|
||||||
let length = encoded.len() as u32;
|
let length = encoded.len() as u32;
|
||||||
let js_object: *mut JSObject = JS_NewUint8Array(cx, length);
|
rooted!(in(cx) let js_object = JS_NewUint8Array(cx, length));
|
||||||
|
assert!(!js_object.is_null());
|
||||||
let mut is_shared = false;
|
let mut is_shared = false;
|
||||||
let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, &mut is_shared, ptr::null());
|
let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object.get(), &mut is_shared, ptr::null());
|
||||||
assert!(!is_shared);
|
assert!(!is_shared);
|
||||||
ptr::copy_nonoverlapping(encoded.as_ptr(), js_object_data, length as usize);
|
ptr::copy_nonoverlapping(encoded.as_ptr(), js_object_data, length as usize);
|
||||||
js_object
|
NonZero::new(js_object.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,7 @@ impl TouchListMethods for TouchList {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index
|
/// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Touch>> {
|
fn IndexedGetter(&self, index: u32) -> Option<Root<Touch>> {
|
||||||
let item = self.Item(index);
|
self.Item(index)
|
||||||
*found = item.is_some();
|
|
||||||
item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 canvas_traits::{CanvasCommonMsg, CanvasMsg, byte_swap};
|
use canvas_traits::{CanvasCommonMsg, CanvasMsg, byte_swap};
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
||||||
|
@ -305,8 +306,7 @@ impl WebGLRenderingContext {
|
||||||
// complexity is worth it.
|
// complexity is worth it.
|
||||||
let (pixels, size) = match source {
|
let (pixels, size) = match source {
|
||||||
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement::ImageData(image_data) => {
|
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement::ImageData(image_data) => {
|
||||||
let global = self.global();
|
(image_data.get_data_array(), image_data.get_size())
|
||||||
(image_data.get_data_array(&global.r()), image_data.get_size())
|
|
||||||
},
|
},
|
||||||
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement::HTMLImageElement(image) => {
|
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement::HTMLImageElement(image) => {
|
||||||
let img_url = match image.get_url() {
|
let img_url = match image.get_url() {
|
||||||
|
@ -632,8 +632,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
|
||||||
fn GetExtension(&self, _cx: *mut JSContext, _name: DOMString) -> *mut JSObject {
|
fn GetExtension(&self, _cx: *mut JSContext, _name: DOMString)
|
||||||
0 as *mut JSObject
|
-> Option<NonZero<*mut JSObject>> {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use core::nonzero::NonZero;
|
||||||
use document_loader::DocumentLoader;
|
use document_loader::DocumentLoader;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods};
|
use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods};
|
||||||
|
@ -87,7 +88,7 @@ impl XMLDocumentMethods for XMLDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
||||||
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString, found: &mut bool) -> *mut JSObject {
|
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
||||||
self.upcast::<Document>().NamedGetter(_cx, name, found)
|
self.upcast::<Document>().NamedGetter(_cx, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
components/servo/Cargo.lock
generated
2
components/servo/Cargo.lock
generated
|
@ -1086,7 +1086,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js"
|
name = "js"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
source = "git+https://github.com/servo/rust-mozjs#f06428fab33a6ae633584a1a7e1bf4e3ef7914b3"
|
source = "git+https://github.com/servo/rust-mozjs#f5444dd82b864a88cf874c66c75aed478fd88d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -994,7 +994,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js"
|
name = "js"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
source = "git+https://github.com/servo/rust-mozjs#f06428fab33a6ae633584a1a7e1bf4e3ef7914b3"
|
source = "git+https://github.com/servo/rust-mozjs#f5444dd82b864a88cf874c66c75aed478fd88d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue