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

Unified Diff: sdk/lib/js/dartium/js_dartium.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 Dartium support 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 | « sdk/lib/js/dart2js/js_dart2js.dart ('k') | tests/html/js_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « sdk/lib/js/dart2js/js_dart2js.dart ('k') | tests/html/js_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698