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

Unified Diff: frog/leg/lib/js_helper.dart

Issue 9618053: Introduce the TYPEDEF element, and use it in order to catch passing closures to the DOM. I make the… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « frog/leg/elements/elements.dart ('k') | frog/leg/native_handler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/lib/js_helper.dart
===================================================================
--- frog/leg/lib/js_helper.dart (revision 5070)
+++ frog/leg/lib/js_helper.dart (working copy)
@@ -1305,12 +1305,6 @@
return ex;
}
-class StackTrace {
- var stack;
- StackTrace(this.stack);
- String toString() => stack != null ? stack : '';
-}
-
/**
* Called by generated code to fetch the stack trace from an
* exception.
@@ -1333,3 +1327,37 @@
}
return result;
}
+
+/**
+ * Called by generated code to convert a Dart closure to a JS
+ * closure when the Dart closure is passed to the DOM.
+ */
+convertDartClosureToJS(closure) {
+ return JS("var", @"""function() {
+ var dartClosure = $0;
+ switch (arguments.length) {
+ case 0: return $1(dartClosure);
+ case 1: return $2(dartClosure, arguments[0]);
+ case 2: return $3(dartClosure, arguments[0], arguments[1]);
+ default:
+ throw new Error('Unsupported number of arguments for wrapped closure');
+ }
+ }""",
+ closure,
+ callClosure0,
+ callClosure1,
+ callClosure2);
+}
+
+/**
+ * Helper methods when converting a Dart closure to a JS closure.
+ */
+callClosure0(closure) => closure();
+callClosure1(closure, arg1) => closure(arg1);
+callClosure2(closure, arg1, arg2) => closure(arg1, arg2);
+
+class StackTrace {
+ var stack;
+ StackTrace(this.stack);
+ String toString() => stack != null ? stack : '';
+}
« no previous file with comments | « frog/leg/elements/elements.dart ('k') | frog/leg/native_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698