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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 926553005: Move the try-catch out of the async-function (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/js_lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index f948cab8dd5c94e9a5db82c77f11ff53d8cf7dfa..1827adb2fe618ae35e44e98ac7849ef32ea9ea0b 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -3589,8 +3589,20 @@ dynamic asyncHelper(dynamic object,
Function _wrapJsFunctionForAsync(dynamic /* js function */ function,
int errorCode) {
+ var protected = JS('', """
+ function(errorCode, result) {
+ while (true) {
floitsch 2015/02/18 12:42:45 Add comment. // Invokes [function] with [errorCode
sigurdm 2015/02/19 09:14:02 Done.
+ try {
+ #(errorCode, result);
+ break;
+ } catch (error) {
+ result = error;
+ errorCode = #;
+ }
+ } while (false);
floitsch 2015/02/18 12:42:45 while (false); ?
sigurdm 2015/02/19 09:14:02 I started out with do { try { .... } catch
+ }""", function, async_error_codes.ERROR);
return (result) {
- JS('', '#(#, #)', function, errorCode, result);
+ JS('', '#(#, #)', protected, errorCode, result);
};
}
@@ -3760,7 +3772,7 @@ class IterationMarker {
}
class SyncStarIterator implements Iterator {
- final Function _body;
+ final dynamic _body;
// If [runningNested] this is the nested iterator, otherwise it is the
// current value.
@@ -3769,8 +3781,23 @@ class SyncStarIterator implements Iterator {
get current => _runningNested ? _current.current : _current;
- SyncStarIterator(body)
- : _body = (() => JS('', '#()', body));
+ SyncStarIterator(this._body);
+
+ runBody() {
+ return JS('', '''
+ (function(body) {
+ var errorValue, errorCode = #;
+ while (true) {
floitsch 2015/02/18 12:42:45 ditto.
sigurdm 2015/02/19 09:14:02 Done.
+ try {
+ return body(errorCode, errorValue);
+ } catch (error) {
+ errorValue = error;
+ errorCode = #
+ }
+ }
+ })(#)''', async_error_codes.SUCCESS, async_error_codes.ERROR, _body);
+ }
+
bool moveNext() {
if (_runningNested) {
@@ -3780,7 +3807,7 @@ class SyncStarIterator implements Iterator {
_runningNested = false;
}
}
- _current = _body();
+ _current = runBody();
if (_current is IterationMarker) {
if (_current.state == IterationMarker.ITERATION_ENDED) {
_current = null;
« pkg/compiler/lib/src/js/rewrite_async.dart ('K') | « pkg/compiler/lib/src/js/rewrite_async.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698