From 9af1ffc558e7aa04cfb0d4ef3706947f234ed580 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Mon, 10 Feb 2020 18:55:35 +0000 Subject: [PATCH] Don't generate getters/setters for read only promises Bug: https://github.com/dart-lang/sdk/issues/40530 For attributes that return promises and are read only, we use promiseToFuture casts that should be maintained. Change-Id: I02e23fc9c47321ced64a152c245cbdccd7337033 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134902 Reviewed-by: Sigmund Cherem Commit-Queue: Srujan Gaddam --- sdk_nnbd/lib/html/dart2js/html_dart2js.dart | 26 ++++++++++++++------- tools/dom/scripts/systemhtml.py | 9 ++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/sdk_nnbd/lib/html/dart2js/html_dart2js.dart b/sdk_nnbd/lib/html/dart2js/html_dart2js.dart index 7f6beaf9d6e..dd2287c20e6 100644 --- a/sdk_nnbd/lib/html/dart2js/html_dart2js.dart +++ b/sdk_nnbd/lib/html/dart2js/html_dart2js.dart @@ -603,7 +603,8 @@ class Animation extends EventTarget { AnimationEffectReadOnly? effect; - Future get finished => JS("Future", "#.finished", this); + Future get finished => + promiseToFuture(JS("", "#.finished", this)); String get id => JS("String", "#.id", this); @@ -619,7 +620,8 @@ class Animation extends EventTarget { JS("void", "#.playbackRate = #", this, value); } - Future get ready => JS("Future", "#.ready", this); + Future get ready => + promiseToFuture(JS("", "#.ready", this)); num? startTime; @@ -1548,7 +1550,8 @@ class BeforeInstallPromptEvent extends Event { List get platforms => JS("List", "#.platforms", this); - Future get userChoice => JS("Future", "#.userChoice", this); + Future?> get userChoice => + promiseToFutureAsMap(JS("", "#.userChoice", this)); Future prompt() => promiseToFuture(JS("", "#.prompt()", this)); } @@ -15855,7 +15858,8 @@ class FetchEvent extends ExtendableEvent { bool get isReload => JS("bool", "#.isReload", this); - Future get preloadResponse => JS("Future", "#.preloadResponse", this); + Future get preloadResponse => + promiseToFuture(JS("", "#.preloadResponse", this)); _Request get request => JS("_Request", "#.request", this); @@ -16388,7 +16392,8 @@ class FontFace extends Interceptor { JS("void", "#.featureSettings = #", this, value); } - Future get loaded => JS("Future", "#.loaded", this); + Future get loaded => + promiseToFuture(JS("", "#.loaded", this)); String get status => JS("String", "#.status", this); @@ -20882,7 +20887,7 @@ class MediaKeySession extends EventTarget { static const EventStreamProvider messageEvent = const EventStreamProvider('message'); - Future get closed => JS("Future", "#.closed", this); + Future get closed => promiseToFuture(JS("", "#.closed", this)); num get expiration => JS("num", "#.expiration", this); @@ -26156,7 +26161,9 @@ class PresentationReceiver extends Interceptor { throw new UnsupportedError("Not supported"); } - Future get connectionList => JS("Future", "#.connectionList", this); + Future get connectionList => + promiseToFuture( + JS("", "#.connectionList", this)); } // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a @@ -26307,7 +26314,7 @@ class PromiseRejectionEvent extends Event { type, eventInitDict); - Future get promise => JS("Future", "#.promise", this); + Future get promise => promiseToFuture(JS("", "#.promise", this)); Object? get reason => JS("Object", "#.reason", this); } @@ -28061,7 +28068,8 @@ class ServiceWorkerContainer extends EventTarget { ServiceWorker? get controller => JS("ServiceWorker", "#.controller", this); - Future get ready => JS("Future", "#.ready", this); + Future get ready => + promiseToFuture(JS("", "#.ready", this)); Future getRegistration([String? documentURL]) => promiseToFuture( diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py index 2f904e8f068..cd03ce1c7e3 100644 --- a/tools/dom/scripts/systemhtml.py +++ b/tools/dom/scripts/systemhtml.py @@ -1462,16 +1462,15 @@ class Dart2JSBackend(HtmlDartGenerator): metadata = self._Metadata(attribute.type.id, attribute.id, output_type, attribute.type.nullable) - if self._nnbd and not attribute.type.nullable: - self._AddAttributeUsingProperties(attribute, html_name, read_only, - rename, metadata) - return - input_type = self._NarrowInputType(attribute.type.id) if self._nnbd and attribute.type.nullable: input_type += '?' static_attribute = 'static' if attribute.is_static else '' if not read_only: + if self._nnbd and not attribute.type.nullable: + self._AddAttributeUsingProperties(attribute, html_name, read_only, + rename, metadata) + return if attribute.type.id == 'Promise': _logger.warn('R/W member is a Promise: %s.%s' % (self._interface.id, html_name))