Commit 5e9ef433 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Supports [LegacyWindowAlias] in the new Web IDL database

The current bindings generator does not recognize the extended
attributes introduced in this patch, and no behavioral change
in prod.

Bug: 839389
Change-Id: I75afcdc75b293c474557de7076c0885a59cb798d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2129786Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755308}
parent df1dcdca
...@@ -333,6 +333,18 @@ In the example above, named properties in `HTMLCollection` instances (such as th ...@@ -333,6 +333,18 @@ In the example above, named properties in `HTMLCollection` instances (such as th
The `[LegacyUnenumerableNamedProperties]` extended attribute must be used **only** in interfaces that support named properties. The `[LegacyUnenumerableNamedProperties]` extended attribute must be used **only** in interfaces that support named properties.
### [LegacyWindowAlias] _(i)_
Standard: [LegacyWindowAlias](https://heycam.github.io/webidl/#LegacyWindowAlias)
### [LegacyWindowAlias_Measure] _(i)_
Summary: The same as `[Measure]` and `[MeasureAs]` but applied to the property exposed as `[LegacyWindowAlias]`. Unlike `[Measure]`, you can optionally provide the feature name like `[LegacyWindowAlias_Measure=FeatureName]`.
### [LegacyWindowAlias_RuntimeEnabled] _(i)_
Summary: The same as `[RuntimeEnabled]` but applied to the property exposed as `[LegacyWindowAlias]`.
### [NamedConstructor] _(i)_ ### [NamedConstructor] _(i)_
Standard: [NamedConstructor](https://heycam.github.io/webidl/#NamedConstructor) Standard: [NamedConstructor](https://heycam.github.io/webidl/#NamedConstructor)
......
...@@ -65,6 +65,9 @@ ImmutablePrototype ...@@ -65,6 +65,9 @@ ImmutablePrototype
ImplementedAs=* ImplementedAs=*
LegacyTreatAsPartialInterface LegacyTreatAsPartialInterface
LegacyUnenumerableNamedProperties LegacyUnenumerableNamedProperties
LegacyWindowAlias=*
LegacyWindowAlias_Measure=|*
LegacyWindowAlias_RuntimeEnabled=*
LenientSetter LenientSetter
LenientThis LenientThis
LogActivity=|GetterOnly|SetterOnly LogActivity=|GetterOnly|SetterOnly
......
...@@ -16,9 +16,12 @@ from .database import Database ...@@ -16,9 +16,12 @@ from .database import Database
from .database import DatabaseBody from .database import DatabaseBody
from .dictionary import Dictionary from .dictionary import Dictionary
from .enumeration import Enumeration from .enumeration import Enumeration
from .exposure import ExposureMutable
from .extended_attribute import ExtendedAttribute from .extended_attribute import ExtendedAttribute
from .extended_attribute import ExtendedAttributesMutable
from .idl_type import IdlTypeFactory from .idl_type import IdlTypeFactory
from .interface import Interface from .interface import Interface
from .interface import LegacyWindowAlias
from .ir_map import IRMap from .ir_map import IRMap
from .make_copy import make_copy from .make_copy import make_copy
from .namespace import Namespace from .namespace import Namespace
...@@ -513,11 +516,39 @@ class IdlCompiler(object): ...@@ -513,11 +516,39 @@ class IdlCompiler(object):
old_interfaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE) old_interfaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE)
old_namespaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.NAMESPACE) old_namespaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.NAMESPACE)
def make_legacy_window_alias(ir):
ext_attrs = ir.extended_attributes
identifier = Identifier(ext_attrs.value_of('LegacyWindowAlias'))
original = self._ref_to_idl_def_factory.create(ir.identifier)
extended_attributes = ExtendedAttributesMutable()
exposure = ExposureMutable()
if 'LegacyWindowAlias_Measure' in ext_attrs:
extended_attributes.append(
ExtendedAttribute(
key='Measure',
values=ext_attrs.value_of(
'LegacyWindowAlias_Measure')))
if 'LegacyWindowAlias_RuntimeEnabled' in ext_attrs:
feature_name = ext_attrs.value_of(
'LegacyWindowAlias_RuntimeEnabled')
extended_attributes.append(
ExtendedAttribute(
key='RuntimeEnabled', values=feature_name))
exposure.add_runtime_enabled_feature(feature_name)
return LegacyWindowAlias(
identifier=identifier,
original=original,
extended_attributes=extended_attributes,
exposure=exposure)
exposed_map = {} # global name: [construct's identifier...] exposed_map = {} # global name: [construct's identifier...]
legacy_window_aliases = []
for ir in itertools.chain(old_interfaces, old_namespaces): for ir in itertools.chain(old_interfaces, old_namespaces):
for pair in ir.exposure.global_names_and_features: for pair in ir.exposure.global_names_and_features:
exposed_map.setdefault(pair.global_name, exposed_map.setdefault(pair.global_name,
[]).append(ir.identifier) []).append(ir.identifier)
if 'LegacyWindowAlias' in ir.extended_attributes:
legacy_window_aliases.append(make_legacy_window_alias(ir))
self._ir_map.move_to_new_phase() self._ir_map.move_to_new_phase()
...@@ -535,6 +566,12 @@ class IdlCompiler(object): ...@@ -535,6 +566,12 @@ class IdlCompiler(object):
new_ir.exposed_constructs = map( new_ir.exposed_constructs = map(
self._ref_to_idl_def_factory.create, sorted(constructs)) self._ref_to_idl_def_factory.create, sorted(constructs))
assert not new_ir.legacy_window_aliases
if new_ir.identifier != 'Window':
continue
new_ir.legacy_window_aliases = sorted(
legacy_window_aliases, key=lambda x: x.identifier)
def _sort_dictionary_members(self): def _sort_dictionary_members(self):
"""Sorts dictionary members in alphabetical order.""" """Sorts dictionary members in alphabetical order."""
old_irs = self._ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY) old_irs = self._ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY)
......
...@@ -9,6 +9,7 @@ from .composition_parts import WithComponent ...@@ -9,6 +9,7 @@ from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo from .composition_parts import WithDebugInfo
from .composition_parts import WithExposure from .composition_parts import WithExposure
from .composition_parts import WithExtendedAttributes from .composition_parts import WithExtendedAttributes
from .composition_parts import WithIdentifier
from .composition_parts import WithOwner from .composition_parts import WithOwner
from .constant import Constant from .constant import Constant
from .constructor import Constructor from .constructor import Constructor
...@@ -106,6 +107,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -106,6 +107,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
self.operations = list(operations) self.operations = list(operations)
self.operation_groups = [] self.operation_groups = []
self.exposed_constructs = [] self.exposed_constructs = []
self.legacy_window_aliases = []
self.indexed_and_named_properties = indexed_and_named_properties self.indexed_and_named_properties = indexed_and_named_properties
self.stringifier = stringifier self.stringifier = stringifier
self.iterable = iterable self.iterable = iterable
...@@ -168,6 +170,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -168,6 +170,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
owner=self) for operation_group_ir in ir.operation_groups owner=self) for operation_group_ir in ir.operation_groups
]) ])
self._exposed_constructs = tuple(ir.exposed_constructs) self._exposed_constructs = tuple(ir.exposed_constructs)
self._legacy_window_aliases = tuple(ir.legacy_window_aliases)
self._indexed_and_named_properties = None self._indexed_and_named_properties = None
if ir.indexed_and_named_properties: if ir.indexed_and_named_properties:
operations = filter( operations = filter(
...@@ -285,6 +288,11 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -285,6 +288,11 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
return tuple( return tuple(
map(lambda ref: ref.target_object, self._exposed_constructs)) map(lambda ref: ref.target_object, self._exposed_constructs))
@property
def legacy_window_aliases(self):
"""Returns a list of properties exposed as [LegacyWindowAlias]."""
return self._legacy_window_aliases
@property @property
def indexed_and_named_properties(self): def indexed_and_named_properties(self):
"""Returns a IndexedAndNamedProperties or None.""" """Returns a IndexedAndNamedProperties or None."""
...@@ -316,6 +324,27 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -316,6 +324,27 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
return True return True
class LegacyWindowAlias(WithIdentifier, WithExtendedAttributes, WithExposure):
"""
Represents a property exposed on a Window object as [LegacyWindowAlias].
"""
def __init__(self, identifier, original, extended_attributes, exposure):
assert isinstance(original, RefById)
WithIdentifier.__init__(self, identifier)
WithExtendedAttributes.__init__(
self, extended_attributes, readonly=True)
WithExposure.__init__(self, exposure, readonly=True)
self._original = original
@property
def original(self):
"""Returns the original object of this alias."""
return self._original.target_object
class IndexedAndNamedProperties(WithOwner, WithDebugInfo): class IndexedAndNamedProperties(WithOwner, WithDebugInfo):
""" """
Represents a set of indexed/named getter/setter/deleter. Represents a set of indexed/named getter/setter/deleter.
......
...@@ -35,7 +35,9 @@ callback MutationCallback = void (sequence<MutationRecord> mutations, ...@@ -35,7 +35,9 @@ callback MutationCallback = void (sequence<MutationRecord> mutations,
[ [
ActiveScriptWrappable, ActiveScriptWrappable,
Exposed=Window Exposed=Window,
LegacyWindowAlias=WebKitMutationObserver,
LegacyWindowAlias_Measure=PrefixedMutationObserverConstructor
] interface MutationObserver { ] interface MutationObserver {
[CallWith=ScriptState] constructor(MutationCallback callback); [CallWith=ScriptState] constructor(MutationCallback callback);
[RaisesException] void observe(Node target, optional MutationObserverInit options = {}); [RaisesException] void observe(Node target, optional MutationObserverInit options = {});
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
[ [
Exposed=(Window,Worker), Exposed=(Window,Worker),
LegacyWindowAlias=WebKitCSSMatrix,
Serializable Serializable
] interface DOMMatrix : DOMMatrixReadOnly { ] interface DOMMatrix : DOMMatrixReadOnly {
[CallWith=ExecutionContext, RaisesException] constructor(optional (DOMString or sequence<unrestricted double>) init); [CallWith=ExecutionContext, RaisesException] constructor(optional (DOMString or sequence<unrestricted double>) init);
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
[ [
Exposed=(Window,Worker), Exposed=(Window,Worker),
ImplementedAs=DOMURL ImplementedAs=DOMURL,
LegacyWindowAlias=webkitURL
] interface URL { ] interface URL {
[RaisesException] constructor(USVString url, optional USVString base); [RaisesException] constructor(USVString url, optional USVString base);
stringifier attribute USVString href; stringifier attribute USVString href;
......
...@@ -26,8 +26,10 @@ ...@@ -26,8 +26,10 @@
// https://w3c.github.io/mediacapture-main/#idl-def-mediastream // https://w3c.github.io/mediacapture-main/#idl-def-mediastream
[ [
ActiveScriptWrappable,
Exposed=Window, Exposed=Window,
ActiveScriptWrappable LegacyWindowAlias=webkitMediaStream,
LegacyWindowAlias_Measure
] interface MediaStream : EventTarget { ] interface MediaStream : EventTarget {
[CallWith=ExecutionContext] constructor(); [CallWith=ExecutionContext] constructor();
[CallWith=ExecutionContext] constructor(MediaStream stream); [CallWith=ExecutionContext] constructor(MediaStream stream);
......
...@@ -64,7 +64,9 @@ enum RTCPeerConnectionState { ...@@ -64,7 +64,9 @@ enum RTCPeerConnectionState {
// * any -> specific dictionary types like RTCConfiguration // * any -> specific dictionary types like RTCConfiguration
[ [
ActiveScriptWrappable, ActiveScriptWrappable,
Exposed=Window Exposed=Window,
LegacyWindowAlias=webkitRTCPeerConnection,
LegacyWindowAlias_Measure
] interface RTCPeerConnection : EventTarget { ] interface RTCPeerConnection : EventTarget {
// TODO(guidou): There should only be one constructor argument. // TODO(guidou): There should only be one constructor argument.
[CallWith=ExecutionContext, RaisesException] constructor(optional RTCConfiguration configuration = {}, optional any mediaConstraints); [CallWith=ExecutionContext, RaisesException] constructor(optional RTCConfiguration configuration = {}, optional any mediaConstraints);
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechgrammar // https://w3c.github.io/speech-api/#speechgrammar
[ [
LegacyWindowAlias=webkitSpeechGrammar,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject NoInterfaceObject
] interface SpeechGrammar { ] interface SpeechGrammar {
[Measure] constructor(); [Measure] constructor();
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechgrammarlist // https://w3c.github.io/speech-api/#speechgrammarlist
[ [
LegacyWindowAlias=webkitSpeechGrammarList,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject NoInterfaceObject
] interface SpeechGrammarList { ] interface SpeechGrammarList {
[Measure] constructor(); [Measure] constructor();
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
[ [
ActiveScriptWrappable, ActiveScriptWrappable,
LegacyWindowAlias=webkitSpeechRecognition,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject NoInterfaceObject
] interface SpeechRecognition : EventTarget { ] interface SpeechRecognition : EventTarget {
[CallWith=ExecutionContext, Measure] constructor(); [CallWith=ExecutionContext, Measure] constructor();
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechrecognitionerrorevent // https://w3c.github.io/speech-api/#speechrecognitionerrorevent
[ [
LegacyWindowAlias=webkitSpeechRecognitionError,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject NoInterfaceObject
] interface SpeechRecognitionErrorEvent : Event { ] interface SpeechRecognitionErrorEvent : Event {
constructor(DOMString type, optional SpeechRecognitionErrorEventInit eventInitDict = {}); constructor(DOMString type, optional SpeechRecognitionErrorEventInit eventInitDict = {});
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechrecognitionevent // https://w3c.github.io/speech-api/#speechrecognitionevent
[ [
LegacyWindowAlias=webkitSpeechRecognitionEvent,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject NoInterfaceObject
] interface SpeechRecognitionEvent : Event { ] interface SpeechRecognitionEvent : Event {
constructor(DOMString type, optional SpeechRecognitionEventInit initDict = {}); constructor(DOMString type, optional SpeechRecognitionEventInit initDict = {});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment