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

Unified Diff: sdk/lib/_internal/js_runtime/lib/async_patch.dart

Issue 1436263002: dart2js: Forbid # placeholders in JS function bodies. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/js_runtime/lib/async_patch.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/async_patch.dart b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
index de6940a68793edc95de35615496c411542ccc6dd..c57b3d2be0819541eec1420696df3ba552fed7a8 100644
--- a/sdk/lib/_internal/js_runtime/lib/async_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
@@ -195,22 +195,28 @@ void _awaitOnObject(object, _WrappedAsyncBody bodyFunction) {
typedef void _WrappedAsyncBody(int errorCode, dynamic result);
_WrappedAsyncBody _wrapJsFunctionForAsync(dynamic /* js function */ function) {
- var protected = JS('', """
- // Invokes [function] with [errorCode] and [result].
- //
- // If (and as long as) the invocation throws, calls [function] again,
- // with an error-code.
- function(errorCode, result) {
- while (true) {
- try {
- #(errorCode, result);
- break;
- } catch (error) {
- result = error;
- errorCode = #;
- }
- }
- }""", function, async_error_codes.ERROR);
+ var protected = JS(
+ '',
+ """
+ (function (fn, ERROR) {
+ // Invokes [function] with [errorCode] and [result].
+ //
+ // If (and as long as) the invocation throws, calls [function] again,
+ // with an error-code.
+ return function(errorCode, result) {
+ while (true) {
+ try {
+ fn(errorCode, result);
+ break;
+ } catch (error) {
+ result = error;
+ errorCode = ERROR;
+ }
+ }
+ }
+ })(#, #)""",
+ function, async_error_codes.ERROR);
+
return Zone.current.registerBinaryCallback((int errorCode, dynamic result) {
JS('', '#(#, #)', protected, errorCode, result);
});
@@ -444,22 +450,25 @@ class _SyncStarIterator implements Iterator {
_SyncStarIterator(this._body);
_runBody() {
- return JS('', '''
-// Invokes [body] with [errorCode] and [result].
-//
-// If (and as long as) the invocation throws, calls [function] again,
-// with an error-code.
-(function(body) {
- var errorValue, errorCode = #;
- while (true) {
- try {
- return body(errorCode, errorValue);
- } catch (error) {
- errorValue = error;
- errorCode = #
- }
- }
-})(#)''', async_error_codes.SUCCESS, async_error_codes.ERROR, _body);
+ // TODO(sra): Find a way to hard-wire SUCCESS and ERROR codes.
+ return JS('',
+ '''
+ // Invokes [body] with [errorCode] and [result].
+ //
+ // If (and as long as) the invocation throws, calls [function] again,
+ // with an error-code.
+ (function(body, SUCCESS, ERROR) {
+ var errorValue, errorCode = SUCCESS;
+ while (true) {
+ try {
+ return body(errorCode, errorValue);
+ } catch (error) {
+ errorValue = error;
+ errorCode = ERROR;
+ }
+ }
+ })(#, #, #)''',
+ _body, async_error_codes.SUCCESS, async_error_codes.ERROR);
}
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698