Skip to content

Commit 38bf70d

Browse files
floitschGcommit-bot@chromium.org
authored andcommitted
Use generic functions in zones.
Migrated from https://chromiumcodereview.appspot.com/2893893002/ Change-Id: I0bd6dc1438eb1e6762e7760a08b5a760b07d4b10 Reviewed-on: https://dart-review.googlesource.com/4942 Reviewed-by: Florian Loitsch <[email protected]> Commit-Queue: Florian Loitsch <[email protected]>
1 parent a8afd3a commit 38bf70d

File tree

60 files changed

+1514
-1702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1514
-1702
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
### Core library changes
1515

16+
* `dart:async`
17+
* The `Zone` class was changed to be strong-mode clean. This required
18+
some breaking API changes.
19+
1620
* `dart:io`
1721
* Unified backends for `SecureSocket`, `SecurityContext`, and
1822
`X509Certificate` to be consistent across all platforms. All

pkg/compiler/lib/src/common/tasks.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ abstract class CompilerTask {
115115
/// of other measuring zones, but we still need to call through the parent
116116
/// chain. Consequently, we use a zone value keyed by [measurer] to see if
117117
/// we should measure or not when delegating.
118-
_run(Zone self, ZoneDelegate parent, Zone zone, f()) {
118+
R _run<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) {
119119
if (zone[measurer] != this) return parent.run(zone, f);
120120
CompilerTask previous = _start();
121121
try {
@@ -126,7 +126,8 @@ abstract class CompilerTask {
126126
}
127127

128128
/// Same as [run] except that [f] takes one argument, [arg].
129-
_runUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) {
129+
R _runUnary<R, T>(
130+
Zone self, ZoneDelegate parent, Zone zone, R f(T arg), T arg) {
130131
if (zone[measurer] != this) return parent.runUnary(zone, f, arg);
131132
CompilerTask previous = _start();
132133
try {
@@ -137,7 +138,8 @@ abstract class CompilerTask {
137138
}
138139

139140
/// Same as [run] except that [f] takes two arguments ([a1] and [a2]).
140-
_runBinary(Zone self, ZoneDelegate parent, Zone zone, f(a1, a2), a1, a2) {
141+
R _runBinary<R, T1, T2>(Zone self, ZoneDelegate parent, Zone zone,
142+
R f(T1 a1, T2 a2), T1 a1, T2 a2) {
141143
if (zone[measurer] != this) return parent.runBinary(zone, f, a1, a2);
142144
CompilerTask previous = _start();
143145
try {

pkg/dev_compiler/lib/js/amd/dart_sdk.js

Lines changed: 260 additions & 322 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/amd/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/js/common/dart_sdk.js

Lines changed: 260 additions & 322 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/common/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/js/es6/dart_sdk.js

Lines changed: 260 additions & 322 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/es6/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/js/legacy/dart_sdk.js

Lines changed: 260 additions & 322 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/legacy/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/sdk/ddc_sdk.sum

64 Bytes
Binary file not shown.

pkg/dev_compiler/test/browser/language_tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require',
224224
'corelib_2/regexp': {},
225225

226226
'lib/async': {
227+
'async_await_zones_test': fail,
227228
'first_regression_test': async_unittest,
228229
'future_or_bad_type_test_implements_multi': fail,
229230
'future_or_bad_type_test_none_multi': fail,
@@ -266,9 +267,7 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require',
266267
'timer_not_available_test': fail,
267268
'timer_repeat_test': async_unittest,
268269
'timer_test': async_unittest,
269-
'zone_bind_callback_test': fail,
270270
'zone_error_callback_test': fail,
271-
'zone_register_callback_test': fail,
272271
'zone_run_unary_test': fail,
273272
},
274273

pkg/dev_compiler/tool/input_sdk/lib/html/dart2js/html_dart2js.dart

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36981,7 +36981,7 @@ class Window extends EventTarget
3698136981
@DomName('Window.requestAnimationFrame')
3698236982
int requestAnimationFrame(FrameRequestCallback callback) {
3698336983
_ensureRequestAnimationFrame();
36984-
return _requestAnimationFrame(_wrapZone/*<num, dynamic>*/(callback));
36984+
return _requestAnimationFrame(_wrapZone(callback));
3698536985
}
3698636986

3698736987
/**
@@ -42919,9 +42919,9 @@ class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
4291942919

4292042920
// TODO(leafp): It would be better to write this as
4292142921
// _onData = onData == null ? null :
42922-
// onData is _wrapZoneCallback<Event, dynamic>
42923-
// ? _wrapZone/*<Event, dynamic>*/(onData)
42924-
// : _wrapZone/*<Event, dynamic>*/((e) => onData(e as T))
42922+
// onData is void Function(Event)
42923+
// ? _wrapZone<Event>(onData)
42924+
// : _wrapZone<Event>((e) => onData(e as T))
4292542925
// In order to support existing tests which pass the wrong type of events but
4292642926
// use a more general listener, without causing as much slowdown for things
4292742927
// which are typed correctly. But this currently runs afoul of restrictions
@@ -42930,7 +42930,7 @@ class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
4293042930
this._target, this._eventType, void onData(T event), this._useCapture)
4293142931
: _onData = onData == null
4293242932
? null
42933-
: _wrapZone<Event, dynamic>((e) => (onData as dynamic)(e)) {
42933+
: _wrapZone<Event>((e) => (onData as dynamic)(e)) {
4293442934
_tryResume();
4293542935
}
4293642936

@@ -42952,7 +42952,7 @@ class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
4295242952
}
4295342953
// Remove current event listener.
4295442954
_unlisten();
42955-
_onData = _wrapZone/*<Event, dynamic>*/(handleData);
42955+
_onData = _wrapZone<Event>(handleData);
4295642956
_tryResume();
4295742957
}
4295842958

@@ -46328,24 +46328,18 @@ class _WrappedEvent implements Event {
4632846328
// for details. All rights reserved. Use of this source code is governed by a
4632946329
// BSD-style license that can be found in the LICENSE file.
4633046330

46331-
// TODO(jacobr): remove these typedefs when dart:async supports generic types.
46332-
typedef R _wrapZoneCallback<A, R>(A a);
46333-
typedef R _wrapZoneBinaryCallback<A, B, R>(A a, B b);
46334-
46335-
_wrapZoneCallback/*<A, R>*/ _wrapZone/*<A, R>*/(
46336-
_wrapZoneCallback/*<A, R>*/ callback) {
46331+
void Function(T) _wrapZone<T>(void Function(T) callback) {
4633746332
// For performance reasons avoid wrapping if we are in the root zone.
4633846333
if (Zone.current == Zone.ROOT) return callback;
4633946334
if (callback == null) return null;
46340-
return Zone.current.bindUnaryCallback/*<R, A>*/(callback, runGuarded: true);
46335+
return Zone.current.bindUnaryCallbackGuarded(callback);
4634146336
}
4634246337

46343-
_wrapZoneBinaryCallback/*<A, B, R>*/ _wrapBinaryZone/*<A, B, R>*/(
46344-
_wrapZoneBinaryCallback/*<A, B, R>*/ callback) {
46338+
void Function(T1, T2) _wrapBinaryZone<T1, T2>(void Function(T1, T2) callback) {
46339+
// For performance reasons avoid wrapping if we are in the root zone.
4634546340
if (Zone.current == Zone.ROOT) return callback;
4634646341
if (callback == null) return null;
46347-
return Zone.current
46348-
.bindBinaryCallback/*<R, A, B>*/(callback, runGuarded: true);
46342+
return Zone.current.bindBinaryCallbackGuarded(callback);
4634946343
}
4635046344

4635146345
/**

pkg/pkg.status

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ front_end/test/src/incremental/hot_reload_e2e_test: Skip # Issue 28629
9696
[ $runtime == vm && ! $use_sdk ]
9797
front_end/tool/perf_test: Skip # Issue 28698
9898

99+
[ $runtime == vm ]
100+
front_end/tool/perf_test: Skip # Issue 30825
101+
99102
[ $runtime == vm && $use_sdk ]
100103
front_end/tool/fasta_perf_test: SkipByDesign # depends on patched_sdk which is not built into the sdk
101104
front_end/test/kernel_generator_test: SkipByDesign # depends on patched_sdk which is not built into the sdk
@@ -226,6 +229,8 @@ kernel/test/closures_test: Fail
226229
[ $runtime == vm ]
227230
analyzer_cli/test/driver_test: Pass, Slow, Timeout
228231

232+
compiler/tool/perf_test: Fail # Unimplemented Typedef handling in kernel transformation.
233+
229234
[ $runtime == vm && $system == windows ]
230235
analyzer/test/src/task/strong/checker_test: Pass, Slow
231236

runtime/bin/socket_patch.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,14 +1136,14 @@ class _RawServerSocket extends Stream<RawSocket> implements RawServerSocket {
11361136
onCancel: _onSubscriptionStateChange,
11371137
onPause: _onPauseStateChange,
11381138
onResume: _onPauseStateChange);
1139-
_socket.setHandlers(read: zone.bindCallback(() {
1139+
_socket.setHandlers(read: zone.bindCallbackGuarded(() {
11401140
while (_socket.available > 0) {
11411141
var socket = _socket.accept();
11421142
if (socket == null) return;
11431143
_controller.add(new _RawSocket(socket));
11441144
if (_controller.isPaused) return;
11451145
}
1146-
}), error: zone.bindUnaryCallback((e) {
1146+
}), error: zone.bindUnaryCallbackGuarded((e) {
11471147
_controller.addError(e);
11481148
_controller.close();
11491149
}), destroyed: () {
@@ -1237,7 +1237,7 @@ class _RawSocket extends Stream<RawSocketEvent> implements RawSocket {
12371237
_controller.add(RawSocketEvent.CLOSED);
12381238
_controller.close();
12391239
},
1240-
error: zone.bindUnaryCallback((e) {
1240+
error: zone.bindUnaryCallbackGuarded((e) {
12411241
_controller.addError(e);
12421242
_socket.close();
12431243
}));
@@ -1734,7 +1734,7 @@ class _RawDatagramSocket extends Stream implements RawDatagramSocket {
17341734
_controller.add(RawSocketEvent.CLOSED);
17351735
_controller.close();
17361736
},
1737-
error: zone.bindUnaryCallback((e) {
1737+
error: zone.bindUnaryCallbackGuarded((e) {
17381738
_controller.addError(e);
17391739
_socket.close();
17401740
}));

sdk/lib/async/future.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ abstract class Future<T> {
519519
// context of all the previous iterations' callbacks.
520520
// This avoids, e.g., deeply nested stack traces from the stack trace
521521
// package.
522-
nextIteration = Zone.current.bindUnaryCallback((bool keepGoing) {
522+
nextIteration = Zone.current.bindUnaryCallbackGuarded((bool keepGoing) {
523523
while (keepGoing) {
524524
FutureOr<bool> result;
525525
try {
@@ -537,7 +537,7 @@ abstract class Future<T> {
537537
keepGoing = result;
538538
}
539539
doneSignal._complete(null);
540-
}, runGuarded: true);
540+
});
541541
nextIteration(true);
542542
return doneSignal;
543543
}

sdk/lib/async/schedule_microtask.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ void scheduleMicrotask(void callback()) {
144144
null, null, currentZone, currentZone.registerCallback(callback));
145145
return;
146146
}
147-
Zone.current
148-
.scheduleMicrotask(Zone.current.bindCallback(callback, runGuarded: true));
147+
Zone.current.scheduleMicrotask(Zone.current.bindCallbackGuarded(callback));
149148
}
150149

151150
class _AsyncRun {

sdk/lib/async/stream_impl.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class _BufferingStreamSubscription<T>
332332
_checkState(wasInputPaused);
333333
}
334334

335-
void _sendError(var error, StackTrace stackTrace) {
335+
void _sendError(Object error, StackTrace stackTrace) {
336336
assert(!_isCanceled);
337337
assert(!_isPaused);
338338
assert(!_inCallback);
@@ -345,12 +345,11 @@ class _BufferingStreamSubscription<T>
345345
_state |= _STATE_IN_CALLBACK;
346346
// TODO(floitsch): this dynamic should be 'void'.
347347
if (_onError is ZoneBinaryCallback<dynamic, Object, StackTrace>) {
348-
ZoneBinaryCallback<dynamic, Object, StackTrace> errorCallback = _onError
349-
as Object/*=ZoneBinaryCallback<dynamic, Object, StackTrace>*/;
348+
ZoneBinaryCallback<dynamic, Object, StackTrace> errorCallback =
349+
_onError;
350350
_zone.runBinaryGuarded(errorCallback, error, stackTrace);
351351
} else {
352-
_zone.runUnaryGuarded<dynamic, Object>(
353-
_onError as Object/*=ZoneUnaryCallback<dynamic, Object>*/, error);
352+
_zone.runUnaryGuarded<Object>(_onError, error);
354353
}
355354
_state &= ~_STATE_IN_CALLBACK;
356355
}

sdk/lib/async/timer.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ abstract class Timer {
4848
// be invoked in the root zone.
4949
return Zone.current.createTimer(duration, callback);
5050
}
51-
return Zone.current.createTimer(
52-
duration, Zone.current.bindCallback(callback, runGuarded: true));
51+
return Zone.current
52+
.createTimer(duration, Zone.current.bindCallbackGuarded(callback));
5353
}
5454

5555
/**
@@ -74,10 +74,7 @@ abstract class Timer {
7474
// be invoked in the root zone.
7575
return Zone.current.createPeriodicTimer(duration, callback);
7676
}
77-
// TODO(floitsch): the return type should be 'void', and the type
78-
// should be inferred.
79-
var boundCallback = Zone.current
80-
.bindUnaryCallback<dynamic, Timer>(callback, runGuarded: true);
77+
var boundCallback = Zone.current.bindUnaryCallbackGuarded<Timer>(callback);
8178
return Zone.current.createPeriodicTimer(duration, boundCallback);
8279
}
8380

0 commit comments

Comments
 (0)