diff options
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 86 | ||||
-rw-r--r-- | components/script/dom/bindings/constant.rs | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 16 | ||||
-rw-r--r-- | components/script/dom/bindings/error.rs | 10 | ||||
-rw-r--r-- | components/script/dom/bindings/interface.rs | 58 | ||||
-rw-r--r-- | components/script/dom/bindings/mozmap.rs | 22 | ||||
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 22 | ||||
-rw-r--r-- | components/script/dom/bindings/structuredclone.rs | 62 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 17 | ||||
-rw-r--r-- | components/script/dom/bindings/utils.rs | 22 | ||||
-rw-r--r-- | components/script/dom/bindings/weakref.rs | 13 |
11 files changed, 180 insertions, 152 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 6015a4b126a..449fda3b7ea 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1775,7 +1775,7 @@ class AttrDefiner(PropertyDefiner): if len(array) == 0: return "" - flags = "JSPROP_ENUMERATE | JSPROP_SHARED" + flags = "JSPROP_ENUMERATE" if self.unforgeable: flags += " | JSPROP_PERMANENT" @@ -1822,15 +1822,18 @@ class AttrDefiner(PropertyDefiner): ' JSPropertySpec {\n' ' name: %s as *const u8 as *const libc::c_char,\n' ' flags: (%s) as u8,\n' - ' getter: %s,\n' - ' setter: %s\n' - ' }', - ' JSPropertySpec {\n' - ' name: 0 as *const libc::c_char,\n' - ' flags: 0,\n' - ' getter: JSNativeWrapper { op: None, info: 0 as *const JSJitInfo },\n' - ' setter: JSNativeWrapper { op: None, info: 0 as *const JSJitInfo }\n' + ' __bindgen_anon_1: JSPropertySpec__bindgen_ty_1 {\n' + ' accessors: JSPropertySpec__bindgen_ty_1__bindgen_ty_1 {\n' + ' getter: JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 {\n' + ' native: %s,\n' + ' },\n' + ' setter: JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2 {\n' + ' native: %s,\n' + ' }\n' + ' }\n' + ' }\n' ' }', + ' JSPropertySpec::ZERO', 'JSPropertySpec', PropertyDefiner.getControllingCondition, specData) @@ -2124,7 +2127,7 @@ class CGDOMJSClass(CGThing): "domClass": DOMClass(self.descriptor), "enumerateHook": "None", "finalizeHook": FINALIZE_HOOK_NAME, - "flags": "0", + "flags": "JSCLASS_FOREGROUND_FINALIZE", "name": str_to_const_array(self.descriptor.interface.identifier.name), "resolveHook": "None", "slots": "1", @@ -2133,7 +2136,7 @@ class CGDOMJSClass(CGThing): if self.descriptor.isGlobal(): assert not self.descriptor.weakReferenceable args["enumerateHook"] = "Some(enumerate_global)" - args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL" + args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL | JSCLASS_FOREGROUND_FINALIZE" args["slots"] = "JSCLASS_GLOBAL_SLOT_COUNT + 1" args["resolveHook"] = "Some(resolve_global)" args["traceHook"] = "js::jsapi::JS_GlobalObjectTraceHook" @@ -2143,9 +2146,8 @@ class CGDOMJSClass(CGThing): static CLASS_OPS: js::jsapi::JSClassOps = js::jsapi::JSClassOps { addProperty: None, delProperty: None, - getProperty: None, - setProperty: None, enumerate: %(enumerateHook)s, + newEnumerate: None, resolve: %(resolveHook)s, mayResolve: None, finalize: Some(%(finalizeHook)s), @@ -2583,10 +2585,11 @@ def CreateBindingJSObject(descriptor, parent=None): let handler = RegisterBindings::PROXY_HANDLERS[PrototypeList::Proxies::%s as usize]; rooted!(in(cx) let private = PrivateValue(raw as *const libc::c_void)); let obj = NewProxyObject(cx, handler, - private.handle(), + Handle::from_raw(UndefinedHandleValue), proto.get(), %s.get(), ptr::null_mut(), ptr::null_mut()); assert!(!obj.is_null()); +SetProxyReservedSlot(obj, 0, &private.get()); rooted!(in(cx) let obj = obj);\ """ % (descriptor.name, parent) else: @@ -2594,11 +2597,13 @@ rooted!(in(cx) let obj = obj);\ " cx, &Class.base as *const JSClass, proto.handle()));\n" "assert!(!obj.is_null());\n" "\n" - "JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT,\n" - " PrivateValue(raw as *const libc::c_void));") + "let val = PrivateValue(raw as *const libc::c_void);\n" + "\n" + "JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT, &val);") if descriptor.weakReferenceable: create += """ -JS_SetReservedSlot(obj.get(), DOM_WEAK_SLOT, PrivateValue(ptr::null()));""" +let val = PrivateValue(ptr::null()); +JS_SetReservedSlot(obj.get(), DOM_WEAK_SLOT, &val);""" return create @@ -2652,9 +2657,10 @@ ensure_expando_object(cx, obj.handle().into(), expando.handle_mut()); else: copyFunc = "JS_InitializePropertiesFromCompatibleNativeObject" copyCode += """\ +let mut slot = UndefinedValue(); +JS_GetReservedSlot(proto.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &mut slot); rooted!(in(cx) let mut unforgeable_holder = ptr::null_mut::<JSObject>()); -unforgeable_holder.handle_mut().set( - JS_GetReservedSlot(proto.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT).to_object()); +unforgeable_holder.handle_mut().set(slot.to_object()); assert!(%(copyFunc)s(cx, %(obj)s.handle(), unforgeable_holder.handle())); """ % {'copyFunc': copyFunc, 'obj': obj} @@ -3013,7 +3019,7 @@ assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null()); CGGeneric(fill( """ assert!(${defineFn}(cx, prototype.handle(), ${prop}, aliasedVal.handle(), - JSPROP_ENUMERATE, None, None)); + JSPROP_ENUMERATE as u32)); """, defineFn=defineFn, prop=prop)) @@ -3078,8 +3084,8 @@ assert!(!unforgeable_holder.is_null()); """ % {'holderClass': holderClass, 'holderProto': holderProto})) code.append(InitUnforgeablePropertiesOnHolder(self.descriptor, self.properties)) code.append(CGGeneric("""\ -JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, - ObjectValue(unforgeable_holder.get()))""")) +let val = ObjectValue(unforgeable_holder.get()); +JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &val)""")) return CGList(code, "\n") @@ -3533,11 +3539,13 @@ class CGAbstractStaticBindingMethod(CGAbstractMethod): self.exposureSet = descriptor.interface.exposureSet def definition_body(self): - preamble = "let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n" + preamble = """\ +let args = CallArgs::from_vp(vp, argc); +let global = GlobalScope::from_object(args.callee()); +""" if len(self.exposureSet) == 1: - preamble += """ -let global = DomRoot::downcast::<dom::types::%s>(global).unwrap(); -""" % list(self.exposureSet)[0] + preamble += ("let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();\n" % + list(self.exposureSet)[0]) return CGList([CGGeneric(preamble), self.generate_code()]) def generate_code(self): @@ -3741,7 +3749,7 @@ class CGSpecializedReplaceableSetter(CGSpecializedSetter): assert all(ord(c) < 128 for c in name) return CGGeneric("""\ JS_DefineProperty(cx, obj, %s as *const u8 as *const libc::c_char, - HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE, None, None)""" % name) + HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE as u32)""" % name) class CGMemberJITInfo(CGThing): @@ -4959,7 +4967,9 @@ class CGProxyUnwrap(CGAbstractMethod): obj = js::UnwrapObject(obj); }*/ //MOZ_ASSERT(IsProxy(obj)); -let box_ = GetProxyPrivate(obj.get()).to_private() as *const %s; + let mut slot = UndefinedValue(); + GetProxyReservedSlot(obj.get(), 0, &mut slot); + let box_ = slot.to_private() as *const %s; return box_;""" % self.descriptor.concreteType) @@ -4985,7 +4995,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): attrs += " | JSPROP_READONLY" # FIXME(#11868) Should assign to desc.value, desc.get() is a copy. fillDescriptor = ("desc.get().value = result_root.get();\n" - "fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), %s);\n" + "fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), (%s) as u32);\n" "return true;" % attrs) templateValues = { 'jsvalRef': 'result_root.handle_mut()', @@ -5011,7 +5021,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): attrs = "0" # FIXME(#11868) Should assign to desc.value, desc.get() is a copy. fillDescriptor = ("desc.get().value = result_root.get();\n" - "fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), %s);\n" + "fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), (%s) as u32);\n" "return true;" % attrs) templateValues = { 'jsvalRef': 'result_root.handle_mut()', @@ -5425,7 +5435,9 @@ finalize_global(obj); """ elif descriptor.weakReferenceable: release += """\ -let weak_box_ptr = JS_GetReservedSlot(obj, DOM_WEAK_SLOT).to_private() as *mut WeakBox<%s>; +let mut slot = UndefinedValue(); +JS_GetReservedSlot(obj, DOM_WEAK_SLOT, &mut slot); +let weak_box_ptr = slot.to_private() as *mut WeakBox<%s>; if !weak_box_ptr.is_null() { let count = { let weak_box = &*weak_box_ptr; @@ -5736,6 +5748,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::jsapi::INTERNED_STRING_TO_JSID', 'js::jsapi::IsCallable', 'js::jsapi::JSAutoCompartment', + 'js::jsapi::JSCLASS_FOREGROUND_FINALIZE', 'js::jsapi::JSCLASS_RESERVED_SLOTS_SHIFT', 'js::jsapi::JSClass', 'js::jsapi::JSContext', @@ -5757,8 +5770,11 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::jsapi::JSPROP_ENUMERATE', 'js::jsapi::JSPROP_PERMANENT', 'js::jsapi::JSPROP_READONLY', - 'js::jsapi::JSPROP_SHARED', 'js::jsapi::JSPropertySpec', + 'js::jsapi::JSPropertySpec__bindgen_ty_1', + 'js::jsapi::JSPropertySpec__bindgen_ty_1__bindgen_ty_1', + 'js::jsapi::JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1', + 'js::jsapi::JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2', 'js::jsapi::JSString', 'js::jsapi::JSTracer', 'js::jsapi::JSType', @@ -5778,7 +5794,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::rust::wrappers::JS_GetProperty', 'js::jsapi::JS_GetPropertyById', 'js::jsapi::JS_GetPropertyDescriptorById', - 'js::jsapi::JS_GetReservedSlot', + 'js::glue::JS_GetReservedSlot', 'js::jsapi::JS_HasProperty', 'js::jsapi::JS_HasPropertyById', 'js::rust::wrappers::JS_InitializePropertiesFromCompatibleNativeObject', @@ -5813,12 +5829,14 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::jsval::ObjectOrNullValue', 'js::jsval::PrivateValue', 'js::jsval::UndefinedValue', + 'js::jsapi::UndefinedHandleValue', 'js::glue::AppendToAutoIdVector', 'js::glue::CallJitGetterOp', 'js::glue::CallJitMethodOp', 'js::glue::CallJitSetterOp', 'js::glue::CreateProxyHandler', - 'js::glue::GetProxyPrivate', + 'js::glue::GetProxyReservedSlot', + 'js::glue::SetProxyReservedSlot', 'js::rust::wrappers::NewProxyObject', 'js::glue::ProxyTraps', 'js::glue::RUST_JSID_IS_INT', diff --git a/components/script/dom/bindings/constant.rs b/components/script/dom/bindings/constant.rs index 22ea8d2f55c..b30247f887b 100644 --- a/components/script/dom/bindings/constant.rs +++ b/components/script/dom/bindings/constant.rs @@ -61,8 +61,6 @@ pub unsafe fn define_constants( 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) as u32)); } } diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 6642f65aed5..0576298d49d 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -45,12 +45,13 @@ pub use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvert pub use js::conversions::ConversionBehavior; use js::conversions::latin1_to_string; use js::error::throw_type_error; -use js::glue::{GetProxyPrivate, IsWrapper}; +use js::glue::{IsWrapper, UnwrapObject}; use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT}; -use js::glue::{UnwrapObject, RUST_JSID_IS_STRING, RUST_JSID_TO_STRING}; +use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING}; +use js::glue::GetProxyReservedSlot; +use js::glue::JS_GetReservedSlot; use js::jsapi::{Heap, JSContext, JSObject, JSString}; -use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetReservedSlot}; -use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsExceptionPending}; +use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetTwoByteStringCharsAndLength, JS_IsExceptionPending}; use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars}; use js::jsval::{ObjectValue, StringValue, UndefinedValue}; use js::rust::{HandleId, HandleObject, HandleValue, MutableHandleValue}; @@ -347,11 +348,12 @@ pub const DOM_OBJECT_SLOT: u32 = 0; /// Get the private pointer of a DOM object from a given reflector. pub unsafe fn private_from_object(obj: *mut JSObject) -> *const libc::c_void { - let value = if is_dom_object(obj) { - JS_GetReservedSlot(obj, DOM_OBJECT_SLOT) + let mut value = UndefinedValue(); + if is_dom_object(obj) { + JS_GetReservedSlot(obj, DOM_OBJECT_SLOT, &mut value); } else { debug_assert!(is_dom_proxy(obj)); - GetProxyPrivate(obj) + GetProxyReservedSlot(obj, 0, &mut value); }; if value.is_undefined() { ptr::null() diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index dee6e9766f0..c953df65c1d 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -157,7 +157,7 @@ impl ErrorInfo { } let filename = { - let filename = (*report).filename as *const u8; + let filename = (*report)._base.filename as *const u8; if !filename.is_null() { let length = (0..).find(|idx| *filename.offset(*idx) == 0).unwrap(); let filename = from_raw_parts(filename, length as usize); @@ -167,14 +167,14 @@ impl ErrorInfo { } }; - let lineno = (*report).lineno; - let column = (*report).column; + let lineno = (*report)._base.lineno; + let column = (*report)._base.column; let message = { - let message = (*report).ucmessage; + let message = (*report)._base.message_.data_ as *const u8; let length = (0..).find(|idx| *message.offset(*idx) == 0).unwrap(); let message = from_raw_parts(message, length as usize); - String::from_utf16_lossy(message) + String::from_utf8_lossy(message).into_owned() }; Some(ErrorInfo { diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index d7e1c371f38..60fb712b831 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -16,7 +16,7 @@ use js::jsapi::{Class, ClassOps, CompartmentOptions}; use js::jsapi::{GetGlobalForObjectCrossCompartment, GetWellKnownSymbol}; use js::jsapi::{JSAutoCompartment, JSClass, JSContext, JSFunctionSpec, JSObject, JSFUN_CONSTRUCTOR}; use js::jsapi::{JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING}; -use js::jsapi::{JSPropertySpec, JSString, JSTracer, JSVersion, JS_AtomizeAndPinString}; +use js::jsapi::{JSPropertySpec, JSString, JSTracer, JS_AtomizeAndPinString}; use js::jsapi::{JS_GetFunctionObject, JS_NewFunction, JS_NewGlobalObject}; use js::jsapi::{JS_NewObject, JS_NewPlainObject}; use js::jsapi::{JS_NewStringCopyN, JS_SetReservedSlot}; @@ -27,11 +27,12 @@ use js::jsapi::MutableHandleValue as RawMutableHandleValue; use js::jsval::{JSVal, PrivateValue}; use js::rust::{HandleObject, HandleValue, MutableHandleObject}; use js::rust::{define_methods, define_properties, get_object_class}; -use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2}; -use js::rust::wrappers::{JS_DefineProperty4, JS_DefinePropertyById3}; +use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty2}; +use js::rust::wrappers::{JS_DefineProperty3, JS_DefineProperty4, JS_DefinePropertyById4}; use js::rust::wrappers::{JS_FireOnNewGlobalObject, JS_GetPrototype}; use js::rust::wrappers::{JS_LinkConstructorAndPrototype, JS_NewObjectWithUniqueType}; use libc; +use std::convert::TryFrom; use std::ptr; /// The class of a non-callback interface object. @@ -92,9 +93,8 @@ impl InterfaceConstructorBehavior { InterfaceConstructorBehavior(ClassOps { addProperty: None, delProperty: None, - getProperty: None, - setProperty: None, enumerate: None, + newEnumerate: None, resolve: None, mayResolve: None, finalize: None, @@ -110,9 +110,8 @@ impl InterfaceConstructorBehavior { InterfaceConstructorBehavior(ClassOps { addProperty: None, delProperty: None, - getProperty: None, - setProperty: None, enumerate: None, + newEnumerate: None, resolve: None, mayResolve: None, finalize: None, @@ -138,7 +137,6 @@ pub unsafe fn create_global_object( assert!(rval.is_null()); let mut options = CompartmentOptions::default(); - options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5; options.creationOptions_.traceGlobal_ = Some(trace); options.creationOptions_.sharedMemoryAndAtomics_ = true; @@ -151,12 +149,12 @@ pub unsafe fn create_global_object( // Initialize the reserved slots before doing anything that can GC, to // avoid getting trace hooks called on a partially initialized object. - JS_SetReservedSlot(rval.get(), DOM_OBJECT_SLOT, PrivateValue(private)); + let private_val = PrivateValue(private); + JS_SetReservedSlot(rval.get(), DOM_OBJECT_SLOT, &private_val); let proto_array: Box<ProtoOrIfaceArray> = Box::new([0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH]); - JS_SetReservedSlot(rval.get(), - DOM_PROTOTYPE_SLOT, - PrivateValue(Box::into_raw(proto_array) as *const libc::c_void)); + let val = PrivateValue(Box::into_raw(proto_array) as *const libc::c_void); + JS_SetReservedSlot(rval.get(), DOM_PROTOTYPE_SLOT, &val); let _ac = JSAutoCompartment::new(cx, rval.get()); JS_FireOnNewGlobalObject(cx, rval.handle()); @@ -197,9 +195,9 @@ pub unsafe fn create_interface_prototype_object( assert!(!unscopable_symbol.is_null()); rooted!(in(cx) let unscopable_id = RUST_SYMBOL_TO_JSID(unscopable_symbol)); - assert!(JS_DefinePropertyById3( + assert!(JS_DefinePropertyById4( cx, rval.handle(), unscopable_id.handle(), unscopable_obj.handle(), - JSPROP_READONLY, None, None)) + JSPROP_READONLY as u32)) } } @@ -225,7 +223,7 @@ pub unsafe fn create_noncallback_interface_object( rval); assert!(JS_LinkConstructorAndPrototype(cx, rval.handle(), interface_prototype_object)); define_name(cx, rval.handle(), name); - define_length(cx, rval.handle(), length); + define_length(cx, rval.handle(), i32::try_from(length).expect("overflow")); define_on_global_object(cx, global, name, rval.handle()); } @@ -249,13 +247,11 @@ pub unsafe fn create_named_constructors( constructor.set(JS_GetFunctionObject(fun)); assert!(!constructor.is_null()); - assert!(JS_DefineProperty1(cx, + assert!(JS_DefineProperty2(cx, constructor.handle(), b"prototype\0".as_ptr() as *const libc::c_char, interface_prototype_object, - JSPROP_PERMANENT | JSPROP_READONLY, - None, - None)); + (JSPROP_PERMANENT | JSPROP_READONLY) as u32)); define_on_global_object(cx, global, name, constructor.handle()); } @@ -329,12 +325,11 @@ pub unsafe fn define_on_global_object( name: &[u8], obj: HandleObject) { assert_eq!(*name.last().unwrap(), b'\0'); - assert!(JS_DefineProperty1(cx, + assert!(JS_DefineProperty2(cx, global, name.as_ptr() as *const libc::c_char, obj, - JSPROP_RESOLVING, - None, None)); + JSPROP_RESOLVING)); } const OBJECT_OPS: ObjectOps = ObjectOps { @@ -345,16 +340,13 @@ const OBJECT_OPS: ObjectOps = ObjectOps { setProperty: None, getOwnPropertyDescriptor: None, deleteProperty: None, - watch: None, - unwatch: None, getElements: None, - enumerate: None, funToString: Some(fun_to_string_hook), }; unsafe extern "C" fn fun_to_string_hook(cx: *mut JSContext, obj: RawHandleObject, - _indent: u32) + _is_to_source: bool) -> *mut JSString { let js_class = get_object_class(obj.get()); assert!(!js_class.is_null()); @@ -444,9 +436,7 @@ unsafe fn create_unscopable_object( rval.handle(), name.as_ptr() as *const libc::c_char, HandleValue::from_raw(TrueHandleValue), - JSPROP_READONLY, - None, - None + JSPROP_READONLY as u32, )); } } @@ -455,21 +445,19 @@ unsafe fn define_name(cx: *mut JSContext, obj: HandleObject, name: &[u8]) { assert_eq!(*name.last().unwrap(), b'\0'); rooted!(in(cx) let name = JS_AtomizeAndPinString(cx, name.as_ptr() as *const libc::c_char)); assert!(!name.is_null()); - assert!(JS_DefineProperty2(cx, + assert!(JS_DefineProperty3(cx, obj, b"name\0".as_ptr() as *const libc::c_char, name.handle().into(), - JSPROP_READONLY, - None, None)); + JSPROP_READONLY as u32)); } -unsafe fn define_length(cx: *mut JSContext, obj: HandleObject, length: u32) { +unsafe fn define_length(cx: *mut JSContext, obj: HandleObject, length: i32) { assert!(JS_DefineProperty4(cx, obj, b"length\0".as_ptr() as *const libc::c_char, length, - JSPROP_READONLY, - None, None)); + JSPROP_READONLY as u32)); } unsafe extern "C" fn invalid_constructor( diff --git a/components/script/dom/bindings/mozmap.rs b/components/script/dom/bindings/mozmap.rs index 599207e95fb..2dfacbb2996 100644 --- a/components/script/dom/bindings/mozmap.rs +++ b/components/script/dom/bindings/mozmap.rs @@ -5,10 +5,13 @@ //! The `MozMap` (open-ended dictionary) type. use dom::bindings::conversions::jsid_to_string; +use dom::bindings::error::report_pending_exception; use dom::bindings::str::DOMString; use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible}; use js::jsapi::JSContext; +use js::jsapi::JSITER_HIDDEN; use js::jsapi::JSITER_OWNONLY; +use js::jsapi::JSITER_SYMBOLS; use js::jsapi::JSPROP_ENUMERATE; use js::jsapi::JS_NewPlainObject; use js::jsval::ObjectValue; @@ -58,7 +61,13 @@ impl<T, C> FromJSValConvertible for MozMap<T> rooted!(in(cx) let object = value.to_object()); let ids = IdVector::new(cx); - assert!(GetPropertyKeys(cx, object.handle(), JSITER_OWNONLY, ids.get())); + if !GetPropertyKeys(cx, object.handle(), JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, ids.get()) { + // TODO: can GetPropertyKeys fail? + // (it does so if the object has duplicate keys) + // https://github.com/servo/servo/issues/21462 + report_pending_exception(cx, false); + return Ok(ConversionResult::Failure("Getting MozMap value property keys failed".into())); + } let mut map = HashMap::new(); for id in &*ids { @@ -74,8 +83,11 @@ impl<T, C> FromJSValConvertible for MozMap<T> ConversionResult::Failure(message) => return Ok(ConversionResult::Failure(message)), }; - let key = jsid_to_string(cx, id.handle()).unwrap(); - map.insert(key, property); + // TODO: Is this guaranteed to succeed? + // https://github.com/servo/servo/issues/21463 + if let Some(key) = jsid_to_string(cx, id.handle()) { + map.insert(key, property); + } } Ok(ConversionResult::Success(MozMap { @@ -100,9 +112,7 @@ impl<T: ToJSValConvertible> ToJSValConvertible for MozMap<T> { key.as_ptr(), key.len(), js_value.handle(), - JSPROP_ENUMERATE, - None, - None)); + JSPROP_ENUMERATE as u32)); } rval.set(ObjectValue(js_object.handle().get())); diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index 76382e59423..2a512b02df3 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -8,11 +8,11 @@ use dom::bindings::conversions::is_dom_proxy; use dom::bindings::utils::delete_property_by_id; -use js::glue::{GetProxyHandler, GetProxyHandlerFamily, SetProxyExtra}; -use js::glue::GetProxyExtra; +use js::glue::{GetProxyHandler, GetProxyHandlerFamily}; +use js::glue::{GetProxyPrivate, SetProxyPrivate}; use js::glue::InvokeGetOwnPropertyDescriptor; -use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, PropertyDescriptor, JSPROP_GETTER}; -use js::jsapi::{JSErrNum, JS_StrictPropertyStub, SetDOMProxyInformation}; +use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, PropertyDescriptor}; +use js::jsapi::{JSErrNum, SetDOMProxyInformation}; use js::jsapi::GetObjectProto; use js::jsapi::GetStaticPrototype; use js::jsapi::Handle as RawHandle; @@ -24,14 +24,13 @@ use js::jsapi::MutableHandle as RawMutableHandle; use js::jsapi::MutableHandleObject as RawMutableHandleObject; use js::jsapi::ObjectOpResult; use js::jsval::ObjectValue; +use js::jsval::UndefinedValue; use js::rust::{Handle, HandleObject, MutableHandle, MutableHandleObject}; use js::rust::wrappers::JS_AlreadyHasOwnPropertyById; use js::rust::wrappers::JS_NewObjectWithGivenProto; use std::ptr; -static JSPROXYSLOT_EXPANDO: u32 = 0; - /// Determine if this id shadows any existing properties for this proxy. pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext, object: RawHandleObject, @@ -61,7 +60,6 @@ pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext, /// Initialize the infrastructure for DOM proxy objects. pub unsafe fn init() { SetDOMProxyInformation(GetProxyHandlerFamily(), - JSPROXYSLOT_EXPANDO, Some(shadow_check_callback)); } @@ -99,11 +97,6 @@ pub unsafe extern "C" fn define_property(cx: *mut JSContext, desc: RawHandle<PropertyDescriptor>, result: *mut ObjectOpResult) -> bool { - if (desc.get().attrs & JSPROP_GETTER) != 0 && desc.get().setter == Some(JS_StrictPropertyStub) { - (*result).code_ = JSErrNum::JSMSG_GETTER_ONLY as ::libc::uintptr_t; - return true; - } - rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>()); ensure_expando_object(cx, proxy, expando.handle_mut()); JS_DefinePropertyById(cx, expando.handle().into(), id, desc, result) @@ -165,7 +158,8 @@ pub unsafe extern "C" fn get_prototype_if_ordinary(_: *mut JSContext, /// Get the expando object, or null if there is none. pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandleObject) { assert!(is_dom_proxy(obj.get())); - let val = GetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO); + let ref mut val = UndefinedValue(); + GetProxyPrivate(obj.get(), val); expando.set(if val.is_undefined() { ptr::null_mut() } else { @@ -182,7 +176,7 @@ pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: RawHandleObject, mu expando.set(JS_NewObjectWithGivenProto(cx, ptr::null_mut(), HandleObject::null())); assert!(!expando.is_null()); - SetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO, &ObjectValue(expando.get())); + SetProxyPrivate(obj.get(), &ObjectValue(expando.get())); } } diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index db6897a287f..d530a51e7bc 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -11,14 +11,21 @@ use dom::bindings::reflector::DomObject; use dom::bindings::root::DomRoot; use dom::blob::{Blob, BlobImpl}; use dom::globalscope::GlobalScope; +use js::glue::CopyJSStructuredCloneData; +use js::glue::DeleteJSAutoStructuredCloneBuffer; +use js::glue::GetLengthOfJSStructuredCloneData; +use js::glue::NewJSAutoStructuredCloneBuffer; +use js::glue::WriteBytesToJSStructuredCloneData; use js::jsapi::{JSAutoCompartment, JSContext}; use js::jsapi::{JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter}; use js::jsapi::{JS_ClearPendingException, JSObject}; use js::jsapi::{JS_ReadBytes, JS_WriteBytes}; use js::jsapi::{JS_ReadUint32Pair, JS_WriteUint32Pair}; +use js::jsapi::CloneDataPolicy; use js::jsapi::HandleObject as RawHandleObject; use js::jsapi::JS_STRUCTURED_CLONE_VERSION; use js::jsapi::MutableHandleObject as RawMutableHandleObject; +use js::jsapi::StructuredCloneScope; use js::jsapi::TransferableOwnership; use js::rust::{Handle, HandleValue, MutableHandleValue}; use js::rust::wrappers::{JS_WriteStructuredClone, JS_ReadStructuredClone}; @@ -207,26 +214,39 @@ pub enum StructuredCloneData { } impl StructuredCloneData { + // TODO: should this be unsafe? /// Writes a structured clone. Returns a `DataClone` error if that fails. 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, - &STRUCTURED_CLONE_CALLBACKS, - ptr::null_mut(), - HandleValue::undefined()) - }; - if !result { - unsafe { + unsafe { + let scbuf = NewJSAutoStructuredCloneBuffer(StructuredCloneScope::DifferentProcess, + &STRUCTURED_CLONE_CALLBACKS); + let scdata = &mut ((*scbuf).data_); + let policy = CloneDataPolicy { + // TODO: SAB? + sharedArrayBuffer_: false, + }; + let result = JS_WriteStructuredClone(cx, + message, + scdata, + StructuredCloneScope::DifferentProcess, + policy, + &STRUCTURED_CLONE_CALLBACKS, + ptr::null_mut(), + HandleValue::undefined()); + if !result { JS_ClearPendingException(cx); + return Err(Error::DataClone); } - return Err(Error::DataClone); + + let nbytes = GetLengthOfJSStructuredCloneData(scdata); + let mut data = Vec::with_capacity(nbytes); + CopyJSStructuredCloneData(scdata, data.as_mut_ptr()); + data.set_len(nbytes); + + DeleteJSAutoStructuredCloneBuffer(scbuf); + + Ok(StructuredCloneData::Vector(data)) } - Ok(StructuredCloneData::Struct(data, nbytes)) } /// Converts a StructuredCloneData to Vec<u8> for inter-thread sharing @@ -254,13 +274,21 @@ impl StructuredCloneData { let mut sc_holder = StructuredCloneHolder { blob: None }; let sc_holder_ptr = &mut sc_holder as *mut _; unsafe { + let scbuf = NewJSAutoStructuredCloneBuffer(StructuredCloneScope::DifferentProcess, + &STRUCTURED_CLONE_CALLBACKS); + let scdata = &mut ((*scbuf).data_); + + WriteBytesToJSStructuredCloneData(data as *const u8, nbytes, scdata); + assert!(JS_ReadStructuredClone(cx, - data, - nbytes, + scdata, JS_STRUCTURED_CLONE_VERSION, + StructuredCloneScope::DifferentProcess, rval, &STRUCTURED_CLONE_CALLBACKS, sc_holder_ptr as *mut raw::c_void)); + + DeleteJSAutoStructuredCloneBuffer(scbuf); } } diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 5cdb84fba26..fd0d346414c 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -39,7 +39,6 @@ use canvas_traits::webgl::{WebGLSLVersion, WebGLSender, WebGLShaderId, WebGLText use canvas_traits::webgl::{WebGLVersion, WebGLVertexArrayId}; use cssparser::RGBA; use devtools_traits::{CSSError, TimelineMarkerType, WorkerId}; -use dom::abstractworker::SharedRt; use dom::bindings::cell::DomRefCell; use dom::bindings::error::Error; use dom::bindings::refcounted::{Trusted, TrustedPromise}; @@ -77,7 +76,6 @@ use net_traits::response::{Response, ResponseBody}; use net_traits::response::HttpsState; use net_traits::storage_thread::StorageType; use offscreen_gl_context::GLLimits; -use parking_lot::RwLock; use profile_traits::mem::ProfilerChan as MemProfilerChan; use profile_traits::time::ProfilerChan as TimeProfilerChan; use script_layout_interface::OpaqueStyleAndLayoutData; @@ -103,7 +101,7 @@ use std::hash::{BuildHasher, Hash}; use std::ops::{Deref, DerefMut}; use std::path::PathBuf; use std::rc::Rc; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::sync::mpsc::{Receiver, Sender}; use std::time::{SystemTime, Instant}; @@ -397,7 +395,6 @@ unsafe_no_jsmanaged_fields!(Stylesheet); unsafe_no_jsmanaged_fields!(HttpsState); unsafe_no_jsmanaged_fields!(Request); unsafe_no_jsmanaged_fields!(RequestInit); -unsafe_no_jsmanaged_fields!(SharedRt); unsafe_no_jsmanaged_fields!(StyleSharedRwLock); unsafe_no_jsmanaged_fields!(USVString); unsafe_no_jsmanaged_fields!(ReferrerPolicy); @@ -594,12 +591,6 @@ unsafe impl<U> JSTraceable for TypedSize2D<f32, U> { } } -unsafe impl JSTraceable for Mutex<Option<SharedRt>> { - unsafe fn trace(&self, _trc: *mut JSTracer) { - // Do nothing. - } -} - unsafe impl JSTraceable for StyleLocked<FontFaceRule> { unsafe fn trace(&self, _trc: *mut JSTracer) { // Do nothing. @@ -666,12 +657,6 @@ unsafe impl JSTraceable for StyleLocked<PropertyDeclarationBlock> { } } -unsafe impl JSTraceable for RwLock<SharedRt> { - unsafe fn trace(&self, _trc: *mut JSTracer) { - // Do nothing. - } -} - unsafe impl JSTraceable for StyleLocked<MediaList> { unsafe fn trace(&self, _trc: *mut JSTracer) { // Do nothing. diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index f8ea201092f..a82786f2143 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -16,20 +16,20 @@ use dom::windowproxy; use js; use js::JS_CALLEE; use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper}; -use js::glue::{GetCrossCompartmentWrapper, WrapperNew}; +use js::glue::{GetCrossCompartmentWrapper, JS_GetReservedSlot, WrapperNew}; use js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING}; use js::glue::{RUST_JSID_TO_INT, RUST_JSID_TO_STRING, UnwrapObject}; use js::jsapi::{CallArgs, DOMCallbacks, GetGlobalForObjectCrossCompartment}; use js::jsapi::{Heap, JSAutoCompartment, JSContext}; use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks}; use js::jsapi::{JS_EnumerateStandardClasses, JS_GetLatin1StringCharsAndLength}; -use js::jsapi::{JS_GetReservedSlot, JS_IsExceptionPending, JS_IsGlobalObject}; -use js::jsapi::{JS_ResolveStandardClass, ToWindowProxyIfWindow}; -use js::jsapi::{JS_StringHasLatin1Chars, ObjectOpResult}; +use js::jsapi::{JS_IsExceptionPending, JS_IsGlobalObject}; +use js::jsapi::{JS_ResolveStandardClass, JS_StringHasLatin1Chars, ObjectOpResult}; use js::jsapi::HandleId as RawHandleId; use js::jsapi::HandleObject as RawHandleObject; +use js::jsapi::MutableHandleObject as RawMutableHandleObject; use js::jsval::{JSVal, UndefinedValue}; -use js::rust::{GCMethods, ToString, get_object_class, is_dom_class}; +use js::rust::{GCMethods, ToString, ToWindowProxyIfWindow, get_object_class, is_dom_class}; use js::rust::{Handle, HandleId, HandleObject, HandleValue, MutableHandleValue}; use js::rust::wrappers::JS_DeletePropertyById; use js::rust::wrappers::JS_ForwardGetPropertyTo; @@ -124,7 +124,9 @@ unsafe impl Sync for DOMJSClass {} pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray { unsafe { assert_ne!(((*get_object_class(global)).flags & JSCLASS_DOM_GLOBAL), 0); - JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as *mut ProtoOrIfaceArray + let mut slot = UndefinedValue(); + JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT, &mut slot); + slot.to_private() as *mut ProtoOrIfaceArray } } @@ -387,14 +389,14 @@ unsafe extern "C" fn wrap(cx: *mut JSContext, } unsafe extern "C" fn pre_wrap(cx: *mut JSContext, - _existing: RawHandleObject, + _scope: RawHandleObject, obj: RawHandleObject, - _object_passed_to_wrap: RawHandleObject) - -> *mut JSObject { + _object_passed_to_wrap: RawHandleObject, + rval: RawMutableHandleObject) { let _ac = JSAutoCompartment::new(cx, obj.get()); let obj = ToWindowProxyIfWindow(obj.get()); assert!(!obj.is_null()); - obj + rval.set(obj) } /// Callback table for use with JS_SetWrapObjectCallbacks diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs index abb1e07bc08..4cafafc0440 100644 --- a/components/script/dom/bindings/weakref.rs +++ b/components/script/dom/bindings/weakref.rs @@ -15,8 +15,10 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::reflector::DomObject; use dom::bindings::root::DomRoot; use dom::bindings::trace::JSTraceable; -use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot}; +use js::glue::JS_GetReservedSlot; +use js::jsapi::{JSTracer, JS_SetReservedSlot}; use js::jsval::PrivateValue; +use js::jsval::UndefinedValue; use libc::c_void; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use std::cell::{Cell, UnsafeCell}; @@ -53,16 +55,17 @@ pub trait WeakReferenceable: DomObject + 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 slot = UndefinedValue(); + JS_GetReservedSlot(object, DOM_WEAK_SLOT, &mut slot); + let mut ptr = slot.to_private() as *mut WeakBox<Self>; if ptr.is_null() { trace!("Creating new WeakBox holder for {:p}.", self); ptr = Box::into_raw(Box::new(WeakBox { count: Cell::new(1), value: Cell::new(Some(ptr::NonNull::from(self))), })); - JS_SetReservedSlot(object, DOM_WEAK_SLOT, PrivateValue(ptr as *const c_void)); + let val = PrivateValue(ptr as *const c_void); + JS_SetReservedSlot(object, DOM_WEAK_SLOT, &val); } let box_ = &*ptr; assert!(box_.value.get().is_some()); |