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
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)_
Standard: [NamedConstructor](https://heycam.github.io/webidl/#NamedConstructor)
......
......@@ -65,6 +65,9 @@ ImmutablePrototype
ImplementedAs=*
LegacyTreatAsPartialInterface
LegacyUnenumerableNamedProperties
LegacyWindowAlias=*
LegacyWindowAlias_Measure=|*
LegacyWindowAlias_RuntimeEnabled=*
LenientSetter
LenientThis
LogActivity=|GetterOnly|SetterOnly
......
......@@ -16,9 +16,12 @@ from .database import Database
from .database import DatabaseBody
from .dictionary import Dictionary
from .enumeration import Enumeration
from .exposure import ExposureMutable
from .extended_attribute import ExtendedAttribute
from .extended_attribute import ExtendedAttributesMutable
from .idl_type import IdlTypeFactory
from .interface import Interface
from .interface import LegacyWindowAlias
from .ir_map import IRMap
from .make_copy import make_copy
from .namespace import Namespace
......@@ -513,11 +516,39 @@ class IdlCompiler(object):
old_interfaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE)
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...]
legacy_window_aliases = []
for ir in itertools.chain(old_interfaces, old_namespaces):
for pair in ir.exposure.global_names_and_features:
exposed_map.setdefault(pair.global_name,
[]).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()
......@@ -535,6 +566,12 @@ class IdlCompiler(object):
new_ir.exposed_constructs = map(
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):
"""Sorts dictionary members in alphabetical order."""
old_irs = self._ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY)
......
......@@ -9,6 +9,7 @@ from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
from .composition_parts import WithExposure
from .composition_parts import WithExtendedAttributes
from .composition_parts import WithIdentifier
from .composition_parts import WithOwner
from .constant import Constant
from .constructor import Constructor
......@@ -106,6 +107,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
self.operations = list(operations)
self.operation_groups = []
self.exposed_constructs = []
self.legacy_window_aliases = []
self.indexed_and_named_properties = indexed_and_named_properties
self.stringifier = stringifier
self.iterable = iterable
......@@ -168,6 +170,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
owner=self) for operation_group_ir in ir.operation_groups
])
self._exposed_constructs = tuple(ir.exposed_constructs)
self._legacy_window_aliases = tuple(ir.legacy_window_aliases)
self._indexed_and_named_properties = None
if ir.indexed_and_named_properties:
operations = filter(
......@@ -285,6 +288,11 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
return tuple(
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
def indexed_and_named_properties(self):
"""Returns a IndexedAndNamedProperties or None."""
......@@ -316,6 +324,27 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
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):
"""
Represents a set of indexed/named getter/setter/deleter.
......
......@@ -35,7 +35,9 @@ callback MutationCallback = void (sequence<MutationRecord> mutations,
[
ActiveScriptWrappable,
Exposed=Window
Exposed=Window,
LegacyWindowAlias=WebKitMutationObserver,
LegacyWindowAlias_Measure=PrefixedMutationObserverConstructor
] interface MutationObserver {
[CallWith=ScriptState] constructor(MutationCallback callback);
[RaisesException] void observe(Node target, optional MutationObserverInit options = {});
......
......@@ -6,6 +6,7 @@
[
Exposed=(Window,Worker),
LegacyWindowAlias=WebKitCSSMatrix,
Serializable
] interface DOMMatrix : DOMMatrixReadOnly {
[CallWith=ExecutionContext, RaisesException] constructor(optional (DOMString or sequence<unrestricted double>) init);
......
......@@ -28,7 +28,8 @@
[
Exposed=(Window,Worker),
ImplementedAs=DOMURL
ImplementedAs=DOMURL,
LegacyWindowAlias=webkitURL
] interface URL {
[RaisesException] constructor(USVString url, optional USVString base);
stringifier attribute USVString href;
......
......@@ -26,8 +26,10 @@
// https://w3c.github.io/mediacapture-main/#idl-def-mediastream
[
ActiveScriptWrappable,
Exposed=Window,
ActiveScriptWrappable
LegacyWindowAlias=webkitMediaStream,
LegacyWindowAlias_Measure
] interface MediaStream : EventTarget {
[CallWith=ExecutionContext] constructor();
[CallWith=ExecutionContext] constructor(MediaStream stream);
......
......@@ -64,7 +64,9 @@ enum RTCPeerConnectionState {
// * any -> specific dictionary types like RTCConfiguration
[
ActiveScriptWrappable,
Exposed=Window
Exposed=Window,
LegacyWindowAlias=webkitRTCPeerConnection,
LegacyWindowAlias_Measure
] interface RTCPeerConnection : EventTarget {
// TODO(guidou): There should only be one constructor argument.
[CallWith=ExecutionContext, RaisesException] constructor(optional RTCConfiguration configuration = {}, optional any mediaConstraints);
......
......@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechgrammar
[
LegacyWindowAlias=webkitSpeechGrammar,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject
] interface SpeechGrammar {
[Measure] constructor();
......
......@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechgrammarlist
[
LegacyWindowAlias=webkitSpeechGrammarList,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject
] interface SpeechGrammarList {
[Measure] constructor();
......
......@@ -27,6 +27,9 @@
[
ActiveScriptWrappable,
LegacyWindowAlias=webkitSpeechRecognition,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject
] interface SpeechRecognition : EventTarget {
[CallWith=ExecutionContext, Measure] constructor();
......
......@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechrecognitionerrorevent
[
LegacyWindowAlias=webkitSpeechRecognitionError,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject
] interface SpeechRecognitionErrorEvent : Event {
constructor(DOMString type, optional SpeechRecognitionErrorEventInit eventInitDict = {});
......
......@@ -26,6 +26,9 @@
// https://w3c.github.io/speech-api/#speechrecognitionevent
[
LegacyWindowAlias=webkitSpeechRecognitionEvent,
LegacyWindowAlias_Measure,
LegacyWindowAlias_RuntimeEnabled=ScriptedSpeechRecognition,
NoInterfaceObject
] interface SpeechRecognitionEvent : Event {
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