Skip to content

Commit

Permalink
Auto merge of #24475 - saschanaz:legacywindowalias, r=jdm
Browse files Browse the repository at this point in the history
Support [LegacyWindowAlias]

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24474 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
  • Loading branch information
bors-servo committed Oct 19, 2019
2 parents 118a9ec + e81b678 commit 605ddbe
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 33 deletions.
21 changes: 18 additions & 3 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -2925,13 +2925,14 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
properties should be a PropertyArrays instance.
"""
def __init__(self, descriptor, properties, haveUnscopables):
def __init__(self, descriptor, properties, haveUnscopables, haveLegacyWindowAliases):
args = [Argument('SafeJSContext', 'cx'), Argument('HandleObject', 'global'),
Argument('*mut ProtoOrIfaceArray', 'cache')]
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', 'void', args,
unsafe=True)
self.properties = properties
self.haveUnscopables = haveUnscopables
self.haveLegacyWindowAliases = haveLegacyWindowAliases

def definition_body(self):
name = self.descriptor.interface.identifier.name
Expand Down Expand Up @@ -2990,7 +2991,8 @@ def definition_body(self):

properties = {
"id": name,
"unscopables": "unscopable_names" if self.haveUnscopables else "&[]"
"unscopables": "unscopable_names" if self.haveUnscopables else "&[]",
"legacyWindowAliases": "legacy_window_aliases" if self.haveLegacyWindowAliases else "&[]"
}
for arrayName in self.properties.arrayNames():
array = getattr(self.properties, arrayName)
Expand Down Expand Up @@ -3058,6 +3060,7 @@ def definition_body(self):
prototype.handle(),
%(name)s,
%(length)s,
%(legacyWindowAliases)s,
interface.handle_mut());
assert!(!interface.is_null());""" % properties))
if self.descriptor.shouldCacheConstructor():
Expand Down Expand Up @@ -6266,6 +6269,15 @@ def reexportedName(name):
if descriptor.weakReferenceable:
cgThings.append(CGWeakReferenceableTrait(descriptor))

legacyWindowAliases = descriptor.interface.legacyWindowAliases
haveLegacyWindowAliases = len(legacyWindowAliases) != 0
if haveLegacyWindowAliases:
cgThings.append(
CGList([CGGeneric("const legacy_window_aliases: &'static [&'static [u8]] = &["),
CGIndenter(CGList([CGGeneric(str_to_const_array(name)) for
name in legacyWindowAliases], ",\n")),
CGGeneric("];\n")], "\n"))

cgThings.append(CGGeneric(str(properties)))

if not descriptor.interface.getExtendedAttribute("Inline"):
Expand All @@ -6287,7 +6299,8 @@ def reexportedName(name):
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
reexports.append('DefineDOMInterface')
cgThings.append(CGConstructorEnabled(descriptor))
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties, haveUnscopables))
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties, haveUnscopables,
haveLegacyWindowAliases))

cgThings = generate_imports(config, CGList(cgThings, '\n'), [descriptor])
cgThings = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
Expand Down Expand Up @@ -7453,6 +7466,8 @@ def InterfaceObjectMapData(config):
for d in config.getDescriptors(hasInterfaceObject=True, isInline=False):
binding = toBindingNamespace(d.name)
pairs.append((d.name, binding, binding))
for alias in d.interface.legacyWindowAliases:
pairs.append((alias, binding, binding))
for ctor in d.interface.namedConstructors:
pairs.append((ctor.identifier.name, binding, binding))
pairs.sort(key=operator.itemgetter(0))
Expand Down
7 changes: 7 additions & 0 deletions components/script/dom/bindings/interface.rs
Expand Up @@ -238,6 +238,7 @@ pub fn create_noncallback_interface_object(
interface_prototype_object: HandleObject,
name: &[u8],
length: u32,
legacy_window_alias_names: &[&[u8]],
rval: MutableHandleObject,
) {
create_object(
Expand All @@ -260,6 +261,12 @@ pub fn create_noncallback_interface_object(
define_name(cx, rval.handle(), name);
define_length(cx, rval.handle(), i32::try_from(length).expect("overflow"));
define_on_global_object(cx, global, name, rval.handle());

if is_exposed_in(global, Globals::WINDOW) {
for legacy_window_alias in legacy_window_alias_names {
define_on_global_object(cx, global, legacy_window_alias, rval.handle());
}
}
}

/// Create and define the named constructors of a non-callback interface.
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/webidls/DOMMatrix.webidl
Expand Up @@ -10,7 +10,8 @@
* related or neighboring rights to this work.
*/

[Exposed=(Window,Worker)]
[Exposed=(Window,Worker),
LegacyWindowAlias=WebKitCSSMatrix]
interface DOMMatrix : DOMMatrixReadOnly {
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);

Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/webidls/URL.webidl
Expand Up @@ -3,7 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// https://url.spec.whatwg.org/#url
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker),
LegacyWindowAlias=webkitURL]
interface URL {
[Throws] constructor(USVString url, optional USVString base);
[SetterThrows]
Expand Down
7 changes: 0 additions & 7 deletions tests/wpt/metadata/css/geometry/WebKitCSSMatrix.html.ini

This file was deleted.

18 changes: 0 additions & 18 deletions tests/wpt/metadata/url/idlharness.any.js.ini

This file was deleted.

4 changes: 2 additions & 2 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -18966,11 +18966,11 @@
"testharness"
],
"mozilla/interfaces.html": [
"7aed97b42d8fe974ea489db66905d9fbc0edb84d",
"1207eaa2d8ff55e0c2216086b5a2c90a41ff78cf",
"testharness"
],
"mozilla/interfaces.js": [
"26db0c23e544d38f02b9573ffaa44bf5dee8370a",
"f1854a3ae00493554006ad2c483489f4be8450a6",
"support"
],
"mozilla/interfaces.worker.js": [
Expand Down
1 change: 1 addition & 0 deletions tests/wpt/mozilla/tests/mozilla/interfaces.html
Expand Up @@ -244,6 +244,7 @@
"WebGLObject",
"WebGLActiveInfo",
"WebGLShaderPrecisionFormat",
"WebKitCSSMatrix",
"WebSocket",
"WheelEvent",
"Window",
Expand Down
1 change: 0 additions & 1 deletion tests/wpt/mozilla/tests/mozilla/interfaces.js
Expand Up @@ -45,7 +45,6 @@ function test_interfaces(interfaceNamesInGlobalScope) {
"Uint32Array",
"Uint8Array",
"Uint8ClampedArray",
"Uint8ClampedArray",
"WeakMap",
"WeakSet",
"WebAssembly",
Expand Down

0 comments on commit 605ddbe

Please sign in to comment.