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

Side by Side Diff: runtime/lib/async_patch.dart

Issue 2684963004: Move _fatal to dart:async (Closed)
Patch Set: Restore the original behavior Created 3 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
« no previous file with comments | « no previous file | runtime/lib/internal_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:_internal"; 5 import "dart:_internal";
6 6
7 // Equivalent of calling FATAL from C++ code.
8 _fatal(msg) native "DartAsync_fatal";
9
7 // We need to pass the value as first argument and leave the second and third 10 // We need to pass the value as first argument and leave the second and third
8 // arguments empty (used for error handling). 11 // arguments empty (used for error handling).
9 // See vm/ast_transformer.cc for usage. 12 // See vm/ast_transformer.cc for usage.
10 Function _asyncThenWrapperHelper(continuation) { 13 Function _asyncThenWrapperHelper(continuation) {
11 // Any function that is used as an asynchronous callback must be registered 14 // Any function that is used as an asynchronous callback must be registered
12 // in the current Zone. Normally, this is done by the future when a 15 // in the current Zone. Normally, this is done by the future when a
13 // callback is registered (for example with `.then` or `.catchError`). In our 16 // callback is registered (for example with `.then` or `.catchError`). In our
14 // case we want to reuse the same callback multiple times and therefore avoid 17 // case we want to reuse the same callback multiple times and therefore avoid
15 // the multiple registrations. For our internal futures (`_Future`) we can 18 // the multiple registrations. For our internal futures (`_Future`) we can
16 // use the shortcut-version of `.then`, and skip the registration. However, 19 // use the shortcut-version of `.then`, and skip the registration. However,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // execution of the generator. 93 // execution of the generator.
91 // 94 //
92 // TODO(hausner): Per spec, the generator should be suspended before 95 // TODO(hausner): Per spec, the generator should be suspended before
93 // exiting when the stream is closed. We could add a getter like this: 96 // exiting when the stream is closed. We could add a getter like this:
94 // get isCancelled => controller.hasListener; 97 // get isCancelled => controller.hasListener;
95 // The generator would translate a 'yield e' statement to 98 // The generator would translate a 'yield e' statement to
96 // controller.add(e); 99 // controller.add(e);
97 // suspend; 100 // suspend;
98 // if (controller.isCancelled) return; 101 // if (controller.isCancelled) return;
99 bool add(event) { 102 bool add(event) {
100 if (!onListenReceived) fatal("yield before stream is listened to!"); 103 if (!onListenReceived) _fatal("yield before stream is listened to");
101 if (isSuspendedAtYield) fatal("unexpected yield"); 104 if (isSuspendedAtYield) _fatal("unexpected yield");
102 // If stream is cancelled, tell caller to exit the async generator. 105 // If stream is cancelled, tell caller to exit the async generator.
103 if (!controller.hasListener) { 106 if (!controller.hasListener) {
104 return true; 107 return true;
105 } 108 }
106 controller.add(event); 109 controller.add(event);
107 scheduleGenerator(); 110 scheduleGenerator();
108 isSuspendedAtYield = true; 111 isSuspendedAtYield = true;
109 return false; 112 return false;
110 } 113 }
111 114
112 // Adds the elements of stream into this controller's stream. 115 // Adds the elements of stream into this controller's stream.
113 // The generator will be scheduled again when all of the 116 // The generator will be scheduled again when all of the
114 // elements of the added stream have been consumed. 117 // elements of the added stream have been consumed.
115 // Returns true if the caller should terminate 118 // Returns true if the caller should terminate
116 // execution of the generator. 119 // execution of the generator.
117 bool addStream(Stream stream) { 120 bool addStream(Stream stream) {
118 if (!onListenReceived) fatal("yield before stream is listened to!"); 121 if (!onListenReceived) _fatal("yield before stream is listened to");
119 // If stream is cancelled, tell caller to exit the async generator. 122 // If stream is cancelled, tell caller to exit the async generator.
120 if (!controller.hasListener) return true; 123 if (!controller.hasListener) return true;
121 isAdding = true; 124 isAdding = true;
122 var whenDoneAdding = 125 var whenDoneAdding =
123 controller.addStream(stream as Stream, cancelOnError: false); 126 controller.addStream(stream as Stream, cancelOnError: false);
124 whenDoneAdding.then((_) { 127 whenDoneAdding.then((_) {
125 isAdding = false; 128 isAdding = false;
126 scheduleGenerator(); 129 scheduleGenerator();
127 if (!isScheduled) isSuspendedAtYield = true; 130 if (!isScheduled) isSuspendedAtYield = true;
128 }); 131 });
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 197
195 /// Returns a [StackTrace] object containing the synchronous prefix for this 198 /// Returns a [StackTrace] object containing the synchronous prefix for this
196 /// asynchronous method. 199 /// asynchronous method.
197 Object _asyncStackTraceHelper() native "StackTrace_asyncStackTraceHelper"; 200 Object _asyncStackTraceHelper() native "StackTrace_asyncStackTraceHelper";
198 201
199 void _clearAsyncThreadStackTrace() 202 void _clearAsyncThreadStackTrace()
200 native "StackTrace_clearAsyncThreadStackTrace"; 203 native "StackTrace_clearAsyncThreadStackTrace";
201 204
202 void _setAsyncThreadStackTrace(StackTrace stackTrace) native 205 void _setAsyncThreadStackTrace(StackTrace stackTrace) native
203 "StackTrace_setAsyncThreadStackTrace"; 206 "StackTrace_setAsyncThreadStackTrace";
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/internal_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698