Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Unified Diff: sdk/lib/async/zone.dart

Issue 136113014: Introduce and use Zone:_enter and Zone:_leave, in Future. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make futures faster and add a simple test. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/async/zone.dart
diff --git a/sdk/lib/async/zone.dart b/sdk/lib/async/zone.dart
index 88b30549d29a8dde06d6b79b28047fc9d2f3f658..36e0f0a114a30c9eefa914f0f28e493d93246a3f 100644
--- a/sdk/lib/async/zone.dart
+++ b/sdk/lib/async/zone.dart
@@ -385,6 +385,29 @@ abstract class Zone {
Zone get _errorZone;
/**
+ * Call to enter the Zone.
+ *
+ * The previous current zone is returned.
+ */
+ static Zone _enter(Zone zone) {
+ assert(zone != null);
+ assert(!identical(zone, _current));
+ Zone previous = _current;
+ _current = zone;
+ return previous;
+ }
+
+ /**
+ * Call to leave the Zone.
+ *
+ * The previous Zone must be provided as `previous`.
+ */
+ static void _leave(Zone previous) {
+ assert(previous != null);
+ Zone._current = previous;
+ }
+
+ /**
* Retrieves the zone-value associated with [key].
*
* If this zone does not contain the value looks up the same key in the
@@ -682,24 +705,22 @@ void _rootHandleUncaughtError(
dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) {
if (Zone._current == zone) return f();
- Zone old = Zone._current;
+ Zone old = Zone._enter(zone);
try {
- Zone._current = zone;
return f();
} finally {
- Zone._current = old;
+ Zone._leave(old);
}
}
dynamic _rootRunUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) {
if (Zone._current == zone) return f(arg);
- Zone old = Zone._current;
+ Zone old = Zone._enter(zone);
try {
- Zone._current = zone;
return f(arg);
} finally {
- Zone._current = old;
+ Zone._leave(old);
}
}
@@ -707,12 +728,11 @@ dynamic _rootRunBinary(Zone self, ZoneDelegate parent, Zone zone,
f(arg1, arg2), arg1, arg2) {
if (Zone._current == zone) return f(arg1, arg2);
- Zone old = Zone._current;
+ Zone old = Zone._enter(zone);
try {
- Zone._current = zone;
return f(arg1, arg2);
} finally {
- Zone._current = old;
+ Zone._leave(old);
}
}

Powered by Google App Engine
This is Rietveld 408576698