| 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);
|
| }
|
|
|
|
|