Fixed Service Workers and any Promise/Future API with a Dictionary parameter.

APIs in dart:html (that take a Dictionary) will receive a Dart Map parameter.  The Map parameter
must be converted to a Dictionary before passing to the browser's API.  Before this change,
any Promise/Future API with a Map/Dictionary parameter never called the Promise and didn't
return a Dart Future - now it does.

This caused a number of breaks especially in Service Workers (register, etc.).  Here is a
complete list of the fixed APIs:

BackgroundFetchManager
    Future<BackgroundFetchRegistration> fetch(String id, Object requests, [Map options])

CacheStorage
    Future match(/*RequestInfo*/ request, [Map options])

CanMakePayment
    Future<List<Client>> matchAll([Map options])

CookieStore
    Future getAll([Map options])
    Future set(String name, String value, [Map options])

CredentialsContainer
    Future get([Map options])
    Future create([Map options])

DirectoryEntry
    Future<Entry> _getDirectory(String path, {Map options})
    Future<Entry> _getFile(String path, {Map options})

ImageCapture
    Future setOptions(Map photoSettings)

MediaCapabilities
    Future<MediaCapabilitiesInfo> decodingInfo(Map configuration)
    Future<MediaCapabilitiesInfo> encodingInfo(Map configuration)

MediaStreamTrack
    Future applyConstraints([Map constraints])

Navigator
    Future requestKeyboardLock([List<String> keyCodes])
    Future requestMidiAccess([Map options])
    Future share([Map data])

OffscreenCanvas
    Future<Blob> convertToBlob([Map options])

PaymentInstruments
    Future set(String instrumentKey, Map details)

Permissions
    Future<PermissionStatus> query(Map permission)
    Future<PermissionStatus> request(Map permissions)
    Future<PermissionStatus> revoke(Map permission)

PushManager
    Future permissionState([Map options])
    Future<PushSubscription> subscribe([Map options])

RtcPeerConnection
    REMOVED:  Future createAnswer([options_OR_successCallback,
                                   RtcPeerConnectionErrorCallback failureCallback,
                                   Map mediaConstraints])
    REMOVED:  Future createOffer([options_OR_successCallback,
                                  RtcPeerConnectionErrorCallback failureCallback,
                                  Map rtcOfferOptions])
    REMOVED:  Future setLocalDescription(Map description, VoidCallback successCallback,
                                         [RtcPeerConnectionErrorCallback failureCallback])
    REMOVED:  Future setLocalDescription(Map description, VoidCallback successCallback,
                                         [RtcPeerConnectionErrorCallback failureCallback])
    Future<RtcSessionDescription> createAnswer([Map options])
    Future<RtcSessionDescription> createOffer([Map options])
    Future setLocalDescription(Map description)
    Future setRemoteDescription(Map description)

ServiceWorkerContainer
    Future<ServiceWorkerRegistration> register(String url, [Map options])

ServiceWorkerRegistration
    Future<List<Notification>> getNotifications([Map filter])
    Future showNotification(String title, [Map options])

VRDevice
    Future requestSession([Map options])
    Future supportsSession([Map options])

VRSession
    Future requestFrameOfReference(String type, [Map options])

Window
    Future fetch(/*RequestInfo*/ input, [Map init])

WorkerGlobalScope
    Future fetch(/*RequestInfo*/ input, [Map init])


In addition, exposed Service Worker "self" as a static getter named "instance".  The
instance is exposed on four different Service Worker classes and can throw a InstanceTypeError
if the instance isn't of the class expected (WorkerGlobalScope.instance will always work
and not throw):

*   SharedWorkerGlobalScope.instance
*   DedicatedWorkerGlobalScope.instance
*   ServiceWorkerGlobalScope.instance
*   WorkerGlobalScope.instance

R=vsm@google.com

Bug: #34202
Change-Id: I641ccbff7cc771465dd32c73db20eba5d6667939
Reviewed-on: https://dart-review.googlesource.com/c/74482
Commit-Queue: Terry Lucas <terry@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>
Reviewed-by: Jenny Messerly <jmesserly@google.com>
This commit is contained in:
Terry Lucas 2018-10-14 22:48:33 +00:00 committed by commit-bot@chromium.org
parent 77c5677abe
commit 490421d166
14 changed files with 482 additions and 418 deletions

View file

@ -1,6 +1,109 @@
## 2.1.0-dev.XX.0
(Add new changes here, and they will be copied to the change section for the
next dev version)
#### `dart:html`
Fixed Service Workers and any Promise/Future API with a Dictionary parameter.
APIs in dart:html (that take a Dictionary) will receive a Dart Map parameter. The Map parameter
must be converted to a Dictionary before passing to the browser's API. Before this change,
any Promise/Future API with a Map/Dictionary parameter never called the Promise and didn't
return a Dart Future - now it does.
This caused a number of breaks especially in Service Workers (register, etc.). Here is a
complete list of the fixed APIs:
BackgroundFetchManager
Future<BackgroundFetchRegistration> fetch(String id, Object requests, [Map options])
CacheStorage
Future match(/*RequestInfo*/ request, [Map options])
CanMakePayment
Future<List<Client>> matchAll([Map options])
CookieStore
Future getAll([Map options])
Future set(String name, String value, [Map options])
CredentialsContainer
Future get([Map options])
Future create([Map options])
ImageCapture
Future setOptions(Map photoSettings)
MediaCapabilities
Future<MediaCapabilitiesInfo> decodingInfo(Map configuration)
Future<MediaCapabilitiesInfo> encodingInfo(Map configuration)
MediaStreamTrack
Future applyConstraints([Map constraints])
Navigator
Future requestKeyboardLock([List<String> keyCodes])
Future requestMidiAccess([Map options])
Future share([Map data])
OffscreenCanvas
Future<Blob> convertToBlob([Map options])
PaymentInstruments
Future set(String instrumentKey, Map details)
Permissions
Future<PermissionStatus> query(Map permission)
Future<PermissionStatus> request(Map permissions)
Future<PermissionStatus> revoke(Map permission)
PushManager
Future permissionState([Map options])
Future<PushSubscription> subscribe([Map options])
RtcPeerConnection
* **CHANGED** Future createAnswer([options_OR_successCallback,
RtcPeerConnectionErrorCallback failureCallback,
Map mediaConstraints])
Future<RtcSessionDescription> createAnswer([Map options])
* **CHANGED** Future createOffer([options_OR_successCallback,
RtcPeerConnectionErrorCallback failureCallback,
Map rtcOfferOptions])
Future<RtcSessionDescription> createOffer([Map options])
* **CHANGED** Future setLocalDescription(Map description, VoidCallback successCallback,
[RtcPeerConnectionErrorCallback failureCallback])
Future setLocalDescription(Map description)
* **CHANGED** Future setLocalDescription(Map description, VoidCallback successCallback,
[RtcPeerConnectionErrorCallback failureCallback])
Future setRemoteDescription(Map description)
ServiceWorkerContainer
Future<ServiceWorkerRegistration> register(String url, [Map options])
ServiceWorkerRegistration
Future<List<Notification>> getNotifications([Map filter])
Future showNotification(String title, [Map options])
VRDevice
Future requestSession([Map options])
Future supportsSession([Map options])
VRSession
Future requestFrameOfReference(String type, [Map options])
Window
Future fetch(/*RequestInfo*/ input, [Map init])
WorkerGlobalScope
Future fetch(/*RequestInfo*/ input, [Map init])
In addition, exposed Service Worker "self" as a static getter named "instance". The
instance is exposed on four different Service Worker classes and can throw a InstanceTypeError
if the instance isn't of the class expected (WorkerGlobalScope.instance will always work
and not throw):
* SharedWorkerGlobalScope.instance
* DedicatedWorkerGlobalScope.instance
* ServiceWorkerGlobalScope.instance
* WorkerGlobalScope.instance
### Language

View file

@ -142,6 +142,9 @@ class HtmlElement extends Element implements NoncedElement {
*/
typedef void FontFaceSetForEachCallback(
FontFace fontFace, FontFace fontFaceAgain, FontFaceSet set);
WorkerGlobalScope get _workerSelf => JS('WorkerGlobalScope', 'self');
// 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
// BSD-style license that can be found in the LICENSE file.
@ -1192,19 +1195,16 @@ class BackgroundFetchManager extends Interceptor {
throw new UnsupportedError("Not supported");
}
Future fetch(String id, Object requests, [Map options]) {
Future<BackgroundFetchRegistration> fetch(String id, Object requests,
[Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _fetch_1(id, requests, options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _fetch_2(id, requests);
return promiseToFuture<BackgroundFetchRegistration>(
JS("", "#.fetch(#, #, #)", this, id, requests, options_dict));
}
@JSName('fetch')
Future _fetch_1(id, requests, options) native;
@JSName('fetch')
Future _fetch_2(id, requests) native;
Future<BackgroundFetchRegistration> get(String id) =>
promiseToFuture<BackgroundFetchRegistration>(
JS("", "#.get(#)", this, id));
@ -1840,18 +1840,14 @@ class CacheStorage extends Interceptor {
Future keys() => promiseToFuture(JS("", "#.keys()", this));
Future match(/*RequestInfo*/ request, [Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _match_1(request, options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _match_2(request);
return promiseToFuture(
JS("", "#.match(#, #)", this, request, options_dict));
}
@JSName('match')
Future _match_1(request, options) native;
@JSName('match')
Future _match_2(request) native;
Future open(String cacheName) =>
promiseToFuture(JS("", "#.open(#)", this, cacheName));
}
@ -2823,19 +2819,15 @@ class Clients extends Interceptor {
Future get(String id) => promiseToFuture(JS("", "#.get(#)", this, id));
Future matchAll([Map options]) {
Future<List<Client>> matchAll([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _matchAll_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _matchAll_2();
return promiseToFuture<List<Client>>(
JS("", "#.matchAll(#)", this, options_dict));
}
@JSName('matchAll')
Future _matchAll_1(options) native;
@JSName('matchAll')
Future _matchAll_2() native;
Future<WindowClient> openWindow(String url) =>
promiseToFuture<WindowClient>(JS("", "#.openWindow(#)", this, url));
}
@ -2997,30 +2989,21 @@ class CookieStore extends Interceptor {
}
Future getAll([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _getAll_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _getAll_2();
return promiseToFuture(JS("", "#.getAll(#)", this, options_dict));
}
@JSName('getAll')
Future _getAll_1(options) native;
@JSName('getAll')
Future _getAll_2() native;
Future set(String name, String value, [Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _set_1(name, value, options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _set_2(name, value);
return promiseToFuture(
JS("", "#.set(#, #, #)", this, name, value, options_dict));
}
@JSName('set')
Future _set_1(name, value, options) native;
@JSName('set')
Future _set_2(name, value) native;
}
// 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
@ -3090,31 +3073,21 @@ class CredentialsContainer extends Interceptor {
}
Future create([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _create_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _create_2();
return promiseToFuture(JS("", "#.create(#)", this, options_dict));
}
@JSName('create')
Future _create_1(options) native;
@JSName('create')
Future _create_2() native;
Future get([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _get_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _get_2();
return promiseToFuture(JS("", "#.get(#)", this, options_dict));
}
@JSName('get')
Future _get_1(options) native;
@JSName('get')
Future _get_2() native;
Future preventSilentAccess() =>
promiseToFuture(JS("", "#.preventSilentAccess()", this));
@ -8722,7 +8695,12 @@ class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
/// Stream of `message` events handled by this [DedicatedWorkerGlobalScope].
Stream<MessageEvent> get onMessage => messageEvent.forTarget(this);
static DedicatedWorkerGlobalScope get instance {
return _workerSelf as DedicatedWorkerGlobalScope;
}
}
// 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
// BSD-style license that can be found in the LICENSE file.
@ -17975,25 +17953,18 @@ class ImageCapture extends Interceptor {
promiseToFuture<ImageBitmap>(JS("", "#.grabFrame()", this));
Future setOptions(Map photoSettings) {
var photoSettings_1 = convertDartToNative_Dictionary(photoSettings);
return _setOptions_1(photoSettings_1);
var photoSettings_dict = convertDartToNative_Dictionary(photoSettings);
return promiseToFuture(JS("", "#.setOptions(#)", this, photoSettings_dict));
}
@JSName('setOptions')
Future _setOptions_1(photoSettings) native;
Future takePhoto([Map photoSettings]) {
Future<Blob> takePhoto([Map photoSettings]) {
var photoSettings_dict = null;
if (photoSettings != null) {
var photoSettings_1 = convertDartToNative_Dictionary(photoSettings);
return _takePhoto_1(photoSettings_1);
photoSettings_dict = convertDartToNative_Dictionary(photoSettings);
}
return _takePhoto_2();
return promiseToFuture<Blob>(
JS("", "#.takePhoto(#)", this, photoSettings_dict));
}
@JSName('takePhoto')
Future _takePhoto_1(photoSettings) native;
@JSName('takePhoto')
Future _takePhoto_2() native;
}
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
@ -19344,21 +19315,17 @@ class MediaCapabilities extends Interceptor {
throw new UnsupportedError("Not supported");
}
Future decodingInfo(Map configuration) {
var configuration_1 = convertDartToNative_Dictionary(configuration);
return _decodingInfo_1(configuration_1);
Future<MediaCapabilitiesInfo> decodingInfo(Map configuration) {
var configuration_dict = convertDartToNative_Dictionary(configuration);
return promiseToFuture<MediaCapabilitiesInfo>(
JS("", "#.decodingInfo(#)", this, configuration_dict));
}
@JSName('decodingInfo')
Future _decodingInfo_1(configuration) native;
Future encodingInfo(Map configuration) {
var configuration_1 = convertDartToNative_Dictionary(configuration);
return _encodingInfo_1(configuration_1);
Future<MediaCapabilitiesInfo> encodingInfo(Map configuration) {
var configuration_dict = convertDartToNative_Dictionary(configuration);
return promiseToFuture<MediaCapabilitiesInfo>(
JS("", "#.encodingInfo(#)", this, configuration_dict));
}
@JSName('encodingInfo')
Future _encodingInfo_1(configuration) native;
}
// 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
@ -20166,18 +20133,14 @@ class MediaStreamTrack extends EventTarget {
final String readyState;
Future applyConstraints([Map constraints]) {
var constraints_dict = null;
if (constraints != null) {
var constraints_1 = convertDartToNative_Dictionary(constraints);
return _applyConstraints_1(constraints_1);
constraints_dict = convertDartToNative_Dictionary(constraints);
}
return _applyConstraints_2();
return promiseToFuture(
JS("", "#.applyConstraints(#)", this, constraints_dict));
}
@JSName('applyConstraints')
Future _applyConstraints_1(constraints) native;
@JSName('applyConstraints')
Future _applyConstraints_2() native;
MediaStreamTrack clone() native;
Map getCapabilities() {
@ -21562,23 +21525,22 @@ class Navigator extends NavigatorConcurrentHardware
}
@JSName('requestKeyboardLock')
Future _requestKeyboardLock_1(List keyCodes) native;
Future _requestKeyboardLock_1(List keyCodes) =>
promiseToFuture(JS("", "#.requestKeyboardLock(#)", this, keyCodes));
@JSName('requestKeyboardLock')
Future _requestKeyboardLock_2() native;
Future _requestKeyboardLock_2() =>
promiseToFuture(JS("", "#.requestKeyboardLock()", this));
@JSName('requestMIDIAccess')
Future requestMidiAccess([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _requestMidiAccess_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _requestMidiAccess_2();
return promiseToFuture(
JS("", "#.requestMidiAccess(#)", this, options_dict));
}
@JSName('requestMIDIAccess')
Future _requestMidiAccess_1(options) native;
@JSName('requestMIDIAccess')
Future _requestMidiAccess_2() native;
Future requestMediaKeySystemAccess(
String keySystem, List<Map> supportedConfigurations) =>
promiseToFuture(JS("", "#.requestMediaKeySystemAccess(#, #)", this,
@ -21587,18 +21549,13 @@ class Navigator extends NavigatorConcurrentHardware
bool sendBeacon(String url, Object data) native;
Future share([Map data]) {
var data_dict = null;
if (data != null) {
var data_1 = convertDartToNative_Dictionary(data);
return _share_1(data_1);
data_dict = convertDartToNative_Dictionary(data);
}
return _share_2();
return promiseToFuture(JS("", "#.share(#)", this, data_dict));
}
@JSName('share')
Future _share_1(data) native;
@JSName('share')
Future _share_2() native;
// From NavigatorAutomationInformation
final bool webdriver;
@ -22748,19 +22705,15 @@ class OffscreenCanvas extends EventTarget {
int width;
Future convertToBlob([Map options]) {
Future<Blob> convertToBlob([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _convertToBlob_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _convertToBlob_2();
return promiseToFuture<Blob>(
JS("", "#.convertToBlob(#)", this, options_dict));
}
@JSName('convertToBlob')
Future _convertToBlob_1(options) native;
@JSName('convertToBlob')
Future _convertToBlob_2() native;
Object getContext(String contextType, [Map attributes]) {
if (attributes != null) {
var attributes_1 = convertDartToNative_Dictionary(attributes);
@ -22892,8 +22845,7 @@ class OffscreenCanvasRenderingContext2D extends Interceptor
CanvasGradient createLinearGradient(num x0, num y0, num x1, num y1) native;
CanvasPattern createPattern(
/*CanvasImageSource*/ image,
String repetitionType) native;
/*CanvasImageSource*/ image, String repetitionType) native;
CanvasGradient createRadialGradient(
num x0, num y0, num r0, num x1, num y1, num r1) native;
@ -23269,8 +23221,7 @@ class PaintRenderingContext2D extends Interceptor implements _CanvasPath {
CanvasGradient createLinearGradient(num x0, num y0, num x1, num y1) native;
CanvasPattern createPattern(
/*CanvasImageSource*/ image,
String repetitionType) native;
/*CanvasImageSource*/ image, String repetitionType) native;
CanvasGradient createRadialGradient(
num x0, num y0, num r0, num x1, num y1, num r1) native;
@ -23596,12 +23547,10 @@ class PaymentInstruments extends Interceptor {
promiseToFuture<List<String>>(JS("", "#.keys()", this));
Future set(String instrumentKey, Map details) {
var details_1 = convertDartToNative_Dictionary(details);
return _set_1(instrumentKey, details_1);
var details_dict = convertDartToNative_Dictionary(details);
return promiseToFuture(
JS("", "#.set(#, #)", this, instrumentKey, details_dict));
}
@JSName('set')
Future _set_1(instrumentKey, details) native;
}
// 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
@ -24132,33 +24081,27 @@ class Permissions extends Interceptor {
throw new UnsupportedError("Not supported");
}
Future query(Map permission) {
var permission_1 = convertDartToNative_Dictionary(permission);
return _query_1(permission_1);
Future<PermissionStatus> query(Map permission) {
var permission_dict = convertDartToNative_Dictionary(permission);
return promiseToFuture<PermissionStatus>(
JS("", "#.query(#)", this, permission_dict));
}
@JSName('query')
Future _query_1(permission) native;
Future request(Map permissions) {
var permissions_1 = convertDartToNative_Dictionary(permissions);
return _request_1(permissions_1);
Future<PermissionStatus> request(Map permissions) {
var permissions_dict = convertDartToNative_Dictionary(permissions);
return promiseToFuture<PermissionStatus>(
JS("", "#.request(#)", this, permissions_dict));
}
@JSName('request')
Future _request_1(permissions) native;
Future<PermissionStatus> requestAll(List<Map> permissions) =>
promiseToFuture<PermissionStatus>(
JS("", "#.requestAll(#)", this, permissions));
Future revoke(Map permission) {
var permission_1 = convertDartToNative_Dictionary(permission);
return _revoke_1(permission_1);
Future<PermissionStatus> revoke(Map permission) {
var permission_dict = convertDartToNative_Dictionary(permission);
return promiseToFuture<PermissionStatus>(
JS("", "#.revoke(#)", this, permission_dict));
}
@JSName('revoke')
Future _revoke_1(permission) native;
}
// 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
@ -24758,30 +24701,21 @@ class PushManager extends Interceptor {
promiseToFuture<PushSubscription>(JS("", "#.getSubscription()", this));
Future permissionState([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _permissionState_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _permissionState_2();
return promiseToFuture(JS("", "#.permissionState(#)", this, options_dict));
}
@JSName('permissionState')
Future _permissionState_1(options) native;
@JSName('permissionState')
Future _permissionState_2() native;
Future subscribe([Map options]) {
Future<PushSubscription> subscribe([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _subscribe_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _subscribe_2();
return promiseToFuture<PushSubscription>(
JS("", "#.subscribe(#)", this, options_dict));
}
@JSName('subscribe')
Future _subscribe_1(options) native;
@JSName('subscribe')
Future _subscribe_2() native;
}
// 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
@ -25456,26 +25390,6 @@ class RtcPeerConnection extends EventTarget {
return false;
}
Future<RtcSessionDescription> createOffer([Map mediaConstraints]) {
var completer = new Completer<RtcSessionDescription>();
_createOffer((value) {
completer.complete(value);
}, (error) {
completer.completeError(error);
}, mediaConstraints);
return completer.future;
}
Future<RtcSessionDescription> createAnswer([Map mediaConstraints]) {
var completer = new Completer<RtcSessionDescription>();
_createAnswer((value) {
completer.complete(value);
}, (error) {
completer.completeError(error);
}, mediaConstraints);
return completer.future;
}
/**
* Temporarily exposes _getStats and old getStats as getLegacyStats until Chrome fully supports
* new getStats API.
@ -25599,48 +25513,15 @@ class RtcPeerConnection extends EventTarget {
void close() native;
Future _createAnswer(
[options_OR_successCallback,
RtcPeerConnectionErrorCallback failureCallback,
Map mediaConstraints]) {
if (options_OR_successCallback == null &&
failureCallback == null &&
mediaConstraints == null) {
return _createAnswer_1();
Future<RtcSessionDescription> createAnswer([Map options]) {
var options_dict = null;
if (options != null) {
options_dict = convertDartToNative_Dictionary(options);
}
if ((options_OR_successCallback is Map) &&
failureCallback == null &&
mediaConstraints == null) {
var options_1 =
convertDartToNative_Dictionary(options_OR_successCallback);
return _createAnswer_2(options_1);
}
if (failureCallback != null &&
(options_OR_successCallback is _RtcSessionDescriptionCallback) &&
mediaConstraints == null) {
return _createAnswer_3(options_OR_successCallback, failureCallback);
}
if (mediaConstraints != null &&
failureCallback != null &&
(options_OR_successCallback is _RtcSessionDescriptionCallback)) {
var mediaConstraints_1 = convertDartToNative_Dictionary(mediaConstraints);
return _createAnswer_4(
options_OR_successCallback, failureCallback, mediaConstraints_1);
}
throw new ArgumentError("Incorrect number or type of arguments");
return promiseToFuture<RtcSessionDescription>(
JS("", "#.createAnswer(#)", this, options_dict));
}
@JSName('createAnswer')
Future _createAnswer_1() native;
@JSName('createAnswer')
Future _createAnswer_2(options) native;
@JSName('createAnswer')
Future _createAnswer_3(_RtcSessionDescriptionCallback successCallback,
RtcPeerConnectionErrorCallback failureCallback) native;
@JSName('createAnswer')
Future _createAnswer_4(_RtcSessionDescriptionCallback successCallback,
RtcPeerConnectionErrorCallback failureCallback, mediaConstraints) native;
@JSName('createDTMFSender')
RtcDtmfSender createDtmfSender(MediaStreamTrack track) native;
@ -25657,48 +25538,15 @@ class RtcPeerConnection extends EventTarget {
@JSName('createDataChannel')
RtcDataChannel _createDataChannel_2(label) native;
Future _createOffer(
[options_OR_successCallback,
RtcPeerConnectionErrorCallback failureCallback,
Map rtcOfferOptions]) {
if (options_OR_successCallback == null &&
failureCallback == null &&
rtcOfferOptions == null) {
return _createOffer_1();
Future<RtcSessionDescription> createOffer([Map options]) {
var options_dict = null;
if (options != null) {
options_dict = convertDartToNative_Dictionary(options);
}
if ((options_OR_successCallback is Map) &&
failureCallback == null &&
rtcOfferOptions == null) {
var options_1 =
convertDartToNative_Dictionary(options_OR_successCallback);
return _createOffer_2(options_1);
}
if (failureCallback != null &&
(options_OR_successCallback is _RtcSessionDescriptionCallback) &&
rtcOfferOptions == null) {
return _createOffer_3(options_OR_successCallback, failureCallback);
}
if (rtcOfferOptions != null &&
failureCallback != null &&
(options_OR_successCallback is _RtcSessionDescriptionCallback)) {
var rtcOfferOptions_1 = convertDartToNative_Dictionary(rtcOfferOptions);
return _createOffer_4(
options_OR_successCallback, failureCallback, rtcOfferOptions_1);
}
throw new ArgumentError("Incorrect number or type of arguments");
return promiseToFuture<RtcSessionDescription>(
JS("", "#.createOffer(#)", this, options_dict));
}
@JSName('createOffer')
Future _createOffer_1() native;
@JSName('createOffer')
Future _createOffer_2(options) native;
@JSName('createOffer')
Future _createOffer_3(_RtcSessionDescriptionCallback successCallback,
RtcPeerConnectionErrorCallback failureCallback) native;
@JSName('createOffer')
Future _createOffer_4(_RtcSessionDescriptionCallback successCallback,
RtcPeerConnectionErrorCallback failureCallback, rtcOfferOptions) native;
List<MediaStream> getLocalStreams() native;
List<RtcRtpReceiver> getReceivers() native;
@ -25723,48 +25571,16 @@ class RtcPeerConnection extends EventTarget {
@JSName('setConfiguration')
void _setConfiguration_1(configuration) native;
Future _setLocalDescription(Map description, VoidCallback successCallback,
[RtcPeerConnectionErrorCallback failureCallback]) {
var description_1 = convertDartToNative_Dictionary(description);
return _setLocalDescription_1(
description_1, successCallback, failureCallback);
}
@JSName('setLocalDescription')
Future _setLocalDescription_1(description, VoidCallback successCallback,
RtcPeerConnectionErrorCallback failureCallback) native;
@JSName('setLocalDescription')
Future setLocalDescription(Map description) {
var completer = new Completer();
_setLocalDescription(description, () {
completer.complete();
}, (exception) {
completer.completeError(exception);
});
return completer.future;
var description_dict = convertDartToNative_Dictionary(description);
return promiseToFuture(
JS("", "#.setLocalDescription(#)", this, description_dict));
}
Future _setRemoteDescription(Map description, VoidCallback successCallback,
[RtcPeerConnectionErrorCallback failureCallback]) {
var description_1 = convertDartToNative_Dictionary(description);
return _setRemoteDescription_1(
description_1, successCallback, failureCallback);
}
@JSName('setRemoteDescription')
Future _setRemoteDescription_1(description, VoidCallback successCallback,
RtcPeerConnectionErrorCallback failureCallback) native;
@JSName('setRemoteDescription')
Future setRemoteDescription(Map description) {
var completer = new Completer();
_setRemoteDescription(description, () {
completer.complete();
}, (exception) {
completer.completeError(exception);
});
return completer.future;
var description_dict = convertDartToNative_Dictionary(description);
return promiseToFuture(
JS("", "#.setRemoteDescription(#)", this, description_dict));
}
/// Stream of `addstream` events handled by this [RtcPeerConnection].
@ -26489,19 +26305,15 @@ class ServiceWorkerContainer extends EventTarget {
promiseToFuture<List<ServiceWorkerRegistration>>(
JS("", "#.getRegistrations()", this));
Future register(String url, [Map options]) {
Future<ServiceWorkerRegistration> register(String url, [Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _register_1(url, options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _register_2(url);
return promiseToFuture<ServiceWorkerRegistration>(
JS("", "#.register(#, #)", this, url, options_dict));
}
@JSName('register')
Future _register_1(url, options) native;
@JSName('register')
Future _register_2(url) native;
Stream<MessageEvent> get onMessage => messageEvent.forTarget(this);
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
@ -26546,7 +26358,12 @@ class ServiceWorkerGlobalScope extends WorkerGlobalScope {
Stream<Event> get onInstall => installEvent.forTarget(this);
Stream<MessageEvent> get onMessage => messageEvent.forTarget(this);
static ServiceWorkerGlobalScope get instance {
return _workerSelf as ServiceWorkerGlobalScope;
}
}
// 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
// BSD-style license that can be found in the LICENSE file.
@ -26576,32 +26393,24 @@ class ServiceWorkerRegistration extends EventTarget {
final ServiceWorker waiting;
Future getNotifications([Map filter]) {
Future<List<Notification>> getNotifications([Map filter]) {
var filter_dict = null;
if (filter != null) {
var filter_1 = convertDartToNative_Dictionary(filter);
return _getNotifications_1(filter_1);
filter_dict = convertDartToNative_Dictionary(filter);
}
return _getNotifications_2();
return promiseToFuture<List<Notification>>(
JS("", "#.getNotifications(#)", this, filter_dict));
}
@JSName('getNotifications')
Future _getNotifications_1(filter) native;
@JSName('getNotifications')
Future _getNotifications_2() native;
Future showNotification(String title, [Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _showNotification_1(title, options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _showNotification_2(title);
return promiseToFuture(
JS("", "#.showNotification(#, #)", this, title, options_dict));
}
@JSName('showNotification')
Future _showNotification_1(title, options) native;
@JSName('showNotification')
Future _showNotification_2(title) native;
Future<bool> unregister() =>
promiseToFuture<bool>(JS("", "#.unregister()", this));
@ -26813,7 +26622,12 @@ class SharedWorkerGlobalScope extends WorkerGlobalScope {
/// Stream of `connect` events handled by this [SharedWorkerGlobalScope].
Stream<Event> get onConnect => connectEvent.forTarget(this);
static SharedWorkerGlobalScope get instance {
return _workerSelf as SharedWorkerGlobalScope;
}
}
// 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
// BSD-style license that can be found in the LICENSE file.
@ -29533,30 +29347,20 @@ class VRDevice extends EventTarget {
final bool isExternal;
Future requestSession([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _requestSession_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _requestSession_2();
return promiseToFuture(JS("", "#.requestSession(#)", this, options_dict));
}
@JSName('requestSession')
Future _requestSession_1(options) native;
@JSName('requestSession')
Future _requestSession_2() native;
Future supportsSession([Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _supportsSession_1(options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _supportsSession_2();
return promiseToFuture(JS("", "#.supportsSession(#)", this, options_dict));
}
@JSName('supportsSession')
Future _supportsSession_1(options) native;
@JSName('supportsSession')
Future _supportsSession_2() native;
}
// 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
@ -29775,18 +29579,14 @@ class VRSession extends EventTarget {
Future end() => promiseToFuture(JS("", "#.end()", this));
Future requestFrameOfReference(String type, [Map options]) {
var options_dict = null;
if (options != null) {
var options_1 = convertDartToNative_Dictionary(options);
return _requestFrameOfReference_1(type, options_1);
options_dict = convertDartToNative_Dictionary(options);
}
return _requestFrameOfReference_2(type);
return promiseToFuture(
JS("", "#.requestFrameOfReference(#, #)", this, type, options_dict));
}
@JSName('requestFrameOfReference')
Future _requestFrameOfReference_1(type, options) native;
@JSName('requestFrameOfReference')
Future _requestFrameOfReference_2(type) native;
Stream<Event> get onBlur => blurEvent.forTarget(this);
Stream<Event> get onFocus => focusEvent.forTarget(this);
@ -31347,18 +31147,13 @@ class Window extends EventTarget
bool confirm([String message]) native;
Future fetch(/*RequestInfo*/ input, [Map init]) {
var init_dict = null;
if (init != null) {
var init_1 = convertDartToNative_Dictionary(init);
return _fetch_1(input, init_1);
init_dict = convertDartToNative_Dictionary(init);
}
return _fetch_2(input);
return promiseToFuture(JS("", "#.fetch(#, #)", this, input, init_dict));
}
@JSName('fetch')
Future _fetch_1(input, init) native;
@JSName('fetch')
Future _fetch_2(input) native;
/**
* Finds text in this window.
*
@ -32399,18 +32194,13 @@ class WorkerGlobalScope extends EventTarget
final WorkerGlobalScope self;
Future fetch(/*RequestInfo*/ input, [Map init]) {
var init_dict = null;
if (init != null) {
var init_1 = convertDartToNative_Dictionary(init);
return _fetch_1(input, init_1);
init_dict = convertDartToNative_Dictionary(init);
}
return _fetch_2(input);
return promiseToFuture(JS("", "#.fetch(#, #)", this, input, init_dict));
}
@JSName('fetch')
Future _fetch_1(input, init) native;
@JSName('fetch')
Future _fetch_2(input) native;
void importScripts(String urls) native;
// From WindowBase64
@ -32443,7 +32233,10 @@ class WorkerGlobalScope extends EventTarget
/// Stream of `error` events handled by this [WorkerGlobalScope].
Stream<Event> get onError => errorEvent.forTarget(this);
static WorkerGlobalScope get instance => _workerSelf;
}
// 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
// BSD-style license that can be found in the LICENSE file.
@ -34393,7 +34186,7 @@ class _DataAttributeMap extends MapBase<String, String> {
/**
* Converts a string name with hyphens into an identifier, by removing hyphens
* and capitalizing the following letter. Optionally [startUppercase] to
* captialize the first letter.
* capitalize the first letter.
*/
String _toCamelCase(String hyphenedName, {bool startUppercase: false}) {
var segments = hyphenedName.split('-');
@ -38666,8 +38459,8 @@ class _DOMWindowCrossFrame implements WindowBase {
// Fields.
HistoryBase get history =>
_HistoryCrossFrame._createSafe(JS('HistoryBase', '#.history', _window));
LocationBase get location => _LocationCrossFrame
._createSafe(JS('LocationBase', '#.location', _window));
LocationBase get location => _LocationCrossFrame._createSafe(
JS('LocationBase', '#.location', _window));
// TODO(vsm): Add frames to navigate subframes. See 2312.

View file

@ -132,10 +132,12 @@ interface HTMLMediaElement {
[DartSupplemental]
interface RTCPeerConnection {
[DartSuppress, RaisesException] void addIceCandidate(RTCIceCandidate candidate);
[DartSuppress] Promise<void> createOffer(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback, optional Dictionary rtcOfferOptions);
[DartSuppress] Promise<void> createAnswer(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback, optional Dictionary mediaConstraints);
[DartSuppress] void addIceCandidate(RTCIceCandidate candidate);
[DartSuppress] Promise<void> getStats(RTCStatsCallback successCallback, optional MediaStreamTrack? selector);
[DartSuppress] Promise<void> setLocalDescription(RTCSessionDescriptionInit description);
[DartSuppress] Promise<void> setRemoteDescription(RTCSessionDescriptionInit description);
[DartSuppress] Promise<void> setLocalDescription(RTCSessionDescriptionInit description, VoidCallback successCallback, [Default=Undefined] optional RTCPeerConnectionErrorCallback failureCallback);
[DartSuppress] Promise<void> setRemoteDescription(RTCSessionDescriptionInit description, VoidCallback successCallback, [Default=Undefined] optional RTCPeerConnectionErrorCallback failureCallback);
};
// See implementation in tools/dom/templates for canvas and offscreenCanvas.

View file

@ -710,6 +710,17 @@ class OperationInfo(object):
parameter_count = len(self.param_infos)
return ', '.join(map(param_name, self.param_infos[:parameter_count]))
""" Check if a parameter to a Future API is a Dictionary argument and if its optional.
Used for any Promised based operation to correctly convert from Map to Dictionary then
perform the PromiseToFuture call.
"""
def dictionaryArgumentName(self, parameter_count=None):
parameter_count = len(self.param_infos)
for argument in self.param_infos[:parameter_count]:
if argument.type_id == 'Dictionary':
return [argument.name, argument.is_optional]
return None
def isCallback(self, type_registry, type_id):
if type_id and not type_id.endswith('[]'):
callback_type = type_registry._database._all_interfaces[type_id]
@ -1701,7 +1712,7 @@ class TypeRegistry(object):
# It's a typedef (implied union)
return self.TypeInfo('any')
else:
print "ERROR: Unexpected interface, or type not found. %s" % type_name
print "ERROR: Unexpected interface, or type not found. %s" % type_name
if 'Callback' in interface.ext_attrs:
return CallbackIDLTypeInfo(type_name, TypeData('Callback',

View file

@ -612,7 +612,7 @@ class HtmlDartGenerator(object):
args = constructor_info.ParametersAsArgumentList(argument_count)
# Handle converting Maps to Dictionaries, etc.
(factory_params, converted_arguments) = self._ConvertArgumentTypes(
(factory_params, converted_arguments, calling_params) = self._ConvertArgumentTypes(
stmts_emitter, arguments, argument_count, constructor_info)
args = ', '.join(converted_arguments)
call_template = '$FACTORY_NAME($FACTORY_PARAMS)'
@ -621,7 +621,7 @@ class HtmlDartGenerator(object):
'$FACTORY.$NAME',
FACTORY=factory_name,
NAME=name)
(factory_params, converted_arguments) = self._ConvertArgumentTypes(
(factory_params, converted_arguments, calling_params) = self._ConvertArgumentTypes(
stmts_emitter, arguments, argument_count, constructor_info)
args = ', '.join(converted_arguments)
call_template = '$FACTORY_NAME($FACTORY_PARAMS)'
@ -709,6 +709,27 @@ class HtmlDartGenerator(object):
future_generic = '<%s>' % self._DartType(callback_info.param_infos[-1].type_id)
param_list = info.ParametersAsArgumentList(None, ignore_named_parameters)
dictionary_argument = info.dictionaryArgumentName();
convert_map = ''
if dictionary_argument is not None:
mapArg = dictionary_argument[0]
tempVariable = '%s_dict' % mapArg
mapArgOptional = dictionary_argument[1]
if not(extensions):
if not(param_list.endswith(', mapArg') or param_list.endswith(', options') or param_list == mapArg):
print "ERROR: %s.%s - Last parameter or only parameter %s is not of type Map" % (self._interface.id, html_name, mapArg)
param_list = '%s_dict' % param_list
if mapArgOptional:
convert_map = ' var %s = null;\n'\
' if (%s != null) {\n'\
' %s = convertDartToNative_Dictionary(%s);\n'\
' }\n' % (tempVariable, mapArg, tempVariable, mapArg)
else:
convert_map = ' var %s = convertDartToNative_Dictionary(%s);\n' % (tempVariable, mapArg)
metadata = ''
if '_RenamingAnnotation' in dir(self):
metadata = (self._RenamingAnnotation(info.declared_name, html_name) +
@ -716,6 +737,7 @@ class HtmlDartGenerator(object):
self._members_emitter.Emit(
'\n'
' $METADATA$MODIFIERS$TYPE$FUTURE_GENERIC $NAME($PARAMS) {\n'
' $CONVERT_DICTIONARY'
' var completer = new Completer$(FUTURE_GENERIC)();\n'
' $ORIGINAL_FUNCTION($PARAMS_LIST\n'
' $NAMED_PARAM($VARIABLE_NAME) { '
@ -730,6 +752,7 @@ class HtmlDartGenerator(object):
NAME=html_name[1:],
PARAMS=info.ParametersAsDeclaration(self._NarrowInputType
if '_NarrowInputType' in dir(self) else self._DartType),
CONVERT_DICTIONARY=convert_map,
PARAMS_LIST='' if param_list == '' else param_list + ',',
NAMED_PARAM=('%s : ' % info.callback_args[0].name
if info.requires_named_arguments and
@ -886,6 +909,7 @@ class HtmlDartGenerator(object):
temp_version = [0]
converted_arguments = []
target_parameters = []
calling_parameters = []
for position, arg in enumerate(arguments[:argument_count]):
conversion = self._InputConversion(arg.type.id, info.declared_name)
param_name = arguments[position].id
@ -921,8 +945,9 @@ class HtmlDartGenerator(object):
target_parameters.append(
'%s%s' % (TypeOrNothing(param_type), param_name))
calling_parameters.append(',%s ' % param_name)
return target_parameters, converted_arguments
return target_parameters, converted_arguments, calling_parameters
def _InputType(self, type_name, info):
conversion = self._InputConversion(type_name, info.declared_name)

View file

@ -202,8 +202,6 @@ convert_to_future_members = monitored.Set(
'FontLoader.notifyWhenFontsReady',
'MediaStreamTrack.getSources',
'Notification.requestPermission',
'RTCPeerConnection.setLocalDescription',
'RTCPeerConnection.setRemoteDescription',
'SQLTransaction.executeSql',
'StorageInfo.requestQuota',
'StorageQuota.requestQuota',
@ -216,6 +214,7 @@ convert_to_future_members = monitored.Set(
# DDC Exposed Classes
ddc_extensions = monitored.Dict('ddcextensions.ddc_extensions', {
'DirectoryEntry': {
'getDirectory': [ '' ],
'getFile': [
'applyExtension(\'FileEntry\', value);',
]
@ -423,8 +422,6 @@ private_html_members = monitored.Set('htmlrenamer.private_html_members', [
'ParentNode.lastElementChild',
'ParentNode.querySelectorAll',
'Range.getClientRects',
'RTCPeerConnection.createAnswer',
'RTCPeerConnection.createOffer',
'Screen.availHeight',
'Screen.availLeft',
'Screen.availTop',
@ -580,6 +577,9 @@ overloaded_and_renamed = monitored.Set(
'Navigator.sendBeacon',
])
def convertedFutureMembers(member):
return member in convert_to_future_members
for member in convert_to_future_members:
if member in renamed_html_members:
renamed_html_members[member] = '_' + renamed_html_members[member]

View file

@ -820,11 +820,11 @@ promise_operations = monitored.Dict('systemhtml.promise_oper_type', {
"ImageCapture.takePhoto": { "type": "Blob" },
"ImageCapture.grabFrame": { "type": "ImageBitmap" },
"Navigator.getInstalledRelatedApps": { "type": "RelatedApplication" },
"OffscreenCanvas.convertToBlob": { "type": "Blob" },
"MediaCapabilities.decodingInfo": { "type": "MediaCapabilitiesInfo" },
"MediaCapabilities.encodingInfo": { "type": "MediaCapabilitiesInfo" },
"MediaDevices.enumerateDevices": { "type": "List<MediaDeviceInfo>" },
"MediaDevices.getUserMedia": { "type": "MediaStream" },
"MediaStreamTrack.applyConstraints": { "type": "MediaTrackConstraints" },
"ServiceWorkerRegistration.getNotifications": { "type": "List<Notification>" },
"PaymentInstruments.delete": { "type": "bool" },
"PaymentInstruments.get": { "type": "dictionary" },
@ -868,6 +868,13 @@ promise_operations = monitored.Dict('systemhtml.promise_oper_type', {
"OfflineAudioContext.startRendering": { "type": "AudioBuffer" },
})
promise_generateCall = monitored.Set('systemhtml.promise_generateCall', [
"Navigator.requestKeyboardLock",
])
def _IsPromiseOperationGenerateCall(interface_operation):
return interface_operation in promise_generateCall
def _GetPromiseOperationType(interface_operation):
if interface_operation in promise_operations:
return promise_operations[interface_operation]
@ -1297,11 +1304,17 @@ class Dart2JSBackend(HtmlDartGenerator):
self._AddInterfaceOperation(info, html_name)
elif info.callback_args:
self._AddFutureifiedOperation(info, html_name)
elif any(self._OperationRequiresConversions(op) for op in info.overloads):
# Any conversions needed?
self._AddOperationWithConversions(info, html_name)
else:
self._AddDirectNativeOperation(info, html_name)
if any(self._OperationRequiresConversions(op) for op in info.overloads):
lookupOp = "%s.%s" % (self._interface.id, html_name)
if (_GetPromiseOperationType(lookupOp) or info.type_name == 'Promise') and \
not _IsPromiseOperationGenerateCall(lookupOp):
self._AddDirectNativeOperation(info, html_name)
else:
# Any conversions needed?
self._AddOperationWithConversions(info, html_name)
else:
self._AddDirectNativeOperation(info, html_name)
def _computeResultType(self, checkType):
# TODO(terry): Work around bug in dart2js compiler e.g.,
@ -1323,17 +1336,50 @@ class Dart2JSBackend(HtmlDartGenerator):
argsPound = "#" if numberArgs == 1 else ("#, " * numberArgs)[:-2]
return ' JS("", "#.$NAME(%s)", this, %s)' % (argsPound, argsNames)
def _promiseToFutureCode(self, argsNames):
""" If argument conversionsMapToDictionary is a list first entry is argument
name and second entry signals if argument is optional (True). """
def _promiseToFutureCode(self, argsNames, conversionsMapToDictionary=None):
numberArgs = argsNames.count(',') + 1
jsCall = self._zeroArgs(argsNames) if len(argsNames) == 0 else \
self._manyArgs(numberArgs, argsNames)
futureTemplate = [
'\n'
' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) => $PROMISE_CALL(',
jsCall,
');\n'
]
futureTemplate = []
if conversionsMapToDictionary is None:
futureTemplate = [
'\n'
' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) => $PROMISE_CALL(', jsCall, ');\n'
]
else:
mapArg = conversionsMapToDictionary[0]
tempVariable = '%s_dict' % mapArg
mapArgOptional = conversionsMapToDictionary[1]
if argsNames.endswith('%s' % mapArg):
argsNames = '%s_dict' % argsNames
jsCall = self._zeroArgs(argsNames) if len(argsNames) == 0 else \
self._manyArgs(numberArgs, argsNames)
if mapArgOptional:
futureTemplate = [
# We will need to convert the Map argument to a Dictionary, test if mapArg is there (optional) then convert.
'\n'
' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) {\n',
' var ', tempVariable, ' = null;\n',
' if (', mapArg, ' != null) {\n',
' ', tempVariable, ' = convertDartToNative_Dictionary(', mapArg, ');\n',
' }\n',
' return $PROMISE_CALL(', jsCall, ');\n',
' }\n'
]
else:
futureTemplate = [
# We will need to convert the Map argument to a Dictionary, the Map argument is not optional.
'\n'
' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) {\n',
' var ', tempVariable, ' = convertDartToNative_Dictionary(', mapArg, ');\n',
' return $PROMISE_CALL(', jsCall, ');\n',
' }\n'
]
return "".join(futureTemplate)
def _AddDirectNativeOperation(self, info, html_name):
@ -1363,7 +1409,8 @@ class Dart2JSBackend(HtmlDartGenerator):
promiseType = 'Future<%s>' % paramType
argsNames = info.ParametersAsArgumentList()
codeTemplate = self._promiseToFutureCode(argsNames)
dictionary_argument = info.dictionaryArgumentName();
codeTemplate = self._promiseToFutureCode(argsNames, dictionary_argument)
self._members_emitter.Emit(codeTemplate,
RENAME=self._RenamingAnnotation(info.declared_name, html_name),
METADATA=self._Metadata(info.type_name, info.declared_name,
@ -1413,7 +1460,7 @@ class Dart2JSBackend(HtmlDartGenerator):
target = '_%s_%d' % (
html_name[1:] if html_name.startswith('_') else html_name, version);
(target_parameters, arguments) = self._ConvertArgumentTypes(
(target_parameters, arguments, calling_params) = self._ConvertArgumentTypes(
stmts_emitter, operation.arguments, argument_count, info)
argument_list = ', '.join(arguments)
@ -1426,14 +1473,34 @@ class Dart2JSBackend(HtmlDartGenerator):
call_emitter.Emit(call)
self._members_emitter.Emit(
' $RENAME$METADATA$MODIFIERS$TYPE$TARGET($PARAMS) native;\n',
RENAME=self._RenamingAnnotation(info.declared_name, target),
METADATA=self._Metadata(info.type_name, info.declared_name, None),
MODIFIERS='static ' if info.IsStatic() else '',
TYPE=TypeOrNothing(native_return_type),
TARGET=target,
PARAMS=', '.join(target_parameters))
if (native_return_type == 'Future'):
hashArgs = ''
if argument_count > 0:
if argument_count < 20:
hashArgs = '#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#'[:argument_count * 2 - 1]
else:
print "ERROR: Arguments exceede 20 - please fix Python code to handle more."
self._members_emitter.Emit(
' $RENAME$METADATA$MODIFIERS$TYPE$TARGET($PARAMS) =>\n'
' promiseToFuture(JS("", "#.$JSNAME($HASH_STR)", this$CALLING_PARAMS));\n',
RENAME=self._RenamingAnnotation(info.declared_name, target),
METADATA=self._Metadata(info.type_name, info.declared_name, None),
MODIFIERS='static ' if info.IsStatic() else '',
TYPE=TypeOrNothing(native_return_type),
TARGET=target,
PARAMS=', '.join(target_parameters),
JSNAME=operation.id,
HASH_STR=hashArgs,
CALLING_PARAMS=calling_params)
else:
self._members_emitter.Emit(
' $RENAME$METADATA$MODIFIERS$TYPE$TARGET($PARAMS) native;\n',
RENAME=self._RenamingAnnotation(info.declared_name, target),
METADATA=self._Metadata(info.type_name, info.declared_name, None),
MODIFIERS='static ' if info.IsStatic() else '',
TYPE=TypeOrNothing(native_return_type),
TARGET=target,
PARAMS=', '.join(target_parameters))
# private methods don't need named arguments.
full_name = '%s.%s' % (self._interface.id, info.declared_name)

View file

@ -159,3 +159,6 @@ class HtmlElement extends Element implements NoncedElement {
*/
typedef void FontFaceSetForEachCallback(
FontFace fontFace, FontFace fontFaceAgain, FontFaceSet set);
WorkerGlobalScope get _workerSelf => JS('WorkerGlobalScope', 'self');

View file

@ -0,0 +1,15 @@
// 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
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
$!MEMBERS
static DedicatedWorkerGlobalScope get instance {
return _workerSelf as DedicatedWorkerGlobalScope;
}
}

View file

@ -34,21 +34,6 @@ $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
} catch (_) { return false;}
return false;
}
Future<RtcSessionDescription> createOffer([Map mediaConstraints]) {
var completer = new Completer<RtcSessionDescription>();
_createOffer(
(value) { completer.complete(value); },
(error) { completer.completeError(error); }, mediaConstraints);
return completer.future;
}
Future<RtcSessionDescription> createAnswer([Map mediaConstraints]) {
var completer = new Completer<RtcSessionDescription>();
_createAnswer(
(value) { completer.complete(value); },
(error) { completer.completeError(error); }, mediaConstraints);
return completer.future;
}
/**
* Temporarily exposes _getStats and old getStats as getLegacyStats until Chrome fully supports

View file

@ -0,0 +1,15 @@
// 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
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
$!MEMBERS
static ServiceWorkerGlobalScope get instance {
return _workerSelf as ServiceWorkerGlobalScope;
}
}

View file

@ -0,0 +1,18 @@
// 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
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
$!MEMBERS
static ServiceWorkerGlobalScope get instance {
if (_workerSelf is! ServiceWorkerGlobalScope) {
throw InstanceTypeError("expected ServiceWorkerGlobalScope got ${_workerSelf.runtimeType}");
}
return _workerSelf;
}
}

View file

@ -0,0 +1,15 @@
// 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
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
$!MEMBERS
static SharedWorkerGlobalScope get instance {
return _workerSelf as SharedWorkerGlobalScope;
}
}

View file

@ -0,0 +1,12 @@
// 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
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
$!MEMBERS
static WorkerGlobalScope get instance => _workerSelf;
}