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

Unified Diff: sdk/lib/js/dart2js/js_dart2js.dart

Issue 222203009: Execute callbacks from JS in the correct zone Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add _wrapToJs Created 6 years, 8 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
« no previous file with comments | « no previous file | sdk/lib/js/dartium/js_dartium.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/js/dart2js/js_dart2js.dart
diff --git a/sdk/lib/js/dart2js/js_dart2js.dart b/sdk/lib/js/dart2js/js_dart2js.dart
index 84ec8f356708b114ff9915d2aedadfbc6da46781..4bc28ac2420fd25e47e57a654dff65743a4fec54 100644
--- a/sdk/lib/js/dart2js/js_dart2js.dart
+++ b/sdk/lib/js/dart2js/js_dart2js.dart
@@ -87,6 +87,7 @@
*/
library dart.js;
+import 'dart:async' show Zone;
import 'dart:html' show Blob, Event, ImageData, Node, Window;
import 'dart:collection' show HashMap, ListMixin;
import 'dart:indexed_db' show KeyRange;
@@ -99,22 +100,35 @@ import 'dart:_js_helper' show Primitives, convertDartClosureToJS,
final JsObject context = _wrapToDart(Primitives.computeGlobalThis());
-_convertDartFunction(Function f, {bool captureThis: false}) {
+_convertDartFunction(Function f) {
return JS('',
- 'function(_call, f, captureThis) {'
+ 'function(_call, f) {'
'return function() {'
- 'return _call(f, captureThis, this, '
- 'Array.prototype.slice.apply(arguments));'
+ 'return _call(f, Array.prototype.slice.apply(arguments));'
'}'
- '}(#, #, #)', DART_CLOSURE_TO_JS(_callDartFunction), f, captureThis);
+ '}(#, #)', DART_CLOSURE_TO_JS(_callDartFunction), _applyZoned(f));
}
-_callDartFunction(callback, bool captureThis, self, List arguments) {
- if (captureThis) {
- arguments = [self]..addAll(arguments);
- }
- var dartArgs = new List.from(arguments.map(_convertToDart));
- return _convertToJS(Function.apply(callback, dartArgs));
+_convertDartFunctionWithThis(Function f) {
+ return JS('',
+ 'function(_call, f) {'
+ 'return function() {'
+ 'var args = Array.prototype.slice.apply(arguments);'
+ 'args.unshift(this);'
+ 'return _call(f, args);'
+ '}'
+ '}(#, #)', DART_CLOSURE_TO_JS(_callDartFunction), _applyZoned(f));
+}
+
+_callDartFunction(f, List arguments) => f(arguments);
+
+_applyZoned(f) {
+ var callDart = (List arguments) {
+ var dartArgs = new List.from(arguments.map(_convertToDart));
+ return _convertToJS(Function.apply(f, dartArgs));
+ };
+ if (Zone.current == Zone.ROOT) return callDart;
+ return Zone.current.bindUnaryCallback(callDart);
}
/**
@@ -323,7 +337,7 @@ class JsFunction extends JsObject {
* with the value of this passed as the first argument.
*/
factory JsFunction.withThis(Function f) {
- var jsFunc = _convertDartFunction(f, captureThis: true);
+ var jsFunc = _convertDartFunctionWithThis(f);
return new JsFunction._fromJs(jsFunc);
}
« no previous file with comments | « no previous file | sdk/lib/js/dartium/js_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698