From a39a3cd141f7df530fece539ab67ff1f4e9c372a Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Fri, 12 Jun 2020 00:52:46 +0000 Subject: [PATCH] [dart:html] Add rename/metadata for some attributes Some fields that were changed to native getters/setters should include renaming/metadata whenever possible to account for name differences. While this is already the case with most fields, this CL adds it to some places that missed it. Annotations for AnimationEffectTiming.duration are changed to be accurate as well. Change-Id: Idb8b94a9b916086d127753f868e97f1a1b9db53f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148464 Reviewed-by: Stephen Adams Commit-Queue: Srujan Gaddam --- sdk/lib/html/dart2js/html_dart2js.dart | 1 + sdk/lib/svg/dart2js/svg_dart2js.dart | 2 +- sdk_nnbd/lib/html/dart2js/html_dart2js.dart | 1 + sdk_nnbd/lib/svg/dart2js/svg_dart2js.dart | 2 +- tools/dom/scripts/dartmetadata.py | 3 +-- tools/dom/scripts/systemhtml.py | 25 ++++++++++++--------- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index 1bb284fe162..77a36ed1898 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -744,6 +744,7 @@ class AnimationEffectTiming extends AnimationEffectTimingReadOnly { // Shadowing definition. + @Returns('num|String|Null') Object get duration native; set duration(Object value) native; diff --git a/sdk/lib/svg/dart2js/svg_dart2js.dart b/sdk/lib/svg/dart2js/svg_dart2js.dart index 5704564d778..c54ac08c685 100644 --- a/sdk/lib/svg/dart2js/svg_dart2js.dart +++ b/sdk/lib/svg/dart2js/svg_dart2js.dart @@ -3244,7 +3244,7 @@ class SvgElement extends Element implements GlobalEventHandlers, NoncedElement { SvgElement.created() : super.created(); // Shadowing definition. - + @JSName('className') AnimatedString get _svgClassName native; @JSName('ownerSVGElement') diff --git a/sdk_nnbd/lib/html/dart2js/html_dart2js.dart b/sdk_nnbd/lib/html/dart2js/html_dart2js.dart index 94b857b4936..04dcc3d96ea 100644 --- a/sdk_nnbd/lib/html/dart2js/html_dart2js.dart +++ b/sdk_nnbd/lib/html/dart2js/html_dart2js.dart @@ -745,6 +745,7 @@ class AnimationEffectTiming extends AnimationEffectTimingReadOnly { // Shadowing definition. + @Returns('num|String|Null') Object? get duration native; set duration(Object? value) native; diff --git a/sdk_nnbd/lib/svg/dart2js/svg_dart2js.dart b/sdk_nnbd/lib/svg/dart2js/svg_dart2js.dart index eea4d4995fc..ebb90155e14 100644 --- a/sdk_nnbd/lib/svg/dart2js/svg_dart2js.dart +++ b/sdk_nnbd/lib/svg/dart2js/svg_dart2js.dart @@ -3282,7 +3282,7 @@ class SvgElement extends Element implements GlobalEventHandlers, NoncedElement { SvgElement.created() : super.created(); // Shadowing definition. - + @JSName('className') AnimatedString get _svgClassName native; @JSName('ownerSVGElement') diff --git a/tools/dom/scripts/dartmetadata.py b/tools/dom/scripts/dartmetadata.py index f7a6bcb393e..71f76022222 100644 --- a/tools/dom/scripts/dartmetadata.py +++ b/tools/dom/scripts/dartmetadata.py @@ -30,8 +30,7 @@ _dart2js_annotations = monitored.Dict( 'dartmetadata._dart2js_annotations', { 'AnimationEffectTiming.duration': [ - "@Creates('Null')", - "@Returns('num|String')", + "@Returns('num|String|Null')", ], 'ArrayBufferView': [ "@Creates('TypedData')", diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py index 4807cf8f583..70248c60f46 100644 --- a/tools/dom/scripts/systemhtml.py +++ b/tools/dom/scripts/systemhtml.py @@ -1394,6 +1394,14 @@ class Dart2JSBackend(HtmlDartGenerator): self._AddAttributeUsingProperties(attribute, html_name, read_only) return + output_type = self.SecureOutputType(attribute.type.id, + can_narrow_type=read_only, + nullable=attribute.type.nullable) + + rename = self._RenamingAnnotation(attribute.id, html_name) + metadata = self._Metadata(attribute.type.id, attribute.id, output_type, + attribute.type.nullable) + # If the attribute is shadowing, we can't generate a shadowing # getter or setter (Issue 1633). # TODO(sra): _FindShadowedAttribute does not take into account the html @@ -1426,7 +1434,8 @@ class Dart2JSBackend(HtmlDartGenerator): 'TreatNullAs' in attribute.ext_attrs)) return self._members_emitter.Emit('\n // Shadowing definition.') - self._AddAttributeUsingProperties(attribute, html_name, read_only) + self._AddAttributeUsingProperties(attribute, html_name, read_only, + rename, metadata) return # If the attribute is shadowed incompatibly in a subclass then we also @@ -1438,23 +1447,18 @@ class Dart2JSBackend(HtmlDartGenerator): if (self._interface.id == 'DOMMatrixReadOnly' or self._interface.id == 'DOMPointReadOnly' or self._interface.id == 'DOMRectReadOnly'): - self._AddAttributeUsingProperties(attribute, html_name, read_only) + self._AddAttributeUsingProperties(attribute, html_name, read_only, + rename, metadata) return # If the type has a conversion we need a getter or setter to contain the # conversion code. if (self._OutputConversion(attribute.type.id, attribute.id) or self._InputConversion(attribute.type.id, attribute.id)): - self._AddAttributeUsingProperties(attribute, html_name, read_only) + self._AddAttributeUsingProperties(attribute, html_name, read_only, + rename, metadata) return - rename = self._RenamingAnnotation(attribute.id, html_name) - output_type = self.SecureOutputType(attribute.type.id, - can_narrow_type=read_only, - nullable=attribute.type.nullable) - metadata = self._Metadata(attribute.type.id, attribute.id, output_type, - attribute.type.nullable) - input_type = self._NarrowInputType(attribute.type.id) if self._nnbd and attribute.type.nullable: input_type += '?' @@ -1536,7 +1540,6 @@ class Dart2JSBackend(HtmlDartGenerator): return self._AddConvertingGetter(attr, html_name, conversion) return_type = self.SecureOutputType(attr.type.id, nullable=attr.type.nullable) - native_type = self._NarrowToImplementationType(attr.type.id) self._members_emitter.Emit( '\n $RENAME' '\n $METADATA'