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

Side by Side Diff: third_party/pkg/angular/lib/core/zone.dart

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 part of angular.core; 1 part of angular.core;
2 2
3 typedef void ZoneOnTurn(); 3 typedef void ZoneOnTurn();
4 typedef void ZoneOnError(dynamic error, dynamic stacktrace, LongStackTrace longS tacktrace); 4 typedef void ZoneOnError(dynamic error, dynamic stacktrace,
5 LongStackTrace longStacktrace);
5 6
6 /** 7 /**
7 * Contains the locations of runAsync calls across VM turns. 8 * Contains the locations of runAsync calls across VM turns.
8 */ 9 */
9 class LongStackTrace { 10 class LongStackTrace {
10 final String reason; 11 final String reason;
11 final dynamic stacktrace; 12 final dynamic stacktrace;
12 final LongStackTrace parent; 13 final LongStackTrace parent;
13 14
14 LongStackTrace(this.reason, this.stacktrace, this.parent); 15 LongStackTrace(this.reason, this.stacktrace, this.parent);
15 16
16 toString() { 17 toString() {
17 List<String> frames = '${this.stacktrace}'.split('\n'); 18 List<String> frames = '${this.stacktrace}'.split('\n')
18 frames = frames.where((frame) { 19 .where((frame) =>
19 return frame.indexOf('(dart:') == -1 && // skip dart runtime libs 20 frame.indexOf('(dart:') == -1 && // skip dart runtime libs
20 frame.indexOf('(package:angular/zone.dart') == -1; // skip angular zone 21 frame.indexOf('(package:angular/zone.dart') == -1 // skip angular zo ne
21 }).toList(); 22 ).toList()..insert(0, reason);
22 frames.insert(0, reason);
23 var parent = this.parent == null ? '' : this.parent; 23 var parent = this.parent == null ? '' : this.parent;
24 return '${frames.join("\n ")}\n$parent'; 24 return '${frames.join("\n ")}\n$parent';
25 } 25 }
26 } 26 }
27 27
28 /** 28 /**
29 * A better zone API which implements onTurnDone. 29 * A better zone API which implements onTurnDone.
30 */ 30 */
31 class NgZone { 31 class NgZone {
32 NgZone() { 32 final async.Zone _outerZone;
33 _zone = async.Zone.current.fork(specification: new async.ZoneSpecification( 33 async.Zone _zone;
34
35 NgZone()
36 : _outerZone = async.Zone.current
37 {
38 _zone = _outerZone.fork(specification: new async.ZoneSpecification(
34 run: _onRun, 39 run: _onRun,
35 runUnary: _onRunUnary, 40 runUnary: _onRunUnary,
36 scheduleMicrotask: _onScheduleMicrotask, 41 scheduleMicrotask: _onScheduleMicrotask,
37 handleUncaughtError: _uncaughtError 42 handleUncaughtError: _uncaughtError
38 )); 43 ));
39 } 44 }
40 45
41 async.Zone _zone;
42 46
43 List _asyncQueue = []; 47 List _asyncQueue = [];
44 bool _errorThrownFromOnRun = false; 48 bool _errorThrownFromOnRun = false;
45 49
46 _onRunBase(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn() ) { 50 _onRunBase(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn() ) {
47 _runningInTurn++; 51 _runningInTurn++;
48 try { 52 try {
49 return fn(); 53 return fn();
50 } catch (e, s) { 54 } catch (e, s) {
51 onError(e, s, _longStacktrace); 55 onError(e, s, _longStacktrace);
52 _errorThrownFromOnRun = true; 56 _errorThrownFromOnRun = true;
53 rethrow; 57 rethrow;
54 } finally { 58 } finally {
55 _runningInTurn--; 59 _runningInTurn--;
56 if (_runningInTurn == 0) 60 if (_runningInTurn == 0) _finishTurn(zone, delegate);
57 _finishTurn(zone, delegate);
58 } 61 }
59 } 62 }
60 // Called from the parent zone. 63 // Called from the parent zone.
61 _onRun(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn()) { 64 _onRun(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn()) =>
62 return _onRunBase(self, delegate, zone, () => delegate.run(zone, fn)); 65 _onRunBase(self, delegate, zone, () => delegate.run(zone, fn));
66
67 _onRunUnary(async.Zone self, async.ZoneDelegate delegate, async.Zone zone,
68 fn(args), args) =>
69 _onRunBase(self, delegate, zone, () => delegate.runUnary(zone, fn, args));
70
71 _onScheduleMicrotask(async.Zone self, async.ZoneDelegate delegate,
72 async.Zone zone, fn()) {
73 _asyncQueue.add(() => delegate.run(zone, fn));
74 if (_runningInTurn == 0 && !_inFinishTurn) _finishTurn(zone, delegate);
63 } 75 }
64 76
65 _onRunUnary(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn( args), args) { 77 _uncaughtError(async.Zone self, async.ZoneDelegate delegate, async.Zone zone,
66 return _onRunBase(self, delegate, zone, () => delegate.runUnary(zone, fn, ar gs)); 78 e, StackTrace s) {
67 } 79 if (!_errorThrownFromOnRun) onError(e, s, _longStacktrace);
68
69 _onScheduleMicrotask(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn()) {
70 _asyncQueue.add(() => delegate.run(zone, fn));
71 if (_runningInTurn == 0 && !_inFinishTurn) {
72 _finishTurn(zone, delegate);
73 }
74 }
75
76 _uncaughtError(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, e, StackTrace s) {
77 if (!_errorThrownFromOnRun) {
78 onError(e, s, _longStacktrace);
79 }
80 _errorThrownFromOnRun = false; 80 _errorThrownFromOnRun = false;
81 } 81 }
82 82
83 var _inFinishTurn = false; 83 var _inFinishTurn = false;
84 _finishTurn(zone, delegate) { 84 _finishTurn(zone, delegate) {
85 if (_inFinishTurn) { 85 if (_inFinishTurn) return;
86 return;
87 }
88 _inFinishTurn = true; 86 _inFinishTurn = true;
89 try { 87 try {
90 // Two loops here: the inner one runs all queued microtasks, 88 // Two loops here: the inner one runs all queued microtasks,
91 // the outer runs onTurnDone (e.g. scope.$digest) and then 89 // the outer runs onTurnDone (e.g. scope.digest) and then
92 // any microtasks which may have been queued from onTurnDone. 90 // any microtasks which may have been queued from onTurnDone.
93 do { 91 do {
94 while (!_asyncQueue.isEmpty) { 92 while (!_asyncQueue.isEmpty) {
95 delegate.run(zone, _asyncQueue.removeAt(0)); 93 delegate.run(zone, _asyncQueue.removeAt(0));
96 } 94 }
97 delegate.run(zone, onTurnDone); 95 delegate.run(zone, onTurnDone);
98 } while (!_asyncQueue.isEmpty); 96 } while (!_asyncQueue.isEmpty);
99 } catch (e, s) { 97 } catch (e, s) {
100 onError(e, s, _longStacktrace); 98 onError(e, s, _longStacktrace);
101 _errorThrownFromOnRun = true; 99 _errorThrownFromOnRun = true;
(...skipping 24 matching lines...) Expand all
126 124
127 LongStackTrace _longStacktrace = null; 125 LongStackTrace _longStacktrace = null;
128 126
129 LongStackTrace _getLongStacktrace(name) { 127 LongStackTrace _getLongStacktrace(name) {
130 var shortStacktrace = 'Long-stacktraces supressed in production.'; 128 var shortStacktrace = 'Long-stacktraces supressed in production.';
131 assert((shortStacktrace = _getStacktrace()) != null); 129 assert((shortStacktrace = _getStacktrace()) != null);
132 return new LongStackTrace(name, shortStacktrace, _longStacktrace); 130 return new LongStackTrace(name, shortStacktrace, _longStacktrace);
133 } 131 }
134 132
135 _getStacktrace() { 133 _getStacktrace() {
136 try { throw []; } catch (e, s) { 134 try {
135 throw [];
136 } catch (e, s) {
137 return s; 137 return s;
138 } 138 }
139 } 139 }
140 140
141 /** 141 /**
142 * Runs the provided function in the zone. Any runAsync calls (e.g. futures) 142 * Runs the provided function in the zone. Any runAsync calls (e.g. futures)
143 * will also be run in this zone. 143 * will also be run in this zone.
144 * 144 *
145 * Returns the return value of body. 145 * Returns the return value of body.
146 */ 146 */
147 run(body()) => _zone.run(body); 147 run(body()) => _zone.run(body);
148 148
149 /**
150 * Allows one to escape the auto-digest mechanism of Angular.
151 *
152 * myFunction(NgZone zone, Element element) {
153 * element.onClick.listen(() {
154 * // auto-digest will run after element click.
155 * });
156 * zone.runOutsideAngular(() {
157 * element.onMouseMove.listen(() {
158 * // auto-digest will NOT run after mouse move
159 * });
160 * });
161 * }
162 */
163 runOutsideAngular(body()) => _outerZone.run(body);
164
149 assertInTurn() { 165 assertInTurn() {
150 assert(_runningInTurn > 0 || _inFinishTurn); 166 assert(_runningInTurn > 0 || _inFinishTurn);
151 } 167 }
152 168
153 assertInZone() { 169 assertInZone() {
154 assertInTurn(); 170 assertInTurn();
155 } 171 }
156 } 172 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/core/scope.dart ('k') | third_party/pkg/angular/lib/core_dom/block.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698