diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 8a66a99cb38e8..7a98b5a83fa6e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -19,7 +19,12 @@ IDLUndefinedValue, ) -from Configuration import getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback +from Configuration import ( + MemberIsUnforgeable, + getTypesFromCallback, + getTypesFromDescriptor, + getTypesFromDictionary, +) AUTOGENERATED_WARNING_COMMENT = \ "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n" @@ -1390,7 +1395,8 @@ class MethodDefiner(PropertyDefiner): """ A class for defining methods on a prototype object. """ - def __init__(self, descriptor, name, static): + def __init__(self, descriptor, name, static, unforgeable): + assert not (static and unforgeable) PropertyDefiner.__init__(self, descriptor, name) # FIXME https://bugzilla.mozilla.org/show_bug.cgi?id=772822 @@ -1401,36 +1407,40 @@ def __init__(self, descriptor, name, static): if not descriptor.interface.isCallback() or static: methods = [m for m in descriptor.interface.members if m.isMethod() and m.isStatic() == static and - not m.isIdentifierLess()] + not m.isIdentifierLess() and + MemberIsUnforgeable(m, descriptor) == unforgeable] else: methods = [] self.regular = [{"name": m.identifier.name, "methodInfo": not m.isStatic(), - "length": methodLength(m), - "flags": "JSPROP_ENUMERATE"} for m in methods] + "length": methodLength(m)} for m in methods] # FIXME Check for an existing iterator on the interface first. if any(m.isGetter() and m.isIndexed() for m in methods): self.regular.append({"name": '@@iterator', "methodInfo": False, "selfHostedName": "ArrayValues", - "length": 0, - "flags": "JSPROP_ENUMERATE"}) + "length": 0}) - if not static: + isUnforgeableInterface = bool(descriptor.interface.getExtendedAttribute("Unforgeable")) + if not static and unforgeable == isUnforgeableInterface: stringifier = descriptor.operations['Stringifier'] if stringifier: self.regular.append({ "name": "toString", "nativeName": stringifier.identifier.name, "length": 0, - "flags": "JSPROP_ENUMERATE" }) + self.unforgeable = unforgeable def generateArray(self, array, name): if len(array) == 0: return "" + flags = "JSPROP_ENUMERATE" + if self.unforgeable: + flags += " | JSPROP_PERMANENT | JSPROP_READONLY" + def specData(m): # TODO: Use something like JS_FNSPEC # https://github.com/servo/servo/issues/6391 @@ -1450,16 +1460,16 @@ def specData(m): accessor = 'Some(%s)' % m.get("nativeName", m["name"]) if m["name"].startswith("@@"): return ('(SymbolCode::%s as i32 + 1)' - % m["name"][2:], accessor, jitinfo, m["length"], m["flags"], selfHostedName) - return (str_to_const_array(m["name"]), accessor, jitinfo, m["length"], m["flags"], selfHostedName) + % m["name"][2:], accessor, jitinfo, m["length"], flags, selfHostedName) + return (str_to_const_array(m["name"]), accessor, jitinfo, m["length"], flags, selfHostedName) return self.generatePrefableArray( array, name, ' JSFunctionSpec {\n' ' name: %s as *const u8 as *const libc::c_char,\n' - ' call: JSNativeWrapper {op: %s, info: %s},\n' + ' call: JSNativeWrapper { op: %s, info: %s },\n' ' nargs: %s,\n' - ' flags: %s as u16,\n' + ' flags: (%s) as u16,\n' ' selfHostedName: %s\n' ' }', ' JSFunctionSpec {\n' @@ -1474,23 +1484,27 @@ def specData(m): class AttrDefiner(PropertyDefiner): - def __init__(self, descriptor, name, static): + def __init__(self, descriptor, name, static, unforgeable): + assert not (static and unforgeable) PropertyDefiner.__init__(self, descriptor, name) self.name = name self.descriptor = descriptor self.regular = [ m - for m in descriptor.interface.members - if m.isAttr() and m.isStatic() == static + for m in descriptor.interface.members if + m.isAttr() and m.isStatic() == static and + MemberIsUnforgeable(m, descriptor) == unforgeable ] self.static = static + self.unforgeable = unforgeable def generateArray(self, array, name): if len(array) == 0: return "" - def flags(attr): - return "JSPROP_SHARED | JSPROP_ENUMERATE" + flags = "JSPROP_ENUMERATE | JSPROP_SHARED" + if self.unforgeable: + flags += " | JSPROP_READONLY | JSPROP_PERMANENT" def getter(attr): if self.static: @@ -1526,7 +1540,7 @@ def setter(attr): "native": accessor}) def specData(attr): - return (str_to_const_array(attr.identifier.name), flags(attr), getter(attr), + return (str_to_const_array(attr.identifier.name), flags, getter(attr), setter(attr)) return self.generatePrefableArray( @@ -1847,10 +1861,16 @@ def __init__(self, descriptor): self.descriptor = descriptor def define(self): + name = str_to_const_array(self.descriptor.interface.identifier.name + "Prototype") + slotCount = 1 + if self.descriptor.hasUnforgeableMembers: + slotCount += 1 return """\ static PrototypeClass: JSClass = JSClass { - name: %s as *const u8 as *const libc::c_char, - flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT, //JSCLASS_HAS_RESERVED_SLOTS(1) + name: %(name)s as *const u8 as *const libc::c_char, + flags: + // JSCLASS_HAS_RESERVED_SLOTS(%(slotCount)s) + (%(slotCount)s & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT, addProperty: None, delProperty: None, getProperty: None, @@ -1865,7 +1885,7 @@ def define(self): trace: None, reserved: [0 as *mut libc::c_void; 25] }; -""" % str_to_const_array(self.descriptor.interface.identifier.name + "Prototype") +""" % {'name': name, 'slotCount': slotCount} class CGInterfaceObjectJSClass(CGThing): @@ -2180,6 +2200,68 @@ def CreateBindingJSObject(descriptor, parent=None): return create +def InitUnforgeablePropertiesOnHolder(descriptor, properties): + """ + Define the unforgeable properties on the unforgeable holder for + the interface represented by descriptor. + + properties is a PropertyArrays instance. + """ + unforgeables = [] + + defineUnforgeableAttrs = "define_properties(cx, unforgeable_holder.handle(), %s);" + defineUnforgeableMethods = "define_methods(cx, unforgeable_holder.handle(), %s);" + + unforgeableMembers = [ + (defineUnforgeableAttrs, properties.unforgeable_attrs), + (defineUnforgeableMethods, properties.unforgeable_methods), + ] + for template, array in unforgeableMembers: + if array.length() > 0: + unforgeables.append(CGGeneric(template % array.variableName())) + return CGList(unforgeables, "\n") + + +def CopyUnforgeablePropertiesToInstance(descriptor): + """ + Copy the unforgeable properties from the unforgeable holder for + this interface to the instance object we have. + """ + if not descriptor.hasUnforgeableMembers: + return "" + copyCode = "" + + # For proxies, we want to define on the expando object, not directly on the + # reflector, so we can make sure we don't get confused by named getters. + if descriptor.proxy: + copyCode += """\ +let mut expando = RootedObject::new(cx, ptr::null_mut()); +{ + let _ac = JSAutoCompartment::new(cx, scope.get()); + expando.handle_mut().set(ensure_expando_object(cx, obj.handle())); +} +""" + obj = "expando" + else: + obj = "obj" + + # We can't do the fast copy for globals, because we can't allocate the + # unforgeable holder for those with the right JSClass. Luckily, there + # aren't too many globals being created. + if descriptor.isGlobal(): + copyFunc = "JS_CopyPropertiesFrom" + else: + copyFunc = "JS_InitializePropertiesFromCompatibleNativeObject" + copyCode += """\ +let mut unforgeable_holder = RootedObject::new(cx, ptr::null_mut()); +unforgeable_holder.handle_mut().set( + JS_GetReservedSlot(proto.ptr, DOM_PROTO_UNFORGEABLE_HOLDER_SLOT).to_object()); +assert!(%(copyFunc)s(cx, %(obj)s.handle(), unforgeable_holder.handle()) != 0); +""" % {'copyFunc': copyFunc, 'obj': obj} + + return copyCode + + class CGWrapMethod(CGAbstractMethod): """ Class that generates the FooBinding::Wrap function for non-callback @@ -2198,7 +2280,9 @@ def __init__(self, descriptor): pub=True, unsafe=True) def definition_body(self): + unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor) if not self.descriptor.isGlobal(): + create = CreateBindingJSObject(self.descriptor, "scope") return CGGeneric("""\ let _ar = JSAutoRequest::new(cx); let scope = scope.reflector().get_jsobject(); @@ -2212,28 +2296,31 @@ def definition_body(self): } assert!(!proto.ptr.is_null()); -%s +%(createObject)s +%(copyUnforgeable)s (*raw).init_reflector(obj.ptr); -Root::from_ref(&*raw)""" % CreateBindingJSObject(self.descriptor, "scope")) +Root::from_ref(&*raw)""" % {'copyUnforgeable': unforgeable, 'createObject': create}) else: + create = CreateBindingJSObject(self.descriptor) return CGGeneric("""\ let _ar = JSAutoRequest::new(cx); -%s +%(createObject)s let _ac = JSAutoCompartment::new(cx, obj.ptr); let mut proto = RootedObject::new(cx, ptr::null_mut()); GetProtoObject(cx, obj.handle(), obj.handle(), proto.handle_mut()); JS_SetPrototype(cx, obj.handle(), proto.handle()); +%(copyUnforgeable)s (*raw).init_reflector(obj.ptr); let ret = Root::from_ref(&*raw); RegisterBindings::Register(cx, obj.handle()); -ret""" % CreateBindingJSObject(self.descriptor)) +ret""" % {'copyUnforgeable': unforgeable, 'createObject': create}) class CGIDLInterface(CGThing): @@ -2274,17 +2361,29 @@ def __init__(self, descriptor, name, returnType, args): class PropertyArrays(): def __init__(self, descriptor): self.static_methods = MethodDefiner(descriptor, "StaticMethods", - static=True) + static=True, unforgeable=False) self.static_attrs = AttrDefiner(descriptor, "StaticAttributes", - static=True) - self.methods = MethodDefiner(descriptor, "Methods", static=False) - self.attrs = AttrDefiner(descriptor, "Attributes", static=False) + static=True, unforgeable=False) + self.methods = MethodDefiner(descriptor, "Methods", static=False, unforgeable=False) + self.unforgeable_methods = MethodDefiner(descriptor, "UnforgeableMethods", + static=False, unforgeable=True) + self.attrs = AttrDefiner(descriptor, "Attributes", static=False, unforgeable=False) + self.unforgeable_attrs = AttrDefiner(descriptor, "UnforgeableAttributes", + static=False, unforgeable=True) self.consts = ConstDefiner(descriptor, "Constants") pass @staticmethod def arrayNames(): - return ["static_methods", "static_attrs", "methods", "attrs", "consts"] + return [ + "static_methods", + "static_attrs", + "methods", + "unforgeable_methods", + "attrs", + "unforgeable_attrs", + "consts", + ] def variableNames(self): names = {} @@ -2396,10 +2495,54 @@ def definition_body(self): createArray += "," createArray += "];" + if self.descriptor.hasUnforgeableMembers: + # We want to use the same JSClass and prototype as the object we'll + # end up defining the unforgeable properties on in the end, so that + # we can use JS_InitializePropertiesFromCompatibleNativeObject to do + # a fast copy. In the case of proxies that's null, because the + # expando object is a vanilla object, but in the case of other DOM + # objects it's whatever our class is. + # + # Also, for a global we can't use the global's class; just use + # nullpr and when we do the copy off the holder we'll take a slower + # path. This also means that we don't need to worry about matching + # the prototype. + if self.descriptor.proxy or self.descriptor.isGlobal(): + holderClass = "ptr::null()" + holderProto = "ptr::null_mut()" + else: + holderClass = "&Class.base as *const js::jsapi::Class as *const JSClass" + holderProto = "rval.get()" + # JS_NewObjectWithoutMetadata() is unsafe. + self.unsafe = True + createUnforgeableHolder = CGGeneric(""" +let mut unforgeable_holder = RootedObject::new(cx, ptr::null_mut()); +{ + let holder_class = %(holderClass)s; + let holder_proto = RootedObject::new(cx, %(holderProto)s); + unforgeable_holder.handle_mut().set( + JS_NewObjectWithoutMetadata(cx, holder_class, holder_proto.handle())); + assert!(!unforgeable_holder.ptr.is_null()); +}""" % {'holderClass': holderClass, 'holderProto': holderProto}) + defineUnforgeables = InitUnforgeablePropertiesOnHolder(self.descriptor, + self.properties) + createUnforgeableHolder = CGList( + [createUnforgeableHolder, defineUnforgeables], "\n") + + installUnforgeableHolder = CGGeneric("""\ +JS_SetReservedSlot(rval.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, + ObjectValue(&*unforgeable_holder.ptr))""") + + unforgeableHolderSetup = CGList( + [createUnforgeableHolder, installUnforgeableHolder], "\n") + else: + unforgeableHolderSetup = None + return CGList([ CGGeneric(getParentProto), CGGeneric(createArray), - CGGeneric(call % self.properties.variableNames()) + CGGeneric(call % self.properties.variableNames()), + unforgeableHolderSetup, ], "\n") @@ -4182,6 +4325,9 @@ def getBody(self): namedSetter = self.descriptor.operations['NamedSetter'] if namedSetter: + if self.descriptor.hasUnforgeableMembers: + raise TypeError("Can't handle a named setter on an interface that has " + "unforgeables. Figure out how that should work!") set += ("if RUST_JSID_IS_STRING(id) != 0 {\n" + CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + " (*opresult).code_ = 0; /* SpecialCodes::OkCode */\n" + @@ -4221,6 +4367,9 @@ def __init__(self, descriptor): def getBody(self): set = "" if self.descriptor.operations['NamedDeleter']: + if self.descriptor.hasUnforgeableMembers: + raise TypeError("Can't handle a deleter on an interface that has " + "unforgeables. Figure out how that should work!") set += CGProxyNamedDeleter(self.descriptor).define() set += "return proxyhandler::delete(%s) as u8;" % ", ".join(a.name for a in self.args) return set @@ -5061,29 +5210,29 @@ def __init__(self, config, prefix, webIDLFile): # Add imports curr = CGImports(curr, descriptors + callbackDescriptors, mainCallbacks, [ 'js', - 'js::JS_CALLEE', - 'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS, JSCLASS_IMPLEMENTS_BARRIERS}', - 'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}', - 'js::{JSCLASS_RESERVED_SLOTS_MASK}', - 'js::{JSPROP_ENUMERATE, JSPROP_SHARED}', - 'js::{JSITER_OWNONLY, JSITER_HIDDEN, JSITER_SYMBOLS}', - 'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}', - 'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}', - 'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}', - 'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}', - 'js::jsapi::{JS_NewObjectWithGivenProto, JS_NewObject, IsCallable, JS_SetProperty, JS_SetPrototype}', - 'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSContext}', - 'js::jsapi::{JSClass, FreeOp, JSFreeOp, JSFunctionSpec, jsid}', - 'js::jsapi::{MutableHandleValue, MutableHandleObject, HandleObject, HandleValue, RootedObject}', - 'js::jsapi::{RootedValue, JSNativeWrapper, JSNative, JSObject, JSPropertyDescriptor}', - 'js::jsapi::{RootedId, JS_InternString, RootedString, INTERNED_STRING_TO_JSID}', - 'js::jsapi::{JSPropertySpec}', - 'js::jsapi::{JSString, JSTracer, JSJitInfo, JSJitInfo_OpType, JSJitInfo_AliasSet}', - 'js::jsapi::{MutableHandle, Handle, HandleId, JSType, JSValueType}', - 'js::jsapi::{SymbolCode, ObjectOpResult, HandleValueArray}', - 'js::jsapi::{JSJitGetterCallArgs, JSJitSetterCallArgs, JSJitMethodCallArgs, CallArgs}', - 'js::jsapi::{JSAutoCompartment, JSAutoRequest, JS_ComputeThis}', - 'js::jsapi::{GetGlobalForObjectCrossCompartment, AutoIdVector, GetPropertyKeys}', + 'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IMPLEMENTS_BARRIERS}', + 'js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_MASK}', + 'js::{JSCLASS_RESERVED_SLOTS_SHIFT, JSFalse, JSITER_HIDDEN, JSITER_OWNONLY}', + 'js::{JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY}', + 'js::{JSPROP_SHARED, JSTrue, JS_CALLEE}', + 'js::jsapi::{AutoIdVector, CallArgs, FreeOp, GetGlobalForObjectCrossCompartment}', + 'js::jsapi::{GetPropertyKeys, Handle, HandleId, HandleObject, HandleValue}', + 'js::jsapi::{HandleValueArray, INTERNED_STRING_TO_JSID, IsCallable}', + 'js::jsapi::{JS_CallFunctionValue, JS_ComputeThis, JS_CopyPropertiesFrom}', + 'js::jsapi::{JS_GetClass, JS_GetGlobalForObject, JS_GetObjectPrototype}', + 'js::jsapi::{JS_GetProperty, JS_GetPropertyById, JS_GetPropertyDescriptorById}', + 'js::jsapi::{JS_GetReservedSlot, JS_HasProperty, JS_HasPropertyById}', + 'js::jsapi::{JS_InitializePropertiesFromCompatibleNativeObject, JS_InternString}', + 'js::jsapi::{JS_IsExceptionPending, JS_NewObject, JS_NewObjectWithGivenProto}', + 'js::jsapi::{JS_NewObjectWithoutMetadata, JS_SetProperty, JS_SetPrototype}', + 'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSAutoCompartment, JSAutoRequest}', + 'js::jsapi::{JSContext, JSClass, JSFreeOp, JSFunctionSpec, JSJitGetterCallArgs}', + 'js::jsapi::{JSJitInfo, JSJitInfo_AliasSet, JSJitInfo_OpType, JSJitMethodCallArgs}', + 'js::jsapi::{JSJitSetterCallArgs, JSNative, JSObject, JSNativeWrapper}', + 'js::jsapi::{JSPropertyDescriptor, JSPropertySpec, JSString, JSTracer, JSType}', + 'js::jsapi::{JSValueType, ObjectOpResult, MutableHandle, MutableHandleObject}', + 'js::jsapi::{MutableHandleValue, RootedId, RootedObject, RootedString}', + 'js::jsapi::{RootedValue, SymbolCode, jsid}', 'js::jsval::JSVal', 'js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue}', 'js::jsval::{NullValue, UndefinedValue}', @@ -5093,31 +5242,24 @@ def __init__(self, config, prefix, webIDLFile): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING, int_to_jsid}', 'js::glue::AppendToAutoIdVector', 'js::rust::GCMethods', - 'js::{JSTrue, JSFalse}', 'dom::bindings', 'dom::bindings::global::GlobalRef', 'dom::bindings::global::global_object_for_js_object', 'dom::bindings::js::{JS, Root, RootedReference}', 'dom::bindings::js::{OptionalRootedReference}', - 'dom::bindings::utils::{create_dom_global, do_create_interface_objects}', - 'dom::bindings::utils::ConstantSpec', - 'dom::bindings::utils::{DOMClass}', - 'dom::bindings::utils::{DOMJSClass, JSCLASS_DOM_GLOBAL}', - 'dom::bindings::utils::{find_enum_string_index, get_array_index_from_id}', - 'dom::bindings::utils::{get_property_on_prototype, get_proto_or_iface_array}', - 'dom::bindings::utils::{finalize_global, trace_global}', - 'dom::bindings::utils::has_property_on_prototype', - 'dom::bindings::utils::is_platform_object', - 'dom::bindings::utils::{Reflectable}', - 'dom::bindings::utils::throwing_constructor', - 'dom::bindings::utils::get_dictionary_property', - 'dom::bindings::utils::set_dictionary_property', - 'dom::bindings::utils::{NativeProperties, NativePropertyHooks}', + 'dom::bindings::utils::{ConstantSpec, DOMClass, DOMJSClass}', + 'dom::bindings::utils::{DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, JSCLASS_DOM_GLOBAL}', + 'dom::bindings::utils::{NativeProperties, NativePropertyHooks, NonNullJSNative}', + 'dom::bindings::utils::{Reflectable, create_dom_global, define_methods}', + 'dom::bindings::utils::{define_properties, do_create_interface_objects}', + 'dom::bindings::utils::{finalize_global, find_enum_string_index, generic_getter}', + 'dom::bindings::utils::{generic_lenient_getter, generic_lenient_setter}', + 'dom::bindings::utils::{generic_method, generic_setter, get_array_index_from_id}', + 'dom::bindings::utils::{get_dictionary_property, get_property_on_prototype}', + 'dom::bindings::utils::{get_proto_or_iface_array, has_property_on_prototype}', + 'dom::bindings::utils::{is_platform_object, set_dictionary_property}', + 'dom::bindings::utils::{throwing_constructor, trace_global}', 'dom::bindings::utils::ConstantVal::{IntVal, UintVal}', - 'dom::bindings::utils::NonNullJSNative', - 'dom::bindings::utils::{generic_getter, generic_lenient_getter}', - 'dom::bindings::utils::{generic_lenient_setter, generic_method}', - 'dom::bindings::utils::generic_setter', 'dom::bindings::trace::{JSTraceable, RootedTraceable}', 'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}', 'dom::bindings::callback::{CallSetup,ExceptionHandling}', @@ -5135,8 +5277,8 @@ def __init__(self, config, prefix, webIDLFile): 'dom::bindings::error::throw_dom_exception', 'dom::bindings::error::throw_type_error', 'dom::bindings::proxyhandler', - 'dom::bindings::proxyhandler::{fill_property_descriptor, get_expando_object}', - 'dom::bindings::proxyhandler::{get_property_descriptor}', + 'dom::bindings::proxyhandler::{ensure_expando_object, fill_property_descriptor}', + 'dom::bindings::proxyhandler::{get_expando_object, get_property_descriptor}', 'dom::bindings::num::Finite', 'dom::bindings::str::ByteString', 'dom::bindings::str::USVString', diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index a8179c5be95d2..efd325820cc7b 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -139,6 +139,13 @@ def getDescriptor(self, interfaceName): return self.config.getDescriptor(interfaceName) +def MemberIsUnforgeable(member, descriptor): + return ((member.isAttr() or member.isMethod()) and + not member.isStatic() and + (member.isUnforgeable() or + bool(descriptor.interface.getExtendedAttribute("Unforgeable")))) + + class Descriptor(DescriptorProvider): """ Represents a single descriptor for an interface. See Bindings.conf. @@ -175,6 +182,9 @@ def __init__(self, config, interface, desc): # them as having a concrete descendant. self.concrete = (not self.interface.isCallback() and desc.get('concrete', True)) + self.hasUnforgeableMembers = (self.concrete and + any(MemberIsUnforgeable(m, self) for m in + self.interface.members)) self.operations = { 'IndexedGetter': None, diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index d00c164d0a906..bcbe687cc6bd3 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -93,6 +93,10 @@ impl GlobalStaticData { // changes. const DOM_PROTO_INSTANCE_CLASS_SLOT: u32 = 0; +/// The index of the slot where the object holder of that interface's +/// unforgeable members are defined. +pub const DOM_PROTO_UNFORGEABLE_HOLDER_SLOT: u32 = 1; + /// The index of the slot that contains a reference to the ProtoOrIfaceArray. // All DOM globals must have a slot at DOM_PROTOTYPE_SLOT. pub const DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT; @@ -191,8 +195,12 @@ pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray pub struct NativeProperties { /// Instance methods for the interface. pub methods: Option<&'static [JSFunctionSpec]>, + /// Unforgeable instance methods for the interface. + pub unforgeable_methods: Option<&'static [JSFunctionSpec]>, /// Instance attributes for the interface. pub attrs: Option<&'static [JSPropertySpec]>, + /// Unforgeable instance attributes for the interface. + pub unforgeable_attrs: Option<&'static [JSPropertySpec]>, /// Constants for the interface. pub consts: Option<&'static [ConstantSpec]>, /// Static methods for the interface. @@ -342,8 +350,8 @@ fn define_constants(cx: *mut JSContext, obj: HandleObject, /// Defines methods on `obj`. The last entry of `methods` must contain zeroed /// memory. /// Fails on JSAPI failure. -fn define_methods(cx: *mut JSContext, obj: HandleObject, - methods: &'static [JSFunctionSpec]) { +pub fn define_methods(cx: *mut JSContext, obj: HandleObject, + methods: &'static [JSFunctionSpec]) { unsafe { assert!(JS_DefineFunctions(cx, obj, methods.as_ptr(), PropertyDefinitionBehavior::DefineAllProperties) != 0); } @@ -352,8 +360,8 @@ fn define_methods(cx: *mut JSContext, obj: HandleObject, /// Defines attributes on `obj`. The last entry of `properties` must contain /// zeroed memory. /// Fails on JSAPI failure. -fn define_properties(cx: *mut JSContext, obj: HandleObject, - properties: &'static [JSPropertySpec]) { +pub fn define_properties(cx: *mut JSContext, obj: HandleObject, + properties: &'static [JSPropertySpec]) { unsafe { assert!(JS_DefineProperties(cx, obj, properties.as_ptr()) != 0); } diff --git a/components/script/dom/testbindingproxy.rs b/components/script/dom/testbindingproxy.rs index 079e7656f688a..0987b5bf63016 100644 --- a/components/script/dom/testbindingproxy.rs +++ b/components/script/dom/testbindingproxy.rs @@ -28,5 +28,4 @@ impl TestBindingProxyMethods for TestBindingProxy { fn IndexedSetter(&self, _: u32, _: DOMString) -> () {} fn NamedSetter(&self, _: DOMString, _: DOMString) -> () {} fn NamedGetter(&self, _: DOMString, _: &mut bool) -> DOMString { "".to_owned() } - } diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index 8689144f32354..57f5fe188cd0d 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -79,7 +79,7 @@ enum DocumentReadyState { "loading", "interactive", "complete" }; // [OverrideBuiltins] partial /*sealed*/ interface Document { // resource metadata management - // [PutForwards=href, Unforgeable] + [/*PutForwards=href, */Unforgeable] readonly attribute Location/*?*/ location; // attribute DOMString domain; // readonly attribute DOMString referrer; diff --git a/components/script/dom/webidls/Location.webidl b/components/script/dom/webidls/Location.webidl index 70b496b00ecee..3ab0ecf32b727 100644 --- a/components/script/dom/webidls/Location.webidl +++ b/components/script/dom/webidls/Location.webidl @@ -4,7 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://html.spec.whatwg.org/multipage/#location -/*[Unforgeable]*/ interface Location { +[Unforgeable] interface Location { void assign(DOMString url); //void replace(DOMString url); void reload(); diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 4f461f1a9a667..78341c4071572 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -11,9 +11,9 @@ //[Replaceable] readonly attribute WindowProxy self; readonly attribute Window window; [BinaryName="Self_"] readonly attribute Window self; - /*[Unforgeable]*/ readonly attribute Document document; + [Unforgeable] readonly attribute Document document; // attribute DOMString name; - /*[PutForwards=href, Unforgeable]*/ readonly attribute Location location; + [/*PutForwards=href, */Unforgeable] readonly attribute Location location; //readonly attribute History history; //[Replaceable] readonly attribute BarProp locationbar; //[Replaceable] readonly attribute BarProp menubar; diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 123d9c48d6641..0e4d1768d5136 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -7029,9 +7029,6 @@ [Window interface: window must inherit property "self" with the proper type (1)] expected: FAIL - [Window interface: window must have own property "document"] - expected: FAIL - [Window interface: window must inherit property "name" with the proper type (3)] expected: FAIL @@ -8667,18 +8664,9 @@ [Window interface: window must inherit property "localStorage" with the proper type (124)] expected: FAIL - [Location interface: window.location must have own property "assign"] - expected: FAIL - - [Location interface: calling assign(DOMString) on window.location with too few arguments must throw TypeError] - expected: FAIL - [Location interface: window.location must have own property "replace"] expected: FAIL - [Location interface: window.location must have own property "reload"] - expected: FAIL - [HTMLOptionElement must be primary interface of new Option()] expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/windowproxy.html.ini b/tests/wpt/mozilla/meta/mozilla/windowproxy.html.ini deleted file mode 100644 index ef3f60406f088..0000000000000 --- a/tests/wpt/mozilla/meta/mozilla/windowproxy.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[windowproxy.html] - type: testharness - [Unforgeable location] - expected: FAIL -