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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « frog/leg/elements/elements.dart ('k') | frog/leg/native_handler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('js_helper'); 5 #library('js_helper');
6 6
7 #import('coreimpl.dart'); 7 #import('coreimpl.dart');
8 8
9 #source('date_helper.dart'); 9 #source('date_helper.dart');
10 #source('regexp_helper.dart'); 10 #source('regexp_helper.dart');
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 } 1298 }
1299 } else if (JS('bool', @'$0 instanceof RangeError', ex)) { 1299 } else if (JS('bool', @'$0 instanceof RangeError', ex)) {
1300 var message = JS('String', @'$0.message', ex); 1300 var message = JS('String', @'$0.message', ex);
1301 if (message.contains('call stack')) { 1301 if (message.contains('call stack')) {
1302 return new StackOverflowException(); 1302 return new StackOverflowException();
1303 } 1303 }
1304 } 1304 }
1305 return ex; 1305 return ex;
1306 } 1306 }
1307 1307
1308 class StackTrace {
1309 var stack;
1310 StackTrace(this.stack);
1311 String toString() => stack != null ? stack : '';
1312 }
1313
1314 /** 1308 /**
1315 * Called by generated code to fetch the stack trace from an 1309 * Called by generated code to fetch the stack trace from an
1316 * exception. 1310 * exception.
1317 */ 1311 */
1318 StackTrace getTraceFromException(exception) { 1312 StackTrace getTraceFromException(exception) {
1319 return new StackTrace(JS("var", @"$0.stack", exception)); 1313 return new StackTrace(JS("var", @"$0.stack", exception));
1320 } 1314 }
1321 1315
1322 /** 1316 /**
1323 * Called by generated code to build a map literal. [keyValuePairs] is 1317 * Called by generated code to build a map literal. [keyValuePairs] is
1324 * a list of key, value, key, value, ..., etc. 1318 * a list of key, value, key, value, ..., etc.
1325 */ 1319 */
1326 makeLiteralMap(List keyValuePairs) { 1320 makeLiteralMap(List keyValuePairs) {
1327 Iterator iterator = keyValuePairs.iterator(); 1321 Iterator iterator = keyValuePairs.iterator();
1328 Map result = new LinkedHashMap(); 1322 Map result = new LinkedHashMap();
1329 while (iterator.hasNext()) { 1323 while (iterator.hasNext()) {
1330 String key = iterator.next(); 1324 String key = iterator.next();
1331 var value = iterator.next(); 1325 var value = iterator.next();
1332 result[key] = value; 1326 result[key] = value;
1333 } 1327 }
1334 return result; 1328 return result;
1335 } 1329 }
1330
1331 /**
1332 * Called by generated code to convert a Dart closure to a JS
1333 * closure when the Dart closure is passed to the DOM.
1334 */
1335 convertDartClosureToJS(closure) {
1336 return JS("var", @"""function() {
1337 var dartClosure = $0;
1338 switch (arguments.length) {
1339 case 0: return $1(dartClosure);
1340 case 1: return $2(dartClosure, arguments[0]);
1341 case 2: return $3(dartClosure, arguments[0], arguments[1]);
1342 default:
1343 throw new Error('Unsupported number of arguments for wrapped closure');
1344 }
1345 }""",
1346 closure,
1347 callClosure0,
1348 callClosure1,
1349 callClosure2);
1350 }
1351
1352 /**
1353 * Helper methods when converting a Dart closure to a JS closure.
1354 */
1355 callClosure0(closure) => closure();
1356 callClosure1(closure, arg1) => closure(arg1);
1357 callClosure2(closure, arg1, arg2) => closure(arg1, arg2);
1358
1359 class StackTrace {
1360 var stack;
1361 StackTrace(this.stack);
1362 String toString() => stack != null ? stack : '';
1363 }
OLDNEW
« 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