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

Side by Side Diff: frog/leg/lib/js_helper.dart

Issue 9641018: Canonicalize closures passed to native functions. (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 | « no previous file | frog/tests/native/src/NativeClosureIdentityFrogTest.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 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 result[key] = value; 1326 result[key] = value;
1327 } 1327 }
1328 return result; 1328 return result;
1329 } 1329 }
1330 1330
1331 /** 1331 /**
1332 * Called by generated code to convert a Dart closure to a JS 1332 * Called by generated code to convert a Dart closure to a JS
1333 * closure when the Dart closure is passed to the DOM. 1333 * closure when the Dart closure is passed to the DOM.
1334 */ 1334 */
1335 convertDartClosureToJS(closure) { 1335 convertDartClosureToJS(closure) {
1336 return JS("var", @"""function() { 1336 if (JS('bool', @'"$identity" in $0', closure)) {
kasperl 2012/03/08 15:06:08 The 'in' construct is probably not going to perfor
ngeoffray 2012/03/08 15:11:36 OK, I copied the test from line 1276, I'll change
ngeoffray 2012/03/08 15:24:01 There is actually a good reason why the code line
1337 return JS('var', @'$0.$identity', closure);
1338 }
1339 var function = JS("var", @"""function() {
1337 var dartClosure = $0; 1340 var dartClosure = $0;
1338 switch (arguments.length) { 1341 switch (arguments.length) {
1339 case 0: return $1(dartClosure); 1342 case 0: return $1(dartClosure);
1340 case 1: return $2(dartClosure, arguments[0]); 1343 case 1: return $2(dartClosure, arguments[0]);
1341 case 2: return $3(dartClosure, arguments[0], arguments[1]); 1344 case 2: return $3(dartClosure, arguments[0], arguments[1]);
1342 default: 1345 default:
1343 throw new Error('Unsupported number of arguments for wrapped closure'); 1346 throw new Error('Unsupported number of arguments for wrapped closure');
1344 } 1347 }
1345 }""", 1348 }""",
1346 closure, 1349 closure,
1347 callClosure0, 1350 callClosure0,
1348 callClosure1, 1351 callClosure1,
1349 callClosure2); 1352 callClosure2);
1353 JS('void', @'$0.$identity = $1', closure, function);
1354 return function;
1350 } 1355 }
1351 1356
1352 /** 1357 /**
1353 * Helper methods when converting a Dart closure to a JS closure. 1358 * Helper methods when converting a Dart closure to a JS closure.
1354 */ 1359 */
1355 callClosure0(closure) => closure(); 1360 callClosure0(closure) => closure();
1356 callClosure1(closure, arg1) => closure(arg1); 1361 callClosure1(closure, arg1) => closure(arg1);
1357 callClosure2(closure, arg1, arg2) => closure(arg1, arg2); 1362 callClosure2(closure, arg1, arg2) => closure(arg1, arg2);
1358 1363
1359 class StackTrace { 1364 class StackTrace {
1360 var stack; 1365 var stack;
1361 StackTrace(this.stack); 1366 StackTrace(this.stack);
1362 String toString() => stack != null ? stack : ''; 1367 String toString() => stack != null ? stack : '';
1363 } 1368 }
OLDNEW
« no previous file with comments | « no previous file | frog/tests/native/src/NativeClosureIdentityFrogTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698