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

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

Issue 9702074: Add support for capturing and changing the current isolate in the closure wrapper. (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('constant_map.dart'); 9 #source('constant_map.dart');
10 #source('date_helper.dart'); 10 #source('date_helper.dart');
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 Iterator iterator = keyValuePairs.iterator(); 1339 Iterator iterator = keyValuePairs.iterator();
1340 Map result = new LinkedHashMap(); 1340 Map result = new LinkedHashMap();
1341 while (iterator.hasNext()) { 1341 while (iterator.hasNext()) {
1342 String key = iterator.next(); 1342 String key = iterator.next();
1343 var value = iterator.next(); 1343 var value = iterator.next();
1344 result[key] = value; 1344 result[key] = value;
1345 } 1345 }
1346 return result; 1346 return result;
1347 } 1347 }
1348 1348
1349 invokeClosure(Function closure,
1350 var isolate,
1351 int numberOfArguments,
1352 var arg1,
1353 var arg2) {
1354 if (numberOfArguments == 0) {
1355 return JS_CALL_IN_ISOLATE(isolate, () => closure());
1356 } else if (numberOfArguments == 1) {
1357 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1));
1358 } else if (numberOfArguments == 2) {
1359 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2));
1360 } else {
1361 throw new Exception(
1362 'Unsupported number of arguments for wrapped closure');
1363 }
1364 }
1365
1349 /** 1366 /**
1350 * Called by generated code to convert a Dart closure to a JS 1367 * Called by generated code to convert a Dart closure to a JS
1351 * closure when the Dart closure is passed to the DOM. 1368 * closure when the Dart closure is passed to the DOM.
1352 */ 1369 */
1353 convertDartClosureToJS(closure) { 1370 convertDartClosureToJS(closure) {
1354 if (closure === null) return null; 1371 if (closure === null) return null;
1355 var function = JS('var', @'#.$identity', closure); 1372 var function = JS('var', @'#.$identity', closure);
1356 if (JS('bool', @'!!#', function)) return function; 1373 if (JS('bool', @'!!#', function)) return function;
1374
1357 function = JS("var", @"""function() { 1375 function = JS("var", @"""function() {
1358 var dartClosure = #; 1376 return #(#, #, arguments.length, arguments[0], arguments[1]);
1359 switch (arguments.length) {
1360 case 0: return #(dartClosure);
1361 case 1: return #(dartClosure, arguments[0]);
1362 case 2: return #(dartClosure, arguments[0], arguments[1]);
1363 default:
1364 throw new Error('Unsupported number of arguments for wrapped closure');
1365 }
1366 }""", 1377 }""",
1378 invokeClosure,
1367 closure, 1379 closure,
1368 callClosure0, 1380 JS_CURRENT_ISOLATE());
1369 callClosure1, 1381
1370 callClosure2);
1371 JS('void', @'#.$identity = #', closure, function); 1382 JS('void', @'#.$identity = #', closure, function);
1372 return function; 1383 return function;
1373 } 1384 }
1374 1385
1375 /** 1386 /**
1376 * Helper methods when converting a Dart closure to a JS closure.
1377 */
1378 callClosure0(closure) => closure();
1379 callClosure1(closure, arg1) => closure(arg1);
1380 callClosure2(closure, arg1, arg2) => closure(arg1, arg2);
1381
1382 /**
1383 * Super class for Dart closures. 1387 * Super class for Dart closures.
1384 */ 1388 */
1385 class Closure implements Function { 1389 class Closure implements Function {
1386 String toString() => "Closure"; 1390 String toString() => "Closure";
1387 } 1391 }
1388 1392
1389 bool jsHasOwnProperty(var jsObject, String property) { 1393 bool jsHasOwnProperty(var jsObject, String property) {
1390 return JS('bool', @'#.hasOwnProperty(#)', jsObject, property); 1394 return JS('bool', @'#.hasOwnProperty(#)', jsObject, property);
1391 } 1395 }
1392 1396
1393 jsPropertyAccess(var jsObject, String property) { 1397 jsPropertyAccess(var jsObject, String property) {
1394 return JS('var', @'#[#]', jsObject, property); 1398 return JS('var', @'#[#]', jsObject, property);
1395 } 1399 }
1396 1400
1397 /** 1401 /**
1398 * Called at the end of unaborted switch cases to get the singleton 1402 * Called at the end of unaborted switch cases to get the singleton
1399 * FallThroughError exception that will be thrown. 1403 * FallThroughError exception that will be thrown.
1400 */ 1404 */
1401 getFallThroughError() => const FallThroughError(); 1405 getFallThroughError() => const FallThroughError();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698