Chromium Code Reviews| 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 cda541dfc9cd14d9a661701a8fad78e2255a6dec..fd0d72679698e64232c201346d65a54fc94342e3 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, runGuarded: true); |
|
floitsch
2014/04/03 12:52:30
are you sure you want to run guarded?
Running guar
justinfagnani
2014/04/10 00:26:59
I'll assume that JS should have a chance to handle
|
| } |
| /** |
| @@ -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); |
| } |