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

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
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 callClosure0(closure) => closure();
1309 callClosure1(closure, arg1) => closure(arg1);
1310 callClosure2(closure, arg1, arg2) => closure(arg1, arg2);
1311
1312 convertDartClosureToJS(closure) {
1313 return JS("var", @"""function() {
1314 var dartClosure = $0;
1315 switch (arguments.length) {
1316 case 0: return $1(dartClosure);
1317 case 1: return $2(dartClosure, arguments[0]);
1318 case 2: return $3(dartClosure, arguments[0], arguments[1]);
1319 default:
1320 throw new Error('Unsupported number of arguments for wrapped closure');
1321 }
1322 }""",
1323 closure,
1324 callClosure0,
1325 callClosure1,
1326 callClosure2);
1327 }
1328
1308 class StackTrace { 1329 class StackTrace {
1309 var stack; 1330 var stack;
1310 StackTrace(this.stack); 1331 StackTrace(this.stack);
1311 String toString() => stack != null ? stack : ''; 1332 String toString() => stack != null ? stack : '';
1312 } 1333 }
1313 1334
1314 /** 1335 /**
1315 * Called by generated code to fetch the stack trace from an 1336 * Called by generated code to fetch the stack trace from an
1316 * exception. 1337 * exception.
1317 */ 1338 */
1318 StackTrace getTraceFromException(exception) { 1339 StackTrace getTraceFromException(exception) {
1319 return new StackTrace(JS("var", @"$0.stack", exception)); 1340 return new StackTrace(JS("var", @"$0.stack", exception));
1320 } 1341 }
1321 1342
1322 /** 1343 /**
1323 * Called by generated code to build a map literal. [keyValuePairs] is 1344 * Called by generated code to build a map literal. [keyValuePairs] is
1324 * a list of key, value, key, value, ..., etc. 1345 * a list of key, value, key, value, ..., etc.
1325 */ 1346 */
1326 makeLiteralMap(List keyValuePairs) { 1347 makeLiteralMap(List keyValuePairs) {
1327 Iterator iterator = keyValuePairs.iterator(); 1348 Iterator iterator = keyValuePairs.iterator();
1328 Map result = new LinkedHashMap(); 1349 Map result = new LinkedHashMap();
1329 while (iterator.hasNext()) { 1350 while (iterator.hasNext()) {
1330 String key = iterator.next(); 1351 String key = iterator.next();
1331 var value = iterator.next(); 1352 var value = iterator.next();
1332 result[key] = value; 1353 result[key] = value;
1333 } 1354 }
1334 return result; 1355 return result;
1335 } 1356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698