mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
WIP
This commit is contained in:
@@ -3135,6 +3135,13 @@ rooted!(in(*cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
|
||||
%s;
|
||||
assert!(!prototype_proto.is_null());""" % getPrototypeProto)]
|
||||
|
||||
if self.descriptor.hasNamedPropertiesObject():
|
||||
assert not self.haveUnscopables
|
||||
code.append(CGGeneric("""\
|
||||
rooted!(in(*cx) let mut prototype_proto_proto = prototype_proto.get());
|
||||
dom::types::%s::create_named_properties_object(cx, prototype_proto_proto.handle(), prototype_proto.handle_mut());
|
||||
assert!(!prototype_proto.is_null());""" % name))
|
||||
|
||||
properties = {
|
||||
"id": name,
|
||||
"unscopables": "unscopable_names" if self.haveUnscopables else "&[]",
|
||||
@@ -5905,7 +5912,7 @@ class CGInterfaceTrait(CGThing):
|
||||
),
|
||||
rettype)
|
||||
|
||||
if descriptor.proxy:
|
||||
if descriptor.proxy or descriptor.isGlobal():
|
||||
for name, operation in descriptor.operations.iteritems():
|
||||
if not operation or operation.isStringifier():
|
||||
continue
|
||||
|
||||
@@ -280,7 +280,8 @@ class Descriptor(DescriptorProvider):
|
||||
continue
|
||||
|
||||
def addIndexedOrNamedOperation(operation, m):
|
||||
self.proxy = True
|
||||
if not self.isGlobal():
|
||||
self.proxy = True
|
||||
if m.isIndexed():
|
||||
operation = 'Indexed' + operation
|
||||
else:
|
||||
@@ -366,6 +367,12 @@ class Descriptor(DescriptorProvider):
|
||||
def internalNameFor(self, name):
|
||||
return self._internalNames.get(name, name)
|
||||
|
||||
def hasNamedPropertiesObject(self):
|
||||
if self.interface.isExternal():
|
||||
return False
|
||||
|
||||
return self.isGlobal() and self.supportsNamedProperties()
|
||||
|
||||
def supportsNamedProperties(self):
|
||||
return self.operations['NamedGetter'] is not None
|
||||
|
||||
|
||||
@@ -4705,7 +4705,7 @@ impl DocumentMethods for Document {
|
||||
#[allow(unsafe_code)]
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
||||
fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> {
|
||||
if name.is_empty() {
|
||||
if name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let name = Atom::from(name);
|
||||
@@ -4746,10 +4746,10 @@ impl DocumentMethods for Document {
|
||||
|
||||
// Step 4.
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
struct NamedElementFilter {
|
||||
struct DocumentNamedGetter {
|
||||
name: Atom,
|
||||
}
|
||||
impl CollectionFilter for NamedElementFilter {
|
||||
impl CollectionFilter for DocumentNamedGetter {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
let type_ = match elem.upcast::<Node>().type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
|
||||
@@ -4771,7 +4771,7 @@ impl DocumentMethods for Document {
|
||||
let collection = HTMLCollection::create(
|
||||
self.window(),
|
||||
self.upcast(),
|
||||
Box::new(NamedElementFilter { name }),
|
||||
Box::new(DocumentNamedGetter { name }),
|
||||
);
|
||||
unsafe {
|
||||
Some(NonNull::new_unchecked(
|
||||
@@ -4786,6 +4786,9 @@ impl DocumentMethods for Document {
|
||||
|
||||
let name_map = self.name_map.borrow();
|
||||
for (name, elements) in &*name_map {
|
||||
if name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut name_iter = elements
|
||||
.iter()
|
||||
.filter(|elem| is_named_element_with_name_attribute(elem));
|
||||
@@ -4795,6 +4798,9 @@ impl DocumentMethods for Document {
|
||||
}
|
||||
let id_map = self.id_map.borrow();
|
||||
for (id, elements) in &*id_map {
|
||||
if id.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut id_iter = elements
|
||||
.iter()
|
||||
.filter(|elem| is_named_element_with_id_attribute(elem));
|
||||
|
||||
@@ -44,8 +44,7 @@
|
||||
optional DOMString features = "");
|
||||
//getter WindowProxy (unsigned long index);
|
||||
|
||||
// https://github.com/servo/servo/issues/14453
|
||||
// getter object (DOMString name);
|
||||
getter object (DOMString name);
|
||||
|
||||
// the user agent
|
||||
readonly attribute Navigator navigator;
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::dom::bindings::cell::{DomRefCell, Ref};
|
||||
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
|
||||
DocumentMethods, DocumentReadyState,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryBinding::HistoryMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
|
||||
ImageBitmapOptions, ImageBitmapSource,
|
||||
@@ -19,7 +20,7 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::{
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
|
||||
use crate::dom::bindings::codegen::UnionTypes::{RequestOrUSVString, StringOrFunction};
|
||||
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
|
||||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::refcounted::Trusted;
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
@@ -40,6 +41,8 @@ use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::hashchangeevent::HashChangeEvent;
|
||||
use crate::dom::history::History;
|
||||
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||
use crate::dom::htmliframeelement::HTMLIFrameElement;
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::location::Location;
|
||||
use crate::dom::mediaquerylist::{MediaQueryList, MediaQueryListMatchState};
|
||||
@@ -71,6 +74,7 @@ use crate::task_manager::TaskManager;
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
use crate::timers::{IsInterval, TimerCallback};
|
||||
use crate::webdriver_handlers::jsval_to_webdriver;
|
||||
use crate::window_named_properties;
|
||||
use app_units::Au;
|
||||
use backtrace::Backtrace;
|
||||
use base64;
|
||||
@@ -94,7 +98,9 @@ use js::jsapi::{GCReason, StackFormat, JS_GC};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::jsval::{JSVal, NullValue};
|
||||
use js::rust::wrappers::JS_DefineProperty;
|
||||
use js::rust::{CustomAutoRooter, CustomAutoRooterGuard, HandleValue};
|
||||
use js::rust::{
|
||||
CustomAutoRooter, CustomAutoRooterGuard, HandleObject, HandleValue, MutableHandleObject,
|
||||
};
|
||||
use media::WindowGLContext;
|
||||
use msg::constellation_msg::{BrowsingContextId, PipelineId};
|
||||
use net_traits::image_cache::{ImageCache, ImageResponder, ImageResponse};
|
||||
@@ -120,17 +126,20 @@ use script_traits::{
|
||||
use script_traits::{TimerSchedulerMsg, WebrenderIpcSender, WindowSizeData, WindowSizeType};
|
||||
use selectors::attr::CaseSensitivity;
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use servo_atoms::Atom;
|
||||
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
|
||||
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
||||
use std::borrow::Cow;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::Cell;
|
||||
use std::cmp;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::default::Default;
|
||||
use std::env;
|
||||
use std::io::{stderr, stdout, Write};
|
||||
use std::mem;
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -1381,9 +1390,164 @@ impl WindowMethods for Window {
|
||||
}
|
||||
rval.get()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
|
||||
#[allow(unsafe_code)]
|
||||
fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> {
|
||||
if name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let name = Atom::from(name);
|
||||
let document = self.Document();
|
||||
|
||||
// TODO: Handle the document-tree child browsing context name property set.
|
||||
|
||||
// Step 1.
|
||||
let elements_with_name = document.get_elements_with_name(&name);
|
||||
let name_iter = elements_with_name
|
||||
.iter()
|
||||
.filter(|elem| is_named_element_with_name_attribute(elem));
|
||||
let elements_with_id = document.get_elements_with_id(&name);
|
||||
let id_iter = elements_with_id
|
||||
.iter()
|
||||
.filter(|elem| is_named_element_with_id_attribute(elem));
|
||||
|
||||
// Step 2.
|
||||
for elem in id_iter.clone() {
|
||||
if let Some(nested_window_proxy) = elem
|
||||
.downcast::<HTMLIFrameElement>()
|
||||
.and_then(|iframe| iframe.GetContentWindow())
|
||||
{
|
||||
unsafe {
|
||||
return Some(NonNull::new_unchecked(
|
||||
nested_window_proxy.reflector().get_jsobject().get(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut elements = name_iter.chain(id_iter);
|
||||
|
||||
let first = elements.next()?;
|
||||
|
||||
if elements.next().is_none() {
|
||||
// Step 3.
|
||||
unsafe {
|
||||
return Some(NonNull::new_unchecked(
|
||||
first.reflector().get_jsobject().get(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4.
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
struct WindowNamedGetter {
|
||||
name: Atom,
|
||||
}
|
||||
impl CollectionFilter for WindowNamedGetter {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
let type_ = match elem.upcast::<Node>().type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
|
||||
_ => return false,
|
||||
};
|
||||
if elem.get_id().as_ref() == Some(&self.name) {
|
||||
return true;
|
||||
}
|
||||
match type_ {
|
||||
HTMLElementTypeId::HTMLEmbedElement |
|
||||
HTMLElementTypeId::HTMLFormElement |
|
||||
HTMLElementTypeId::HTMLImageElement |
|
||||
HTMLElementTypeId::HTMLObjectElement => {
|
||||
elem.get_name().as_ref() == Some(&self.name)
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
let collection = HTMLCollection::create(
|
||||
self,
|
||||
document.upcast(),
|
||||
Box::new(WindowNamedGetter { name }),
|
||||
);
|
||||
unsafe {
|
||||
Some(NonNull::new_unchecked(
|
||||
collection.reflector().get_jsobject().get(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
||||
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
||||
let mut names_with_first_named_element_map: HashMap<&Atom, &Element> = HashMap::new();
|
||||
|
||||
let name_map = self.name_map.borrow();
|
||||
for (name, elements) in &*name_map {
|
||||
if name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut name_iter = elements
|
||||
.iter()
|
||||
.filter(|elem| is_named_element_with_name_attribute(elem));
|
||||
if let Some(first) = name_iter.next() {
|
||||
names_with_first_named_element_map.insert(name, first);
|
||||
}
|
||||
}
|
||||
let id_map = self.id_map.borrow();
|
||||
for (id, elements) in &*id_map {
|
||||
if id.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut id_iter = elements
|
||||
.iter()
|
||||
.filter(|elem| is_named_element_with_id_attribute(elem));
|
||||
if let Some(first) = id_iter.next() {
|
||||
match names_with_first_named_element_map.entry(id) {
|
||||
Entry::Vacant(entry) => drop(entry.insert(first)),
|
||||
Entry::Occupied(mut entry) => {
|
||||
if first.upcast::<Node>().is_before(entry.get().upcast()) {
|
||||
*entry.get_mut() = first;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut names_with_first_named_element_vec: Vec<(&Atom, &Element)> =
|
||||
names_with_first_named_element_map
|
||||
.iter()
|
||||
.map(|(k, v)| (*k, *v))
|
||||
.collect();
|
||||
names_with_first_named_element_vec.sort_unstable_by(|a, b| {
|
||||
if a.1 == b.1 {
|
||||
// This can happen if an img has an id different from its name,
|
||||
// spec does not say which string to put first.
|
||||
a.0.cmp(&b.0)
|
||||
} else if a.1.upcast::<Node>().is_before(b.1.upcast::<Node>()) {
|
||||
cmp::Ordering::Less
|
||||
} else {
|
||||
cmp::Ordering::Greater
|
||||
}
|
||||
});
|
||||
|
||||
names_with_first_named_element_vec
|
||||
.iter()
|
||||
.map(|(k, _v)| DOMString::from(&***k))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
// https://heycam.github.io/webidl/#named-properties-object
|
||||
// https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
|
||||
#[allow(unsafe_code)]
|
||||
pub fn create_named_properties_object(
|
||||
cx: JSContext,
|
||||
proto: HandleObject,
|
||||
object: MutableHandleObject,
|
||||
) {
|
||||
window_named_properties::create(cx, proto, object)
|
||||
}
|
||||
|
||||
pub(crate) fn set_current_event(&self, event: Option<&Event>) -> Option<DomRoot<Event>> {
|
||||
let current = self
|
||||
.current_event
|
||||
@@ -2654,3 +2818,21 @@ impl ParseErrorReporter for CSSErrorReporter {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn is_named_element_with_name_attribute(elem: &Element) -> bool {
|
||||
let type_ = match elem.upcast::<Node>().type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
|
||||
_ => return false,
|
||||
};
|
||||
match type_ {
|
||||
HTMLElementTypeId::HTMLEmbedElement |
|
||||
HTMLElementTypeId::HTMLFormElement |
|
||||
HTMLElementTypeId::HTMLImageElement |
|
||||
HTMLElementTypeId::HTMLObjectElement => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_named_element_with_id_attribute(elem: &Element) -> bool {
|
||||
elem.is_html_element()
|
||||
}
|
||||
|
||||
@@ -111,6 +111,8 @@ mod timers;
|
||||
mod unpremultiplytable;
|
||||
#[warn(deprecated)]
|
||||
mod webdriver_handlers;
|
||||
#[warn(deprecated)]
|
||||
mod window_named_properties;
|
||||
|
||||
pub use init::init;
|
||||
pub use script_runtime::JSEngineSetup;
|
||||
|
||||
205
components/script/window_named_properties.rs
Normal file
205
components/script/window_named_properties.rs
Normal file
@@ -0,0 +1,205 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use crate::dom::bindings::proxyhandler::fill_property_descriptor;
|
||||
use crate::dom::bindings::root::Root;
|
||||
use crate::dom::bindings::utils::has_property_on_prototype;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::js::conversions::ToJSValConvertible;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use js::conversions::jsstr_to_string;
|
||||
use js::error::throw_type_error;
|
||||
use js::glue::RUST_JSID_TO_STRING;
|
||||
use js::glue::{CreateProxyHandler, NewProxyObject, ProxyTraps, RUST_JSID_IS_STRING};
|
||||
use js::jsapi::JS_SetImmutablePrototype;
|
||||
use js::jsapi::{Handle, HandleObject, JSClass, JSContext, JSErrNum, UndefinedHandleValue};
|
||||
use js::jsapi::{
|
||||
HandleId, JSClass_NON_NATIVE, MutableHandle, ObjectOpResult, PropertyDescriptor,
|
||||
ProxyClassExtension, ProxyClassOps, ProxyObjectOps, JSCLASS_DELAY_METADATA_BUILDER,
|
||||
JSCLASS_IS_PROXY, JSCLASS_RESERVED_SLOTS_MASK, JSCLASS_RESERVED_SLOTS_SHIFT,
|
||||
};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::IntoHandle;
|
||||
use js::rust::{Handle as RustHandle, MutableHandle as RustMutableHandle};
|
||||
use js::rust::{HandleObject as RustHandleObject, MutableHandleObject as RustMutableHandleObject};
|
||||
use libc;
|
||||
use std::ptr;
|
||||
|
||||
struct SyncWrapper(*const libc::c_void);
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl Sync for SyncWrapper {}
|
||||
|
||||
lazy_static! {
|
||||
static ref HANDLER: SyncWrapper = {
|
||||
let traps = ProxyTraps {
|
||||
enter: None,
|
||||
getOwnPropertyDescriptor: Some(get_own_property_descriptor),
|
||||
defineProperty: Some(define_property),
|
||||
ownPropertyKeys: None,
|
||||
delete_: Some(delete),
|
||||
enumerate: None,
|
||||
getPrototypeIfOrdinary: None,
|
||||
preventExtensions: Some(prevent_extensions),
|
||||
isExtensible: Some(is_extensible),
|
||||
has: None,
|
||||
get: None,
|
||||
set: None,
|
||||
call: None,
|
||||
construct: None,
|
||||
hasOwn: None,
|
||||
getOwnEnumerablePropertyKeys: None,
|
||||
nativeCall: None,
|
||||
hasInstance: None,
|
||||
objectClassIs: None,
|
||||
className: Some(class_name),
|
||||
fun_toString: None,
|
||||
boxedValue_unbox: None,
|
||||
defaultValue: None,
|
||||
trace: None,
|
||||
finalize: None,
|
||||
objectMoved: None,
|
||||
isCallable: None,
|
||||
isConstructor: None,
|
||||
};
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe {
|
||||
SyncWrapper(CreateProxyHandler(&traps, ptr::null()))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn get_own_property_descriptor(
|
||||
cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
desc: MutableHandle<PropertyDescriptor>,
|
||||
) -> bool {
|
||||
let cx = SafeJSContext::from_ptr(cx);
|
||||
if !RUST_JSID_IS_STRING(id) {
|
||||
// Nothing to do if we're resolving a non-string property.
|
||||
return true;
|
||||
}
|
||||
|
||||
let mut found = false;
|
||||
if !has_property_on_prototype(
|
||||
*cx,
|
||||
RustHandle::from_raw(proxy),
|
||||
RustHandle::from_raw(id),
|
||||
&mut found,
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if found {
|
||||
return true;
|
||||
}
|
||||
|
||||
let s = jsstr_to_string(*cx, RUST_JSID_TO_STRING(id));
|
||||
if s.is_empty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
let window = Root::downcast::<Window>(GlobalScope::from_object(proxy.get()))
|
||||
.expect("global is not a window");
|
||||
if let Some(obj) = window.NamedGetter(cx, s.into()) {
|
||||
rooted!(in(*cx) let mut val = UndefinedValue());
|
||||
obj.to_jsval(*cx, val.handle_mut());
|
||||
fill_property_descriptor(RustMutableHandle::from_raw(desc), proxy.get(), val.get(), 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn define_property(
|
||||
cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
_id: HandleId,
|
||||
_desc: Handle<PropertyDescriptor>,
|
||||
_result: *mut ObjectOpResult,
|
||||
) -> bool {
|
||||
throw_type_error(
|
||||
cx,
|
||||
"Not allowed to define a property on the named properties object.",
|
||||
);
|
||||
false
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn delete(
|
||||
_cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
_id: HandleId,
|
||||
result: *mut ObjectOpResult,
|
||||
) -> bool {
|
||||
(*result).code_ = JSErrNum::JSMSG_CANT_DELETE_WINDOW_NAMED_PROPERTY as usize;
|
||||
true
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn prevent_extensions(
|
||||
_cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
result: *mut ObjectOpResult,
|
||||
) -> bool {
|
||||
(*result).code_ = JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS as usize;
|
||||
true
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn is_extensible(
|
||||
_cx: *mut JSContext,
|
||||
_proxy: HandleObject,
|
||||
extensible: *mut bool,
|
||||
) -> bool {
|
||||
*extensible = true;
|
||||
true
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn class_name(_cx: *mut JSContext, _proxy: HandleObject) -> *const i8 {
|
||||
&b"WindowProperties" as *const _ as *const i8
|
||||
}
|
||||
|
||||
// Maybe this should be a DOMJSClass. See https://bugzilla.mozilla.org/show_bug.cgi?id=787070
|
||||
static CLASS: JSClass = JSClass {
|
||||
name: b"WindowProperties\0" as *const u8 as *const libc::c_char,
|
||||
flags: JSClass_NON_NATIVE |
|
||||
JSCLASS_IS_PROXY |
|
||||
JSCLASS_DELAY_METADATA_BUILDER |
|
||||
((1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), /* JSCLASS_HAS_RESERVED_SLOTS(1) */
|
||||
cOps: &ProxyClassOps,
|
||||
spec: ptr::null(),
|
||||
ext: &ProxyClassExtension,
|
||||
oOps: &ProxyObjectOps,
|
||||
};
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn create(
|
||||
cx: SafeJSContext,
|
||||
proto: RustHandleObject,
|
||||
mut properties_obj: RustMutableHandleObject,
|
||||
) {
|
||||
unsafe {
|
||||
properties_obj.set(NewProxyObject(
|
||||
*cx,
|
||||
HANDLER.0,
|
||||
UndefinedHandleValue,
|
||||
proto.get(),
|
||||
// TODO: pass proper clasp
|
||||
&CLASS,
|
||||
true,
|
||||
));
|
||||
assert!(!properties_obj.get().is_null());
|
||||
let mut succeeded = false;
|
||||
assert!(JS_SetImmutablePrototype(
|
||||
*cx,
|
||||
properties_obj.handle().into_handle(),
|
||||
&mut succeeded
|
||||
));
|
||||
assert!(succeeded);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user