Chromium Code Reviews| Index: sdk/lib/js/dartium/js_dartium.dart |
| diff --git a/sdk/lib/js/dartium/js_dartium.dart b/sdk/lib/js/dartium/js_dartium.dart |
| index e7f3004c686d8efbc0b5bdc038bbb28178f2f5d2..374d53655742682cfea035ce0a86be607cd4ccca 100644 |
| --- a/sdk/lib/js/dartium/js_dartium.dart |
| +++ b/sdk/lib/js/dartium/js_dartium.dart |
| @@ -87,6 +87,7 @@ |
| */ |
| library dart.js; |
| +import 'dart:async' show Zone; |
| import 'dart:collection' show ListMixin; |
| import 'dart:nativewrappers'; |
| @@ -171,7 +172,11 @@ class JsObject extends NativeFieldWrapperClass2 { |
| * |
| * The type of [property] must be either [String] or [num]. |
| */ |
| - operator[]=(property, value) native "JsObject_[]="; |
| + operator[]=(property, value) { |
| + return _setIndex(property, _maybeWrapFunction(value)); |
| + } |
| + |
| + Object _setIndex(property, value) native "JsObject_[]="; |
| int get hashCode native "JsObject_hashCode"; |
| @@ -222,6 +227,7 @@ class JsObject extends NativeFieldWrapperClass2 { |
| */ |
| callMethod(String method, [List args]) { |
| try { |
| + args = args == null ? null : args.map(_maybeWrapFunction).toList(); |
| return _callMethod(method, args); |
| } catch(e) { |
| if (hasProperty(method)) { |
| @@ -245,7 +251,7 @@ class JsFunction extends JsObject { |
| * Returns a [JsFunction] that captures its 'this' binding and calls [f] |
| * with the value of this passed as the first argument. |
| */ |
| - factory JsFunction.withThis(Function f) => _withThis(f); |
| + factory JsFunction.withThis(Function f) => _withThis(_maybeWrapFunction(f)); |
| /** |
| * Invokes the JavaScript function with arguments [args]. If [thisArg] is |
| @@ -359,6 +365,17 @@ class JsArray<E> extends JsObject with ListMixin<E> { |
| } |
| } |
| +_maybeWrapFunction(value) { |
| + if (value is Function) return _applyZoned(value); |
|
Jacob
2014/04/10 00:51:53
nit: the following is cleaner.
_maybeWrapFunction(
justinfagnani
2014/04/10 03:55:05
Done.
|
| + return value; |
| +} |
| + |
| +_applyZoned(f) { |
| + var call = (List arguments) => Function.apply(f, arguments); |
| + if (Zone.current == Zone.ROOT) return call; |
| + return Zone.current.bindUnaryCallback(call); |
| +} |
| + |
| /** |
| * Placeholder object for cases where we need to determine exactly how many |
| * args were passed to a function. |