mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Rustfmt some of script.
This commit is contained in:
parent
ceb72e54e4
commit
0c61be7a57
50 changed files with 1499 additions and 885 deletions
|
@ -8,9 +8,9 @@ use dom::bindings::error::{Error, Fallible};
|
|||
use dom::bindings::global::global_root_from_object;
|
||||
use dom::bindings::reflector::Reflectable;
|
||||
use js::jsapi::GetGlobalForObjectCrossCompartment;
|
||||
use js::jsapi::JSAutoCompartment;
|
||||
use js::jsapi::{Heap, MutableHandleObject, RootedObject, RootedValue};
|
||||
use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject};
|
||||
use js::jsapi::{JSAutoCompartment};
|
||||
use js::jsapi::{JSCompartment, JS_EnterCompartment, JS_LeaveCompartment};
|
||||
use js::jsapi::{JS_BeginRequest, JS_EndRequest};
|
||||
use js::jsapi::{JS_GetProperty, JS_IsExceptionPending, JS_ReportPendingException};
|
||||
|
@ -28,13 +28,13 @@ pub enum ExceptionHandling {
|
|||
/// Report any exception and don't throw it to the caller code.
|
||||
Report,
|
||||
/// Throw any exception to the caller code.
|
||||
Rethrow
|
||||
Rethrow,
|
||||
}
|
||||
|
||||
/// A common base class for representing IDL callback function types.
|
||||
#[derive(JSTraceable, PartialEq)]
|
||||
pub struct CallbackFunction {
|
||||
object: CallbackObject
|
||||
object: CallbackObject,
|
||||
}
|
||||
|
||||
impl CallbackFunction {
|
||||
|
@ -42,8 +42,8 @@ impl CallbackFunction {
|
|||
pub fn new() -> CallbackFunction {
|
||||
CallbackFunction {
|
||||
object: CallbackObject {
|
||||
callback: Heap::default()
|
||||
}
|
||||
callback: Heap::default(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ impl CallbackFunction {
|
|||
/// A common base class for representing IDL callback interface types.
|
||||
#[derive(JSTraceable, PartialEq)]
|
||||
pub struct CallbackInterface {
|
||||
object: CallbackObject
|
||||
object: CallbackObject,
|
||||
}
|
||||
|
||||
/// A common base class for representing IDL callback function and
|
||||
|
@ -103,8 +103,8 @@ impl CallbackInterface {
|
|||
pub fn new() -> CallbackInterface {
|
||||
CallbackInterface {
|
||||
object: CallbackObject {
|
||||
callback: Heap::default()
|
||||
}
|
||||
callback: Heap::default(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,21 +116,18 @@ impl CallbackInterface {
|
|||
|
||||
/// Returns the property with the given `name`, if it is a callable object,
|
||||
/// or an error otherwise.
|
||||
pub fn get_callable_property(&self, cx: *mut JSContext, name: &str)
|
||||
-> Fallible<JSVal> {
|
||||
pub fn get_callable_property(&self, cx: *mut JSContext, name: &str) -> Fallible<JSVal> {
|
||||
let mut callable = RootedValue::new(cx, UndefinedValue());
|
||||
let obj = RootedObject::new(cx, self.callback());
|
||||
unsafe {
|
||||
let c_name = CString::new(name).unwrap();
|
||||
if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(),
|
||||
callable.handle_mut()) {
|
||||
if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(), callable.handle_mut()) {
|
||||
return Err(Error::JSFailed);
|
||||
}
|
||||
|
||||
if !callable.ptr.is_object() ||
|
||||
!IsCallable(callable.ptr.to_object()) {
|
||||
return Err(Error::Type(
|
||||
format!("The value of the {} property is not callable", name)));
|
||||
if !callable.ptr.is_object() || !IsCallable(callable.ptr.to_object()) {
|
||||
return Err(Error::Type(format!("The value of the {} property is not callable",
|
||||
name)));
|
||||
}
|
||||
}
|
||||
Ok(callable.ptr)
|
||||
|
@ -172,15 +169,17 @@ impl CallSetup {
|
|||
pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup {
|
||||
let global = global_root_from_object(callback.callback());
|
||||
let cx = global.r().get_cx();
|
||||
unsafe { JS_BeginRequest(cx); }
|
||||
unsafe {
|
||||
JS_BeginRequest(cx);
|
||||
}
|
||||
|
||||
let exception_compartment = unsafe {
|
||||
GetGlobalForObjectCrossCompartment(callback.callback())
|
||||
};
|
||||
CallSetup {
|
||||
exception_compartment:
|
||||
RootedObject::new_with_addr(cx, exception_compartment,
|
||||
unsafe { return_address() }),
|
||||
exception_compartment: RootedObject::new_with_addr(cx,
|
||||
exception_compartment,
|
||||
unsafe { return_address() }),
|
||||
cx: cx,
|
||||
old_compartment: unsafe { JS_EnterCompartment(cx, callback.callback()) },
|
||||
handling: handling,
|
||||
|
@ -195,10 +194,11 @@ impl CallSetup {
|
|||
|
||||
impl Drop for CallSetup {
|
||||
fn drop(&mut self) {
|
||||
unsafe { JS_LeaveCompartment(self.cx, self.old_compartment); }
|
||||
let need_to_deal_with_exception =
|
||||
self.handling == ExceptionHandling::Report &&
|
||||
unsafe { JS_IsExceptionPending(self.cx) };
|
||||
unsafe {
|
||||
JS_LeaveCompartment(self.cx, self.old_compartment);
|
||||
}
|
||||
let need_to_deal_with_exception = self.handling == ExceptionHandling::Report &&
|
||||
unsafe { JS_IsExceptionPending(self.cx) };
|
||||
if need_to_deal_with_exception {
|
||||
unsafe {
|
||||
let old_global = RootedObject::new(self.cx, self.exception_compartment.ptr);
|
||||
|
@ -212,6 +212,8 @@ impl Drop for CallSetup {
|
|||
}
|
||||
}
|
||||
}
|
||||
unsafe { JS_EndRequest(self.cx); }
|
||||
unsafe {
|
||||
JS_EndRequest(self.cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! A shareable mutable container for the DOM.
|
||||
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use js::jsapi::{JSTracer};
|
||||
use js::jsapi::JSTracer;
|
||||
use std::cell::{BorrowState, Ref, RefCell, RefMut};
|
||||
use util::task_state;
|
||||
use util::task_state::SCRIPT;
|
||||
|
@ -40,7 +40,7 @@ impl<T> DOMRefCell<T> {
|
|||
pub unsafe fn borrow_for_gc_trace(&self) -> &T {
|
||||
// FIXME: IN_GC isn't reliable enough - doesn't catch minor GCs
|
||||
// https://github.com/servo/servo/issues/6389
|
||||
//debug_assert!(task_state::get().contains(SCRIPT | IN_GC));
|
||||
// debug_assert!(task_state::get().contains(SCRIPT | IN_GC));
|
||||
&*self.value.as_unsafe_cell().get()
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ use js::rust::ToString;
|
|||
use libc;
|
||||
use num::Float;
|
||||
use std::{ptr, slice};
|
||||
use util::str::{DOMString};
|
||||
use util::str::DOMString;
|
||||
pub use util::str::{StringificationBehavior, jsstring_to_str};
|
||||
|
||||
|
||||
|
@ -119,7 +119,10 @@ impl<T: Float + ToJSValConvertible> ToJSValConvertible for Finite<T> {
|
|||
impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite<T> {
|
||||
type Config = ();
|
||||
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, option: ()) -> Result<Finite<T>, ()> {
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
option: ())
|
||||
-> Result<Finite<T>, ()> {
|
||||
let result = try!(FromJSValConvertible::from_jsval(cx, value, option));
|
||||
match Finite::new(result) {
|
||||
Some(v) => Ok(v),
|
||||
|
@ -140,18 +143,17 @@ pub fn jsid_to_str(cx: *mut JSContext, id: HandleId) -> DOMString {
|
|||
}
|
||||
}
|
||||
|
||||
//http://heycam.github.io/webidl/#es-USVString
|
||||
// http://heycam.github.io/webidl/#es-USVString
|
||||
impl ToJSValConvertible for USVString {
|
||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
self.0.to_jsval(cx, rval);
|
||||
}
|
||||
}
|
||||
|
||||
//http://heycam.github.io/webidl/#es-USVString
|
||||
// http://heycam.github.io/webidl/#es-USVString
|
||||
impl FromJSValConvertible for USVString {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _: ())
|
||||
-> Result<USVString, ()> {
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _: ()) -> Result<USVString, ()> {
|
||||
let jsstr = ToString(cx, value);
|
||||
if jsstr.is_null() {
|
||||
debug!("ToString failed");
|
||||
|
@ -170,10 +172,11 @@ impl FromJSValConvertible for USVString {
|
|||
}
|
||||
}
|
||||
|
||||
//http://heycam.github.io/webidl/#es-ByteString
|
||||
// http://heycam.github.io/webidl/#es-ByteString
|
||||
impl ToJSValConvertible for ByteString {
|
||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
let jsstr = JS_NewStringCopyN(cx, self.as_ptr() as *const libc::c_char,
|
||||
let jsstr = JS_NewStringCopyN(cx,
|
||||
self.as_ptr() as *const libc::c_char,
|
||||
self.len() as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
panic!("JS_NewStringCopyN failed");
|
||||
|
@ -182,10 +185,13 @@ impl ToJSValConvertible for ByteString {
|
|||
}
|
||||
}
|
||||
|
||||
//http://heycam.github.io/webidl/#es-ByteString
|
||||
// http://heycam.github.io/webidl/#es-ByteString
|
||||
impl FromJSValConvertible for ByteString {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ()) -> Result<ByteString, ()> {
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
_option: ())
|
||||
-> Result<ByteString, ()> {
|
||||
let string = ToString(cx, value);
|
||||
if string.is_null() {
|
||||
debug!("ToString failed");
|
||||
|
@ -195,8 +201,7 @@ impl FromJSValConvertible for ByteString {
|
|||
let latin1 = JS_StringHasLatin1Chars(string);
|
||||
if latin1 {
|
||||
let mut length = 0;
|
||||
let chars = JS_GetLatin1StringCharsAndLength(cx, ptr::null(),
|
||||
string, &mut length);
|
||||
let chars = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
||||
assert!(!chars.is_null());
|
||||
|
||||
let char_slice = slice::from_raw_parts(chars as *mut u8, length as usize);
|
||||
|
@ -293,9 +298,11 @@ pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()>
|
|||
/// not an object for a DOM object of the given type (as defined by the
|
||||
/// proto_id and proto_depth).
|
||||
#[inline]
|
||||
pub unsafe fn private_from_proto_check<F>(mut obj: *mut JSObject, proto_check: F)
|
||||
pub unsafe fn private_from_proto_check<F>(mut obj: *mut JSObject,
|
||||
proto_check: F)
|
||||
-> Result<*const libc::c_void, ()>
|
||||
where F: Fn(&'static DOMClass) -> bool {
|
||||
where F: Fn(&'static DOMClass) -> bool
|
||||
{
|
||||
let dom_class = try!(get_dom_class(obj).or_else(|_| {
|
||||
if IsWrapper(obj) {
|
||||
debug!("found wrapper");
|
||||
|
|
|
@ -15,7 +15,7 @@ use dom::bindings::reflector::{Reflectable, Reflector};
|
|||
use dom::window::{self, ScriptHelpers};
|
||||
use dom::workerglobalscope::WorkerGlobalScope;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use js::jsapi::{GetGlobalForObjectCrossCompartment};
|
||||
use js::jsapi::GetGlobalForObjectCrossCompartment;
|
||||
use js::jsapi::{JSContext, JSObject, JS_GetClass, MutableHandleValue};
|
||||
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
||||
use msg::constellation_msg::{ConstellationChan, PipelineId, WorkerId};
|
||||
|
@ -140,7 +140,7 @@ impl<'a> GlobalRef<'a> {
|
|||
pub fn get_next_worker_id(&self) -> WorkerId {
|
||||
match *self {
|
||||
GlobalRef::Window(ref window) => window.get_next_worker_id(),
|
||||
GlobalRef::Worker(ref worker) => worker.get_next_worker_id()
|
||||
GlobalRef::Worker(ref worker) => worker.get_next_worker_id(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,10 @@ impl<'a> GlobalRef<'a> {
|
|||
|
||||
/// Schedule the given `callback` to be invoked after at least `duration` milliseconds have
|
||||
/// passed.
|
||||
pub fn schedule_callback(&self, callback: Box<ScheduledCallback>, duration: MsDuration) -> TimerHandle {
|
||||
pub fn schedule_callback(&self,
|
||||
callback: Box<ScheduledCallback>,
|
||||
duration: MsDuration)
|
||||
-> TimerHandle {
|
||||
match *self {
|
||||
GlobalRef::Window(window) => window.schedule_callback(callback, duration),
|
||||
GlobalRef::Worker(worker) => worker.schedule_callback(callback, duration),
|
||||
|
|
|
@ -15,20 +15,25 @@ use std::mem;
|
|||
/// or are derived from other interfaces.
|
||||
pub trait Castable: IDLInterface + Reflectable + Sized {
|
||||
/// Check whether a DOM object implements one of its deriving interfaces.
|
||||
fn is<T>(&self) -> bool where T: DerivedFrom<Self> {
|
||||
let class = unsafe {
|
||||
get_dom_class(self.reflector().get_jsobject().get()).unwrap()
|
||||
};
|
||||
fn is<T>(&self) -> bool
|
||||
where T: DerivedFrom<Self>
|
||||
{
|
||||
let class = unsafe { get_dom_class(self.reflector().get_jsobject().get()).unwrap() };
|
||||
T::derives(class)
|
||||
}
|
||||
|
||||
/// Cast a DOM object upwards to one of the interfaces it derives from.
|
||||
fn upcast<T>(&self) -> &T where T: Castable, Self: DerivedFrom<T> {
|
||||
fn upcast<T>(&self) -> &T
|
||||
where T: Castable,
|
||||
Self: DerivedFrom<T>
|
||||
{
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
|
||||
/// Cast a DOM object downwards to one of the interfaces it might implement.
|
||||
fn downcast<T>(&self) -> Option<&T> where T: DerivedFrom<Self> {
|
||||
fn downcast<T>(&self) -> Option<&T>
|
||||
where T: DerivedFrom<Self>
|
||||
{
|
||||
if self.is::<T>() {
|
||||
Some(unsafe { mem::transmute(self) })
|
||||
} else {
|
||||
|
|
|
@ -52,7 +52,7 @@ use util::task_state;
|
|||
/// This should only be used as a field in other DOM objects.
|
||||
#[must_root]
|
||||
pub struct JS<T> {
|
||||
ptr: NonZero<*const T>
|
||||
ptr: NonZero<*const T>,
|
||||
}
|
||||
|
||||
// JS<T> is similar to Rc<T>, in that it's not always clear how to avoid double-counting.
|
||||
|
@ -68,7 +68,7 @@ impl<T> JS<T> {
|
|||
pub unsafe fn to_layout(&self) -> LayoutJS<T> {
|
||||
debug_assert!(task_state::get().is_layout());
|
||||
LayoutJS {
|
||||
ptr: self.ptr.clone()
|
||||
ptr: self.ptr.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ impl<T: Reflectable> JS<T> {
|
|||
pub fn from_rooted(root: &Root<T>) -> JS<T> {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
JS {
|
||||
ptr: unsafe { NonZero::new(&**root) }
|
||||
ptr: unsafe { NonZero::new(&**root) },
|
||||
}
|
||||
}
|
||||
/// Create a JS<T> from a &T
|
||||
|
@ -88,7 +88,7 @@ impl<T: Reflectable> JS<T> {
|
|||
pub fn from_ref(obj: &T) -> JS<T> {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
JS {
|
||||
ptr: unsafe { NonZero::new(&*obj) }
|
||||
ptr: unsafe { NonZero::new(&*obj) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,18 +114,23 @@ impl<T: Reflectable> JSTraceable for JS<T> {
|
|||
/// traits must be implemented on this.
|
||||
#[allow_unrooted_interior]
|
||||
pub struct LayoutJS<T> {
|
||||
ptr: NonZero<*const T>
|
||||
ptr: NonZero<*const T>,
|
||||
}
|
||||
|
||||
impl<T: Castable> LayoutJS<T> {
|
||||
/// Cast a DOM object root upwards to one of the interfaces it derives from.
|
||||
pub fn upcast<U>(&self) -> LayoutJS<U> where U: Castable, T: DerivedFrom<U> {
|
||||
pub fn upcast<U>(&self) -> LayoutJS<U>
|
||||
where U: Castable,
|
||||
T: DerivedFrom<U>
|
||||
{
|
||||
debug_assert!(task_state::get().is_layout());
|
||||
unsafe { mem::transmute_copy(self) }
|
||||
}
|
||||
|
||||
/// Cast a DOM object downwards to one of the interfaces it might implement.
|
||||
pub fn downcast<U>(&self) -> Option<LayoutJS<U>> where U: DerivedFrom<T> {
|
||||
pub fn downcast<U>(&self) -> Option<LayoutJS<U>>
|
||||
where U: DerivedFrom<T>
|
||||
{
|
||||
debug_assert!(task_state::get().is_layout());
|
||||
unsafe {
|
||||
if (*self.unsafe_get()).is::<U>() {
|
||||
|
@ -164,11 +169,15 @@ impl<T> PartialEq for LayoutJS<T> {
|
|||
impl<T> Eq for LayoutJS<T> {}
|
||||
|
||||
impl<T> Hash for JS<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) { self.ptr.hash(state) }
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.ptr.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Hash for LayoutJS<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) { self.ptr.hash(state) }
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.ptr.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl <T> Clone for JS<T> {
|
||||
|
@ -177,7 +186,7 @@ impl <T> Clone for JS<T> {
|
|||
fn clone(&self) -> JS<T> {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
JS {
|
||||
ptr: self.ptr.clone()
|
||||
ptr: self.ptr.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +196,7 @@ impl <T> Clone for LayoutJS<T> {
|
|||
fn clone(&self) -> LayoutJS<T> {
|
||||
debug_assert!(task_state::get().is_layout());
|
||||
LayoutJS {
|
||||
ptr: self.ptr.clone()
|
||||
ptr: self.ptr.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,12 +204,11 @@ impl <T> Clone for LayoutJS<T> {
|
|||
impl LayoutJS<Node> {
|
||||
/// Create a new JS-owned value wrapped from an address known to be a
|
||||
/// `Node` pointer.
|
||||
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress)
|
||||
-> LayoutJS<Node> {
|
||||
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> LayoutJS<Node> {
|
||||
debug_assert!(task_state::get().is_layout());
|
||||
let TrustedNodeAddress(addr) = inner;
|
||||
LayoutJS {
|
||||
ptr: NonZero::new(addr as *const Node)
|
||||
ptr: NonZero::new(addr as *const Node),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +333,7 @@ impl<T: Reflectable + PartialEq> PartialEq<T> for MutHeap<JS<T>> {
|
|||
#[must_root]
|
||||
#[derive(JSTraceable)]
|
||||
pub struct MutNullableHeap<T: HeapGCValue> {
|
||||
ptr: UnsafeCell<Option<T>>
|
||||
ptr: UnsafeCell<Option<T>>,
|
||||
}
|
||||
|
||||
impl<T: Reflectable> MutNullableHeap<JS<T>> {
|
||||
|
@ -333,7 +341,7 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
|
|||
pub fn new(initial: Option<&T>) -> MutNullableHeap<JS<T>> {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
MutNullableHeap {
|
||||
ptr: UnsafeCell::new(initial.map(JS::from_ref))
|
||||
ptr: UnsafeCell::new(initial.map(JS::from_ref)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +409,7 @@ impl<T: HeapGCValue> Default for MutNullableHeap<T> {
|
|||
fn default() -> MutNullableHeap<T> {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
MutNullableHeap {
|
||||
ptr: UnsafeCell::new(None)
|
||||
ptr: UnsafeCell::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +471,9 @@ pub struct RootCollectionPtr(pub *const RootCollection);
|
|||
|
||||
impl Copy for RootCollectionPtr {}
|
||||
impl Clone for RootCollectionPtr {
|
||||
fn clone(&self) -> RootCollectionPtr { *self }
|
||||
fn clone(&self) -> RootCollectionPtr {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl RootCollection {
|
||||
|
@ -471,7 +481,7 @@ impl RootCollection {
|
|||
pub fn new() -> RootCollection {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
RootCollection {
|
||||
roots: UnsafeCell::new(vec!()),
|
||||
roots: UnsafeCell::new(vec![]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -495,7 +505,7 @@ impl RootCollection {
|
|||
Some(idx) => {
|
||||
roots.remove(idx);
|
||||
},
|
||||
None => panic!("Can't remove a root that was never rooted!")
|
||||
None => panic!("Can't remove a root that was never rooted!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -528,12 +538,17 @@ pub struct Root<T: Reflectable> {
|
|||
|
||||
impl<T: Castable> Root<T> {
|
||||
/// Cast a DOM object root upwards to one of the interfaces it derives from.
|
||||
pub fn upcast<U>(root: Root<T>) -> Root<U> where U: Castable, T: DerivedFrom<U> {
|
||||
pub fn upcast<U>(root: Root<T>) -> Root<U>
|
||||
where U: Castable,
|
||||
T: DerivedFrom<U>
|
||||
{
|
||||
unsafe { mem::transmute(root) }
|
||||
}
|
||||
|
||||
/// Cast a DOM object root downwards to one of the interfaces it might implement.
|
||||
pub fn downcast<U>(root: Root<T>) -> Option<Root<U>> where U: DerivedFrom<T> {
|
||||
pub fn downcast<U>(root: Root<T>) -> Option<Root<U>>
|
||||
where U: DerivedFrom<T>
|
||||
{
|
||||
if root.is::<U>() {
|
||||
Some(unsafe { mem::transmute(root) })
|
||||
} else {
|
||||
|
@ -546,8 +561,7 @@ impl<T: Reflectable> Root<T> {
|
|||
/// Create a new stack-bounded root for the provided JS-owned value.
|
||||
/// It cannot not outlive its associated `RootCollection`, and it gives
|
||||
/// out references which cannot outlive this new `Root`.
|
||||
pub fn new(unrooted: NonZero<*const T>)
|
||||
-> Root<T> {
|
||||
pub fn new(unrooted: NonZero<*const T>) -> Root<T> {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
STACK_ROOTS.with(|ref collection| {
|
||||
let RootCollectionPtr(collection) = collection.get().unwrap();
|
||||
|
@ -587,6 +601,8 @@ impl<T: Reflectable> PartialEq for Root<T> {
|
|||
|
||||
impl<T: Reflectable> Drop for Root<T> {
|
||||
fn drop(&mut self) {
|
||||
unsafe { (*self.root_list).unroot(self); }
|
||||
unsafe {
|
||||
(*self.root_list).unroot(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ impl<T: Float> Finite<T> {
|
|||
/// Create a new `Finite<T: Float>`.
|
||||
#[inline]
|
||||
pub fn wrap(value: T) -> Finite<T> {
|
||||
assert!(value.is_finite(), "Finite<T> doesn't encapsulate unrestricted value.");
|
||||
assert!(value.is_finite(),
|
||||
"Finite<T> doesn't encapsulate unrestricted value.");
|
||||
Finite(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ use js::glue::GetProxyExtra;
|
|||
use js::glue::InvokeGetOwnPropertyDescriptor;
|
||||
use js::glue::{GetProxyHandler, SetProxyExtra};
|
||||
use js::jsapi::GetObjectProto;
|
||||
use js::jsapi::JS_GetPropertyDescriptorById;
|
||||
use js::jsapi::{Handle, HandleId, HandleObject, MutableHandle, ObjectOpResult, RootedObject};
|
||||
use js::jsapi::{JSContext, JSObject, JSPropertyDescriptor};
|
||||
use js::jsapi::{JSErrNum, JS_StrictPropertyStub};
|
||||
use js::jsapi::{JS_DefinePropertyById6, JS_NewObjectWithGivenProto};
|
||||
use js::jsapi::{JS_GetPropertyDescriptorById};
|
||||
use js::jsval::ObjectValue;
|
||||
use js::{JSPROP_ENUMERATE, JSPROP_GETTER, JSPROP_READONLY};
|
||||
use libc;
|
||||
|
@ -28,11 +28,11 @@ static JSPROXYSLOT_EXPANDO: u32 = 0;
|
|||
/// with argument `id` and return the result, if it is not `undefined`.
|
||||
/// Otherwise, walk along the prototype chain to find a property with that
|
||||
/// name.
|
||||
pub unsafe extern fn get_property_descriptor(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
desc: MutableHandle<JSPropertyDescriptor>)
|
||||
-> bool {
|
||||
pub unsafe extern "C" fn get_property_descriptor(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
desc: MutableHandle<JSPropertyDescriptor>)
|
||||
-> bool {
|
||||
let handler = GetProxyHandler(proxy.get());
|
||||
if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) {
|
||||
return false;
|
||||
|
@ -51,11 +51,13 @@ pub unsafe extern fn get_property_descriptor(cx: *mut JSContext,
|
|||
}
|
||||
|
||||
/// Defines an expando on the given `proxy`.
|
||||
pub unsafe extern fn define_property(cx: *mut JSContext, proxy: HandleObject,
|
||||
id: HandleId, desc: Handle<JSPropertyDescriptor>,
|
||||
result: *mut ObjectOpResult)
|
||||
-> bool {
|
||||
//FIXME: Workaround for https://github.com/mozilla/rust/issues/13385
|
||||
pub unsafe extern "C" fn define_property(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
desc: Handle<JSPropertyDescriptor>,
|
||||
result: *mut ObjectOpResult)
|
||||
-> bool {
|
||||
// FIXME: Workaround for https://github.com/mozilla/rust/issues/13385
|
||||
let setter: *const libc::c_void = mem::transmute(desc.get().setter);
|
||||
let setter_stub: *const libc::c_void = mem::transmute(JS_StrictPropertyStub);
|
||||
if (desc.get().attrs & JSPROP_GETTER) != 0 && setter == setter_stub {
|
||||
|
@ -68,8 +70,11 @@ pub unsafe extern fn define_property(cx: *mut JSContext, proxy: HandleObject,
|
|||
}
|
||||
|
||||
/// Deletes an expando off the given `proxy`.
|
||||
pub unsafe extern fn delete(cx: *mut JSContext, proxy: HandleObject, id: HandleId,
|
||||
bp: *mut ObjectOpResult) -> bool {
|
||||
pub unsafe extern "C" fn delete(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
bp: *mut ObjectOpResult)
|
||||
-> bool {
|
||||
let expando = RootedObject::new(cx, get_expando_object(proxy));
|
||||
if expando.ptr.is_null() {
|
||||
(*bp).code_ = 0 /* OkCode */;
|
||||
|
@ -80,16 +85,19 @@ pub unsafe extern fn delete(cx: *mut JSContext, proxy: HandleObject, id: HandleI
|
|||
}
|
||||
|
||||
/// Controls whether the Extensible bit can be changed
|
||||
pub unsafe extern fn prevent_extensions(_cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
result: *mut ObjectOpResult) -> bool {
|
||||
pub unsafe extern "C" fn prevent_extensions(_cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
result: *mut ObjectOpResult)
|
||||
-> bool {
|
||||
(*result).code_ = JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS as ::libc::uintptr_t;
|
||||
true
|
||||
}
|
||||
|
||||
/// Reports whether the object is Extensible
|
||||
pub unsafe extern fn is_extensible(_cx: *mut JSContext, _proxy: HandleObject,
|
||||
succeeded: *mut bool) -> bool {
|
||||
pub unsafe extern "C" fn is_extensible(_cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
succeeded: *mut bool)
|
||||
-> bool {
|
||||
*succeeded = true;
|
||||
true
|
||||
}
|
||||
|
@ -109,8 +117,7 @@ pub fn get_expando_object(obj: HandleObject) -> *mut JSObject {
|
|||
|
||||
/// Get the expando object, or create it if it doesn't exist yet.
|
||||
/// Fails on JSAPI failure.
|
||||
pub fn ensure_expando_object(cx: *mut JSContext, obj: HandleObject)
|
||||
-> *mut JSObject {
|
||||
pub fn ensure_expando_object(cx: *mut JSContext, obj: HandleObject) -> *mut JSObject {
|
||||
unsafe {
|
||||
assert!(is_dom_proxy(obj.get()));
|
||||
let mut expando = get_expando_object(obj);
|
||||
|
@ -127,7 +134,8 @@ pub fn ensure_expando_object(cx: *mut JSContext, obj: HandleObject)
|
|||
/// Set the property descriptor's object to `obj` and set it to enumerable,
|
||||
/// and writable if `readonly` is true.
|
||||
pub fn fill_property_descriptor(desc: &mut JSPropertyDescriptor,
|
||||
obj: *mut JSObject, readonly: bool) {
|
||||
obj: *mut JSObject,
|
||||
readonly: bool) {
|
||||
desc.obj = obj;
|
||||
desc.attrs = if readonly { JSPROP_READONLY } else { 0 } | JSPROP_ENUMERATE;
|
||||
desc.getter = None;
|
||||
|
|
|
@ -138,7 +138,7 @@ impl<T: Reflectable> Drop for Trusted<T> {
|
|||
/// from being garbage collected due to outstanding references.
|
||||
pub struct LiveDOMReferences {
|
||||
// keyed on pointer to Rust DOM object
|
||||
table: RefCell<HashMap<*const libc::c_void, Arc<Mutex<usize>>>>
|
||||
table: RefCell<HashMap<*const libc::c_void, Arc<Mutex<usize>>>>,
|
||||
}
|
||||
|
||||
impl LiveDOMReferences {
|
||||
|
@ -197,7 +197,8 @@ impl LiveDOMReferences {
|
|||
}
|
||||
|
||||
/// A JSTraceDataOp for tracing reflectors held in LIVE_REFERENCES
|
||||
pub unsafe extern fn trace_refcounted_objects(tracer: *mut JSTracer, _data: *mut libc::c_void) {
|
||||
pub unsafe extern "C" fn trace_refcounted_objects(tracer: *mut JSTracer,
|
||||
_data: *mut libc::c_void) {
|
||||
LIVE_REFERENCES.with(|ref r| {
|
||||
let r = r.borrow();
|
||||
let live_references = r.as_ref().unwrap();
|
||||
|
|
|
@ -12,11 +12,10 @@ use std::ptr;
|
|||
|
||||
/// Create the reflector for a new DOM object and yield ownership to the
|
||||
/// reflector.
|
||||
pub fn reflect_dom_object<T: Reflectable>
|
||||
(obj: Box<T>,
|
||||
global: GlobalRef,
|
||||
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<T>) -> Root<T>)
|
||||
-> Root<T> {
|
||||
pub fn reflect_dom_object<T: Reflectable>(obj: Box<T>,
|
||||
global: GlobalRef,
|
||||
wrap_fn: fn(*mut JSContext, GlobalRef, Box<T>) -> Root<T>)
|
||||
-> Root<T> {
|
||||
wrap_fn(global.get_cx(), global, obj)
|
||||
}
|
||||
|
||||
|
@ -65,7 +64,7 @@ impl Reflector {
|
|||
/// Create an uninitialized `Reflector`.
|
||||
pub fn new() -> Reflector {
|
||||
Reflector {
|
||||
object: UnsafeCell::new(ptr::null_mut())
|
||||
object: UnsafeCell::new(ptr::null_mut()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,12 +56,26 @@ impl ByteString {
|
|||
// http://tools.ietf.org/html/rfc2616#section-2.2
|
||||
match x {
|
||||
0...31 | 127 => false, // CTLs
|
||||
40 | 41 | 60 | 62 | 64 |
|
||||
44 | 59 | 58 | 92 | 34 |
|
||||
47 | 91 | 93 | 63 | 61 |
|
||||
123 | 125 | 32 => false, // separators
|
||||
40 |
|
||||
41 |
|
||||
60 |
|
||||
62 |
|
||||
64 |
|
||||
44 |
|
||||
59 |
|
||||
58 |
|
||||
92 |
|
||||
34 |
|
||||
47 |
|
||||
91 |
|
||||
93 |
|
||||
63 |
|
||||
61 |
|
||||
123 |
|
||||
125 |
|
||||
32 => false, // separators
|
||||
x if x > 127 => false, // non-CHARs
|
||||
_ => true
|
||||
_ => true,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -75,7 +89,7 @@ impl ByteString {
|
|||
Other,
|
||||
CR,
|
||||
LF,
|
||||
SPHT // SP or HT
|
||||
SPHT, // SP or HT
|
||||
}
|
||||
let ByteString(ref vec) = *self;
|
||||
let mut prev = PreviousCharacter::Other; // The previous character
|
||||
|
|
|
@ -22,17 +22,22 @@ pub struct StructuredCloneData {
|
|||
|
||||
impl StructuredCloneData {
|
||||
/// Writes a structured clone. Returns a `DataClone` error if that fails.
|
||||
pub fn write(cx: *mut JSContext, message: HandleValue)
|
||||
-> Fallible<StructuredCloneData> {
|
||||
pub fn write(cx: *mut JSContext, message: HandleValue) -> Fallible<StructuredCloneData> {
|
||||
let mut data = ptr::null_mut();
|
||||
let mut nbytes = 0;
|
||||
let result = unsafe {
|
||||
JS_WriteStructuredClone(cx, message, &mut data, &mut nbytes,
|
||||
ptr::null(), ptr::null_mut(),
|
||||
JS_WriteStructuredClone(cx,
|
||||
message,
|
||||
&mut data,
|
||||
&mut nbytes,
|
||||
ptr::null(),
|
||||
ptr::null_mut(),
|
||||
HandleValue::undefined())
|
||||
};
|
||||
if !result {
|
||||
unsafe { JS_ClearPendingException(cx); }
|
||||
unsafe {
|
||||
JS_ClearPendingException(cx);
|
||||
}
|
||||
return Err(Error::DataClone);
|
||||
}
|
||||
Ok(StructuredCloneData {
|
||||
|
@ -46,10 +51,13 @@ impl StructuredCloneData {
|
|||
/// Panics if `JS_ReadStructuredClone` fails.
|
||||
pub fn read(self, global: GlobalRef, rval: MutableHandleValue) {
|
||||
unsafe {
|
||||
assert!(JS_ReadStructuredClone(
|
||||
global.get_cx(), self.data, self.nbytes,
|
||||
JS_STRUCTURED_CLONE_VERSION, rval,
|
||||
ptr::null(), ptr::null_mut()));
|
||||
assert!(JS_ReadStructuredClone(global.get_cx(),
|
||||
self.data,
|
||||
self.nbytes,
|
||||
JS_STRUCTURED_CLONE_VERSION,
|
||||
rval,
|
||||
ptr::null(),
|
||||
ptr::null_mut()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,8 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap<JSVal>)
|
|||
(*tracer).debugPrintIndex_ = !0;
|
||||
(*tracer).debugPrintArg_ = name.as_ptr() as *const libc::c_void;
|
||||
debug!("tracing value {}", description);
|
||||
JS_CallValueTracer(tracer, val.ptr.get() as *mut _,
|
||||
JS_CallValueTracer(tracer,
|
||||
val.ptr.get() as *mut _,
|
||||
GCTraceKindToAscii(val.get().trace_kind()));
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +127,8 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref
|
|||
(*tracer).debugPrintIndex_ = !0;
|
||||
(*tracer).debugPrintArg_ = name.as_ptr() as *const libc::c_void;
|
||||
debug!("tracing reflector {}", description);
|
||||
JS_CallUnbarrieredObjectTracer(tracer, reflector.rootable(),
|
||||
JS_CallUnbarrieredObjectTracer(tracer,
|
||||
reflector.rootable(),
|
||||
GCTraceKindToAscii(JSGCTraceKind::JSTRACE_OBJECT));
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +141,8 @@ pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: &Heap<*mut JS
|
|||
(*tracer).debugPrintIndex_ = !0;
|
||||
(*tracer).debugPrintArg_ = name.as_ptr() as *const libc::c_void;
|
||||
debug!("tracing {}", description);
|
||||
JS_CallObjectTracer(tracer, obj.ptr.get() as *mut _,
|
||||
JS_CallObjectTracer(tracer,
|
||||
obj.ptr.get() as *mut _,
|
||||
GCTraceKindToAscii(JSGCTraceKind::JSTRACE_OBJECT));
|
||||
}
|
||||
}
|
||||
|
@ -354,12 +357,12 @@ impl<T> JSTraceable for IpcReceiver<T> where T: Deserialize + Serialize {
|
|||
/// Homemade trait object for JSTraceable things
|
||||
struct TraceableInfo {
|
||||
pub ptr: *const libc::c_void,
|
||||
pub trace: fn(obj: *const libc::c_void, tracer: *mut JSTracer)
|
||||
pub trace: fn(obj: *const libc::c_void, tracer: *mut JSTracer),
|
||||
}
|
||||
|
||||
/// Holds a set of JSTraceables that need to be rooted
|
||||
pub struct RootedTraceableSet {
|
||||
set: Vec<TraceableInfo>
|
||||
set: Vec<TraceableInfo>,
|
||||
}
|
||||
|
||||
#[allow(missing_docs)] // FIXME
|
||||
|
@ -376,7 +379,7 @@ pub use self::dummy::ROOTED_TRACEABLES;
|
|||
impl RootedTraceableSet {
|
||||
fn new() -> RootedTraceableSet {
|
||||
RootedTraceableSet {
|
||||
set: vec!()
|
||||
set: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,7 +427,7 @@ impl RootedTraceableSet {
|
|||
/// If you know what you're doing, use this.
|
||||
#[derive(JSTraceable)]
|
||||
pub struct RootedTraceable<'a, T: 'a + JSTraceable> {
|
||||
ptr: &'a T
|
||||
ptr: &'a T,
|
||||
}
|
||||
|
||||
impl<'a, T: JSTraceable> RootedTraceable<'a, T> {
|
||||
|
@ -433,7 +436,9 @@ impl<'a, T: JSTraceable> RootedTraceable<'a, T> {
|
|||
unsafe {
|
||||
RootedTraceableSet::add(traceable);
|
||||
}
|
||||
RootedTraceable { ptr: traceable }
|
||||
RootedTraceable {
|
||||
ptr: traceable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,7 +456,7 @@ impl<'a, T: JSTraceable> Drop for RootedTraceable<'a, T> {
|
|||
#[derive(JSTraceable)]
|
||||
#[allow_unrooted_interior]
|
||||
pub struct RootedVec<T: JSTraceable> {
|
||||
v: Vec<T>
|
||||
v: Vec<T>,
|
||||
}
|
||||
|
||||
|
||||
|
@ -459,9 +464,7 @@ impl<T: JSTraceable> RootedVec<T> {
|
|||
/// Create a vector of items of type T that is rooted for
|
||||
/// the lifetime of this struct
|
||||
pub fn new() -> RootedVec<T> {
|
||||
let addr = unsafe {
|
||||
return_address() as *const libc::c_void
|
||||
};
|
||||
let addr = unsafe { return_address() as *const libc::c_void };
|
||||
|
||||
unsafe { RootedVec::new_with_destination_address(addr) }
|
||||
}
|
||||
|
@ -470,7 +473,9 @@ impl<T: JSTraceable> RootedVec<T> {
|
|||
/// for RootTraceableSet.
|
||||
pub unsafe fn new_with_destination_address(addr: *const libc::c_void) -> RootedVec<T> {
|
||||
RootedTraceableSet::add::<RootedVec<T>>(&*(addr as *const _));
|
||||
RootedVec::<T> { v: vec!() }
|
||||
RootedVec::<T> {
|
||||
v: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -504,7 +509,9 @@ impl<T: JSTraceable> DerefMut for RootedVec<T> {
|
|||
|
||||
impl<A: JSTraceable + Reflectable> FromIterator<Root<A>> for RootedVec<JS<A>> {
|
||||
#[allow(moved_no_move)]
|
||||
fn from_iter<T>(iterable: T) -> RootedVec<JS<A>> where T: IntoIterator<Item=Root<A>> {
|
||||
fn from_iter<T>(iterable: T) -> RootedVec<JS<A>>
|
||||
where T: IntoIterator<Item = Root<A>>
|
||||
{
|
||||
let mut vec = unsafe {
|
||||
RootedVec::new_with_destination_address(return_address() as *const libc::c_void)
|
||||
};
|
||||
|
|
|
@ -58,7 +58,7 @@ pub struct WindowProxyHandler(pub *const libc::c_void);
|
|||
|
||||
impl HeapSizeOf for WindowProxyHandler {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
//FIXME(#6907) this is a pointer to memory allocated by `new` in NewProxyHandler in rust-mozjs.
|
||||
// FIXME(#6907) this is a pointer to memory allocated by `new` in NewProxyHandler in rust-mozjs.
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ pub struct ConstantSpec {
|
|||
/// name of the constant.
|
||||
pub name: &'static [u8],
|
||||
/// value of the constant.
|
||||
pub value: ConstantVal
|
||||
pub value: ConstantVal,
|
||||
}
|
||||
|
||||
impl ConstantSpec {
|
||||
|
@ -166,10 +166,12 @@ pub struct DOMJSClass {
|
|||
/// The actual JSClass.
|
||||
pub base: js::jsapi::Class,
|
||||
/// Associated data for DOM object reflectors.
|
||||
pub dom_class: DOMClass
|
||||
pub dom_class: DOMClass,
|
||||
}
|
||||
impl Clone for DOMJSClass {
|
||||
fn clone(&self) -> DOMJSClass { *self }
|
||||
fn clone(&self) -> DOMJSClass {
|
||||
*self
|
||||
}
|
||||
}
|
||||
unsafe impl Sync for DOMJSClass {}
|
||||
|
||||
|
@ -216,17 +218,17 @@ pub fn do_create_interface_objects(cx: *mut JSContext,
|
|||
rval: MutableHandleObject) {
|
||||
assert!(rval.get().is_null());
|
||||
if let Some(proto_class) = proto_class {
|
||||
create_interface_prototype_object(cx, proto_proto,
|
||||
proto_class, members, rval);
|
||||
create_interface_prototype_object(cx, proto_proto, proto_class, members, rval);
|
||||
|
||||
if !rval.get().is_null() {
|
||||
let dom_class_ptr = match dom_class {
|
||||
Some(dom_class) => dom_class as *const DOMClass as *const libc::c_void,
|
||||
None => ptr::null() as *const libc::c_void,
|
||||
None => ptr::null() as *const libc::c_void,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
JS_SetReservedSlot(rval.get(), DOM_PROTO_INSTANCE_CLASS_SLOT,
|
||||
JS_SetReservedSlot(rval.get(),
|
||||
DOM_PROTO_INSTANCE_CLASS_SLOT,
|
||||
PrivateValue(dom_class_ptr));
|
||||
}
|
||||
}
|
||||
|
@ -234,22 +236,30 @@ pub fn do_create_interface_objects(cx: *mut JSContext,
|
|||
|
||||
if let Some((native, name, nargs)) = constructor {
|
||||
let s = CString::new(name).unwrap();
|
||||
create_interface_object(cx, receiver,
|
||||
native, nargs, rval.handle(),
|
||||
members, s.as_ptr())
|
||||
create_interface_object(cx,
|
||||
receiver,
|
||||
native,
|
||||
nargs,
|
||||
rval.handle(),
|
||||
members,
|
||||
s.as_ptr())
|
||||
}
|
||||
|
||||
for ctor in named_constructors {
|
||||
let (cnative, cname, cnargs) = *ctor;
|
||||
|
||||
let cs = CString::new(cname).unwrap();
|
||||
let constructor = RootedObject::new(cx, create_constructor(cx, cnative, cnargs, cs.as_ptr()));
|
||||
let constructor = RootedObject::new(cx,
|
||||
create_constructor(cx, cnative, cnargs, cs.as_ptr()));
|
||||
assert!(!constructor.ptr.is_null());
|
||||
unsafe {
|
||||
assert!(JS_DefineProperty1(cx, constructor.handle(), b"prototype\0".as_ptr() as *const libc::c_char,
|
||||
assert!(JS_DefineProperty1(cx,
|
||||
constructor.handle(),
|
||||
b"prototype\0".as_ptr() as *const libc::c_char,
|
||||
rval.handle(),
|
||||
JSPROP_PERMANENT | JSPROP_READONLY,
|
||||
None, None));
|
||||
None,
|
||||
None));
|
||||
}
|
||||
define_constructor(cx, receiver, cs.as_ptr(), constructor.handle());
|
||||
}
|
||||
|
@ -259,10 +269,14 @@ pub fn do_create_interface_objects(cx: *mut JSContext,
|
|||
fn create_constructor(cx: *mut JSContext,
|
||||
constructor_native: NonNullJSNative,
|
||||
ctor_nargs: u32,
|
||||
name: *const libc::c_char) -> *mut JSObject {
|
||||
name: *const libc::c_char)
|
||||
-> *mut JSObject {
|
||||
unsafe {
|
||||
let fun = JS_NewFunction(cx, Some(constructor_native), ctor_nargs,
|
||||
JSFUN_CONSTRUCTOR, name);
|
||||
let fun = JS_NewFunction(cx,
|
||||
Some(constructor_native),
|
||||
ctor_nargs,
|
||||
JSFUN_CONSTRUCTOR,
|
||||
name);
|
||||
assert!(!fun.is_null());
|
||||
|
||||
let constructor = JS_GetFunctionObject(fun);
|
||||
|
@ -281,9 +295,7 @@ fn define_constructor(cx: *mut JSContext,
|
|||
assert!(JS_AlreadyHasOwnProperty(cx, receiver, name, &mut already_defined));
|
||||
|
||||
if !already_defined {
|
||||
assert!(JS_DefineProperty1(cx, receiver, name,
|
||||
constructor,
|
||||
0, None, None));
|
||||
assert!(JS_DefineProperty1(cx, receiver, name, constructor, 0, None, None));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -294,11 +306,16 @@ fn define_constructor(cx: *mut JSContext,
|
|||
fn create_interface_object(cx: *mut JSContext,
|
||||
receiver: HandleObject,
|
||||
constructor_native: NonNullJSNative,
|
||||
ctor_nargs: u32, proto: HandleObject,
|
||||
ctor_nargs: u32,
|
||||
proto: HandleObject,
|
||||
members: &'static NativeProperties,
|
||||
name: *const libc::c_char) {
|
||||
unsafe {
|
||||
let constructor = RootedObject::new(cx, create_constructor(cx, constructor_native, ctor_nargs, name));
|
||||
let constructor = RootedObject::new(cx,
|
||||
create_constructor(cx,
|
||||
constructor_native,
|
||||
ctor_nargs,
|
||||
name));
|
||||
assert!(!constructor.ptr.is_null());
|
||||
|
||||
if let Some(static_methods) = members.static_methods {
|
||||
|
@ -323,22 +340,25 @@ fn create_interface_object(cx: *mut JSContext,
|
|||
|
||||
/// Defines constants on `obj`.
|
||||
/// Fails on JSAPI failure.
|
||||
fn define_constants(cx: *mut JSContext, obj: HandleObject,
|
||||
constants: &'static [ConstantSpec]) {
|
||||
fn define_constants(cx: *mut JSContext, obj: HandleObject, constants: &'static [ConstantSpec]) {
|
||||
for spec in constants {
|
||||
let value = RootedValue::new(cx, spec.get_value());
|
||||
unsafe {
|
||||
assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *const libc::c_char,
|
||||
assert!(JS_DefineProperty(cx,
|
||||
obj,
|
||||
spec.name.as_ptr() as *const libc::c_char,
|
||||
value.handle(),
|
||||
JSPROP_ENUMERATE | JSPROP_READONLY |
|
||||
JSPROP_PERMANENT, None, None));
|
||||
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT,
|
||||
None,
|
||||
None));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the *interface prototype object*.
|
||||
/// Fails on JSAPI failure.
|
||||
fn create_interface_prototype_object(cx: *mut JSContext, global: HandleObject,
|
||||
fn create_interface_prototype_object(cx: *mut JSContext,
|
||||
global: HandleObject,
|
||||
proto_class: &'static JSClass,
|
||||
members: &'static NativeProperties,
|
||||
rval: MutableHandleObject) {
|
||||
|
@ -362,8 +382,10 @@ fn create_interface_prototype_object(cx: *mut JSContext, global: HandleObject,
|
|||
|
||||
/// A throwing constructor, for those interfaces that have neither
|
||||
/// `NoInterfaceObject` nor `Constructor`.
|
||||
pub unsafe extern fn throwing_constructor(cx: *mut JSContext, _argc: c_uint,
|
||||
_vp: *mut JSVal) -> bool {
|
||||
pub unsafe extern "C" fn throwing_constructor(cx: *mut JSContext,
|
||||
_argc: c_uint,
|
||||
_vp: *mut JSVal)
|
||||
-> bool {
|
||||
throw_type_error(cx, "Illegal constructor.");
|
||||
false
|
||||
}
|
||||
|
@ -389,29 +411,31 @@ pub fn initialize_global(global: *mut JSObject) {
|
|||
/// set to true and `*vp` to the value, otherwise `*found` is set to false.
|
||||
///
|
||||
/// Returns false on JSAPI failure.
|
||||
pub fn get_property_on_prototype(cx: *mut JSContext, proxy: HandleObject,
|
||||
id: HandleId, found: *mut bool, vp: MutableHandleValue)
|
||||
pub fn get_property_on_prototype(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
found: *mut bool,
|
||||
vp: MutableHandleValue)
|
||||
-> bool {
|
||||
unsafe {
|
||||
//let proto = GetObjectProto(proxy);
|
||||
let mut proto = RootedObject::new(cx, ptr::null_mut());
|
||||
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) ||
|
||||
proto.ptr.is_null() {
|
||||
*found = false;
|
||||
return true;
|
||||
}
|
||||
let mut has_property = false;
|
||||
if !JS_HasPropertyById(cx, proto.handle(), id, &mut has_property) {
|
||||
return false;
|
||||
}
|
||||
*found = has_property;
|
||||
let no_output = vp.ptr.is_null();
|
||||
if !has_property || no_output {
|
||||
return true;
|
||||
}
|
||||
// let proto = GetObjectProto(proxy);
|
||||
let mut proto = RootedObject::new(cx, ptr::null_mut());
|
||||
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) || proto.ptr.is_null() {
|
||||
*found = false;
|
||||
return true;
|
||||
}
|
||||
let mut has_property = false;
|
||||
if !JS_HasPropertyById(cx, proto.handle(), id, &mut has_property) {
|
||||
return false;
|
||||
}
|
||||
*found = has_property;
|
||||
let no_output = vp.ptr.is_null();
|
||||
if !has_property || no_output {
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_ForwardGetPropertyTo(cx, proto.handle(), id, proxy, vp)
|
||||
}
|
||||
JS_ForwardGetPropertyTo(cx, proto.handle(), id, proxy, vp)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an array index from the given `jsid`. Returns `None` if the given
|
||||
|
@ -485,17 +509,19 @@ pub fn get_dictionary_property(cx: *mut JSContext,
|
|||
property: &str,
|
||||
rval: MutableHandleValue)
|
||||
-> Result<bool, ()> {
|
||||
fn has_property(cx: *mut JSContext, object: HandleObject, property: &CString,
|
||||
found: &mut bool) -> bool {
|
||||
unsafe {
|
||||
JS_HasProperty(cx, object, property.as_ptr(), found)
|
||||
}
|
||||
fn has_property(cx: *mut JSContext,
|
||||
object: HandleObject,
|
||||
property: &CString,
|
||||
found: &mut bool)
|
||||
-> bool {
|
||||
unsafe { JS_HasProperty(cx, object, property.as_ptr(), found) }
|
||||
}
|
||||
fn get_property(cx: *mut JSContext, object: HandleObject, property: &CString,
|
||||
value: MutableHandleValue) -> bool {
|
||||
unsafe {
|
||||
JS_GetProperty(cx, object, property.as_ptr(), value)
|
||||
}
|
||||
fn get_property(cx: *mut JSContext,
|
||||
object: HandleObject,
|
||||
property: &CString,
|
||||
value: MutableHandleValue)
|
||||
-> bool {
|
||||
unsafe { JS_GetProperty(cx, object, property.as_ptr(), value) }
|
||||
}
|
||||
|
||||
let property = CString::new(property).unwrap();
|
||||
|
@ -525,7 +551,8 @@ pub fn get_dictionary_property(cx: *mut JSContext,
|
|||
pub fn set_dictionary_property(cx: *mut JSContext,
|
||||
object: HandleObject,
|
||||
property: &str,
|
||||
value: HandleValue) -> Result<(), ()> {
|
||||
value: HandleValue)
|
||||
-> Result<(), ()> {
|
||||
if object.get().is_null() {
|
||||
return Err(());
|
||||
}
|
||||
|
@ -541,16 +568,17 @@ pub fn set_dictionary_property(cx: *mut JSContext,
|
|||
}
|
||||
|
||||
/// Returns whether `proxy` has a property `id` on its prototype.
|
||||
pub fn has_property_on_prototype(cx: *mut JSContext, proxy: HandleObject,
|
||||
id: HandleId) -> bool {
|
||||
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
||||
pub fn has_property_on_prototype(cx: *mut JSContext, proxy: HandleObject, id: HandleId) -> bool {
|
||||
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
||||
let mut found = false;
|
||||
!get_property_on_prototype(cx, proxy, id, &mut found,
|
||||
unsafe { MutableHandleValue::from_marked_location(ptr::null_mut()) }) || found
|
||||
!get_property_on_prototype(cx, proxy, id, &mut found, unsafe {
|
||||
MutableHandleValue::from_marked_location(ptr::null_mut())
|
||||
}) || found
|
||||
}
|
||||
|
||||
/// Create a DOM global object with the given class.
|
||||
pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass,
|
||||
pub fn create_dom_global(cx: *mut JSContext,
|
||||
class: *const JSClass,
|
||||
private: *const libc::c_void,
|
||||
trace: JSTraceOp)
|
||||
-> *mut JSObject {
|
||||
|
@ -561,8 +589,11 @@ pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass,
|
|||
|
||||
let obj =
|
||||
RootedObject::new(cx,
|
||||
JS_NewGlobalObject(cx, class, ptr::null_mut(),
|
||||
OnNewGlobalHookOption::DontFireOnNewGlobalHook, &options));
|
||||
JS_NewGlobalObject(cx,
|
||||
class,
|
||||
ptr::null_mut(),
|
||||
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
|
||||
&options));
|
||||
if obj.ptr.is_null() {
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
@ -586,8 +617,7 @@ pub unsafe fn finalize_global(obj: *mut JSObject) {
|
|||
<*mut JSObject>::relocate(entry);
|
||||
}
|
||||
}
|
||||
let _: Box<ProtoOrIfaceArray> =
|
||||
Box::from_raw(protolist);
|
||||
let _: Box<ProtoOrIfaceArray> = Box::from_raw(protolist);
|
||||
}
|
||||
|
||||
/// Trace the resources held by reserved slots of a global object
|
||||
|
@ -595,23 +625,27 @@ pub unsafe fn trace_global(tracer: *mut JSTracer, obj: *mut JSObject) {
|
|||
let array = get_proto_or_iface_array(obj);
|
||||
for proto in (*array).iter() {
|
||||
if !proto.is_null() {
|
||||
trace_object(tracer, "prototype", &*(proto as *const *mut JSObject as *const Heap<*mut JSObject>));
|
||||
trace_object(tracer,
|
||||
"prototype",
|
||||
&*(proto as *const *mut JSObject as *const Heap<*mut JSObject>));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern fn wrap(cx: *mut JSContext,
|
||||
_existing: HandleObject,
|
||||
obj: HandleObject)
|
||||
-> *mut JSObject {
|
||||
unsafe extern "C" fn wrap(cx: *mut JSContext,
|
||||
_existing: HandleObject,
|
||||
obj: HandleObject)
|
||||
-> *mut JSObject {
|
||||
// FIXME terrible idea. need security wrappers
|
||||
// https://github.com/servo/servo/issues/2382
|
||||
WrapperNew(cx, obj, GetCrossCompartmentWrapper(), ptr::null(), false)
|
||||
}
|
||||
|
||||
unsafe extern fn pre_wrap(cx: *mut JSContext, _existing: HandleObject,
|
||||
obj: HandleObject, _object_passed_to_wrap: HandleObject)
|
||||
-> *mut JSObject {
|
||||
unsafe extern "C" fn pre_wrap(cx: *mut JSContext,
|
||||
_existing: HandleObject,
|
||||
obj: HandleObject,
|
||||
_object_passed_to_wrap: HandleObject)
|
||||
-> *mut JSObject {
|
||||
let _ac = JSAutoCompartment::new(cx, obj.get());
|
||||
JS_ObjectToOuterObject(cx, obj)
|
||||
}
|
||||
|
@ -623,7 +657,7 @@ pub static WRAP_CALLBACKS: JSWrapObjectCallbacks = JSWrapObjectCallbacks {
|
|||
};
|
||||
|
||||
/// Callback to outerize windows.
|
||||
pub unsafe extern fn outerize_global(_cx: *mut JSContext, obj: HandleObject) -> *mut JSObject {
|
||||
pub unsafe extern "C" fn outerize_global(_cx: *mut JSContext, obj: HandleObject) -> *mut JSObject {
|
||||
debug!("outerizing");
|
||||
let win = root_from_handleobject::<window::Window>(obj).unwrap();
|
||||
let context = win.browsing_context();
|
||||
|
@ -631,12 +665,17 @@ pub unsafe extern fn outerize_global(_cx: *mut JSContext, obj: HandleObject) ->
|
|||
}
|
||||
|
||||
/// Deletes the property `id` from `object`.
|
||||
pub unsafe fn delete_property_by_id(cx: *mut JSContext, object: HandleObject,
|
||||
id: HandleId, bp: *mut ObjectOpResult) -> bool {
|
||||
pub unsafe fn delete_property_by_id(cx: *mut JSContext,
|
||||
object: HandleObject,
|
||||
id: HandleId,
|
||||
bp: *mut ObjectOpResult)
|
||||
-> bool {
|
||||
JS_DeletePropertyById1(cx, object, id, bp)
|
||||
}
|
||||
|
||||
unsafe fn generic_call(cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal,
|
||||
unsafe fn generic_call(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
is_lenient: bool,
|
||||
call: unsafe extern fn(*const JSJitInfo, *mut JSContext,
|
||||
HandleObject, *mut libc::c_void, u32,
|
||||
|
@ -677,31 +716,36 @@ unsafe fn generic_call(cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal,
|
|||
}
|
||||
|
||||
/// Generic method of IDL interface.
|
||||
pub unsafe extern fn generic_method(cx: *mut JSContext,
|
||||
argc: libc::c_uint, vp: *mut JSVal)
|
||||
-> bool {
|
||||
pub unsafe extern "C" fn generic_method(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
generic_call(cx, argc, vp, false, CallJitMethodOp)
|
||||
}
|
||||
|
||||
/// Generic getter of IDL interface.
|
||||
pub unsafe extern fn generic_getter(cx: *mut JSContext,
|
||||
argc: libc::c_uint, vp: *mut JSVal)
|
||||
-> bool {
|
||||
pub unsafe extern "C" fn generic_getter(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
generic_call(cx, argc, vp, false, CallJitGetterOp)
|
||||
}
|
||||
|
||||
/// Generic lenient getter of IDL interface.
|
||||
pub unsafe extern fn generic_lenient_getter(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
pub unsafe extern "C" fn generic_lenient_getter(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
generic_call(cx, argc, vp, true, CallJitGetterOp)
|
||||
}
|
||||
|
||||
unsafe extern fn call_setter(info: *const JSJitInfo, cx: *mut JSContext,
|
||||
handle: HandleObject, this: *mut libc::c_void,
|
||||
argc: u32, vp: *mut JSVal)
|
||||
-> bool {
|
||||
unsafe extern "C" fn call_setter(info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
handle: HandleObject,
|
||||
this: *mut libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
if !CallJitSetterOp(info, cx, handle, this, argc, vp) {
|
||||
return false;
|
||||
}
|
||||
|
@ -710,23 +754,25 @@ unsafe extern fn call_setter(info: *const JSJitInfo, cx: *mut JSContext,
|
|||
}
|
||||
|
||||
/// Generic setter of IDL interface.
|
||||
pub unsafe extern fn generic_setter(cx: *mut JSContext,
|
||||
argc: libc::c_uint, vp: *mut JSVal)
|
||||
-> bool {
|
||||
pub unsafe extern "C" fn generic_setter(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
generic_call(cx, argc, vp, false, call_setter)
|
||||
}
|
||||
|
||||
/// Generic lenient setter of IDL interface.
|
||||
pub unsafe extern fn generic_lenient_setter(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
pub unsafe extern "C" fn generic_lenient_setter(cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal)
|
||||
-> bool {
|
||||
generic_call(cx, argc, vp, true, call_setter)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn instance_class_has_proto_at_depth(clasp: *const js::jsapi::Class,
|
||||
proto_id: u32,
|
||||
depth: u32) -> bool {
|
||||
depth: u32)
|
||||
-> bool {
|
||||
let domclass: *const DOMJSClass = clasp as *const _;
|
||||
let domclass = &*domclass;
|
||||
domclass.dom_class.interface_chain[depth as usize] as u32 == proto_id
|
||||
|
|
|
@ -50,8 +50,9 @@ pub trait WeakReferenceable: Reflectable + Sized {
|
|||
fn downgrade(&self) -> WeakRef<Self> {
|
||||
unsafe {
|
||||
let object = self.reflector().get_jsobject().get();
|
||||
let mut ptr =
|
||||
JS_GetReservedSlot(object, DOM_WEAK_SLOT).to_private() as *mut WeakBox<Self>;
|
||||
let mut ptr = JS_GetReservedSlot(object,
|
||||
DOM_WEAK_SLOT)
|
||||
.to_private() as *mut WeakBox<Self>;
|
||||
if ptr.is_null() {
|
||||
debug!("Creating new WeakBox holder for {:p}.", self);
|
||||
ptr = Box::into_raw(box WeakBox {
|
||||
|
@ -63,9 +64,13 @@ pub trait WeakReferenceable: Reflectable + Sized {
|
|||
let box_ = &*ptr;
|
||||
assert!(box_.value.get().is_some());
|
||||
let new_count = box_.count.get() + 1;
|
||||
debug!("Incrementing WeakBox refcount for {:p} to {}.", self, new_count);
|
||||
debug!("Incrementing WeakBox refcount for {:p} to {}.",
|
||||
self,
|
||||
new_count);
|
||||
box_.count.set(new_count);
|
||||
WeakRef { ptr: NonZero::new(ptr) }
|
||||
WeakRef {
|
||||
ptr: NonZero::new(ptr),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +100,9 @@ impl<T: WeakReferenceable> Clone for WeakRef<T> {
|
|||
let box_ = &**self.ptr;
|
||||
let new_count = box_.count.get() + 1;
|
||||
box_.count.set(new_count);
|
||||
WeakRef { ptr: self.ptr }
|
||||
WeakRef {
|
||||
ptr: self.ptr,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +150,9 @@ impl<T: WeakReferenceable> MutableWeakRef<T> {
|
|||
|
||||
/// Set the pointee of a mutable weak reference.
|
||||
pub fn set(&self, value: Option<&T>) {
|
||||
unsafe { *self.cell.get() = value.map(WeakRef::new); }
|
||||
unsafe {
|
||||
*self.cell.get() = value.map(WeakRef::new);
|
||||
}
|
||||
}
|
||||
|
||||
/// Root a mutable weak reference. Returns `None` if the object
|
||||
|
|
|
@ -19,13 +19,14 @@ pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult {
|
|||
// Step 2.
|
||||
Err(Error::Namespace)
|
||||
},
|
||||
XMLName::QName => Ok(())
|
||||
XMLName::QName => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate a namespace and qualified name and extract their parts.
|
||||
/// See https://dom.spec.whatwg.org/#validate-and-extract for details.
|
||||
pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
|
||||
pub fn validate_and_extract(namespace: Option<DOMString>,
|
||||
qualified_name: &str)
|
||||
-> Fallible<(Namespace, Option<Atom>, Atom)> {
|
||||
// Step 1.
|
||||
let namespace = namespace_from_domstring(namespace);
|
||||
|
@ -64,8 +65,7 @@ pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
|
|||
// Step 7.
|
||||
Err(Error::Namespace)
|
||||
},
|
||||
(ref ns, p) if ns != &ns!(XMLNS) &&
|
||||
(qualified_name == "xmlns" || p == Some("xmlns")) => {
|
||||
(ref ns, p) if ns != &ns!(XMLNS) && (qualified_name == "xmlns" || p == Some("xmlns")) => {
|
||||
// Step 8.
|
||||
Err(Error::Namespace)
|
||||
},
|
||||
|
@ -86,7 +86,7 @@ pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
|
|||
pub enum XMLName {
|
||||
QName,
|
||||
Name,
|
||||
InvalidXMLName
|
||||
InvalidXMLName,
|
||||
}
|
||||
|
||||
/// Check if an element name is valid. See http://www.w3.org/TR/xml/#NT-Name
|
||||
|
@ -95,33 +95,34 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
fn is_valid_start(c: char) -> bool {
|
||||
match c {
|
||||
':' |
|
||||
'A' ... 'Z' |
|
||||
'A'...'Z' |
|
||||
'_' |
|
||||
'a' ... 'z' |
|
||||
'\u{C0}' ... '\u{D6}' |
|
||||
'\u{D8}' ... '\u{F6}' |
|
||||
'\u{F8}' ... '\u{2FF}' |
|
||||
'\u{370}' ... '\u{37D}' |
|
||||
'\u{37F}' ... '\u{1FFF}' |
|
||||
'\u{200C}' ... '\u{200D}' |
|
||||
'\u{2070}' ... '\u{218F}' |
|
||||
'\u{2C00}' ... '\u{2FEF}' |
|
||||
'\u{3001}' ... '\u{D7FF}' |
|
||||
'\u{F900}' ... '\u{FDCF}' |
|
||||
'\u{FDF0}' ... '\u{FFFD}' |
|
||||
'\u{10000}' ... '\u{EFFFF}' => true,
|
||||
'a'...'z' |
|
||||
'\u{C0}'...'\u{D6}' |
|
||||
'\u{D8}'...'\u{F6}' |
|
||||
'\u{F8}'...'\u{2FF}' |
|
||||
'\u{370}'...'\u{37D}' |
|
||||
'\u{37F}'...'\u{1FFF}' |
|
||||
'\u{200C}'...'\u{200D}' |
|
||||
'\u{2070}'...'\u{218F}' |
|
||||
'\u{2C00}'...'\u{2FEF}' |
|
||||
'\u{3001}'...'\u{D7FF}' |
|
||||
'\u{F900}'...'\u{FDCF}' |
|
||||
'\u{FDF0}'...'\u{FFFD}' |
|
||||
'\u{10000}'...'\u{EFFFF}' => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_valid_continuation(c: char) -> bool {
|
||||
is_valid_start(c) || match c {
|
||||
is_valid_start(c) ||
|
||||
match c {
|
||||
'-' |
|
||||
'.' |
|
||||
'0' ... '9' |
|
||||
'0'...'9' |
|
||||
'\u{B7}' |
|
||||
'\u{300}' ... '\u{36F}' |
|
||||
'\u{203F}' ... '\u{2040}' => true,
|
||||
'\u{300}'...'\u{36F}' |
|
||||
'\u{203F}'...'\u{2040}' => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +150,7 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
if c == ':' {
|
||||
match seen_colon {
|
||||
true => non_qname_colons = true,
|
||||
false => seen_colon = true
|
||||
false => seen_colon = true,
|
||||
}
|
||||
}
|
||||
last = c
|
||||
|
@ -161,7 +162,7 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
|
||||
match non_qname_colons {
|
||||
false => XMLName::QName,
|
||||
true => XMLName::Name
|
||||
true => XMLName::Name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue