OLD | NEW |
---|---|
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 _isolate_helper; | 5 library _isolate_helper; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection' show Queue, HashMap; | 8 import 'dart:collection' show Queue, HashMap; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 import 'dart:_js_helper' show | 10 import 'dart:_js_helper' show |
11 Closure, | |
11 Null, | 12 Null, |
12 Primitives, | 13 Primitives, |
13 convertDartClosureToJS; | 14 convertDartClosureToJS; |
14 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, | 15 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, |
15 JS, | 16 JS, |
16 JS_CREATE_ISOLATE, | 17 JS_CREATE_ISOLATE, |
17 JS_CURRENT_ISOLATE_CONTEXT, | 18 JS_CURRENT_ISOLATE_CONTEXT, |
18 JS_CURRENT_ISOLATE, | 19 JS_CURRENT_ISOLATE, |
19 JS_SET_CURRENT_ISOLATE, | 20 JS_SET_CURRENT_ISOLATE, |
20 IsolateContext; | 21 IsolateContext; |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 throw new Exception(trace); | 542 throw new Exception(trace); |
542 } | 543 } |
543 } | 544 } |
544 } | 545 } |
545 | 546 |
546 static void _consoleLog(msg) { | 547 static void _consoleLog(msg) { |
547 JS("void", r"#.console.log(#)", globalThis, msg); | 548 JS("void", r"#.console.log(#)", globalThis, msg); |
548 } | 549 } |
549 | 550 |
550 static _getJSFunctionFromName(String functionName) { | 551 static _getJSFunctionFromName(String functionName) { |
551 return JS("", "init.globalFunctions[#]", functionName); | 552 return JS("", "init.globalFunctions[#]()", functionName); |
552 } | 553 } |
553 | 554 |
554 /** | 555 /** |
555 * Get a string name for the function, if possible. The result for | 556 * Get a string name for the function, if possible. The result for |
556 * anonymous functions is browser-dependent -- it may be "" or "anonymous" | 557 * anonymous functions is browser-dependent -- it may be "" or "anonymous" |
557 * but you should probably not count on this. | 558 * but you should probably not count on this. |
558 */ | 559 */ |
559 static String _getJSFunctionName(Function f) { | 560 static String _getJSFunctionName(Function f) { |
560 return JS("String|Null", r"(#['$name'] || #)", f, null); | 561 if (f is! Closure) return null; |
kasperl
2013/11/29 10:10:55
?:
ahe
2013/12/06 15:57:53
Done.
| |
562 return JS("String|Null", r'#.$name', f); | |
561 } | 563 } |
562 | 564 |
563 /** Create a new JavaScript object instance given its constructor. */ | 565 /** Create a new JavaScript object instance given its constructor. */ |
564 static dynamic _allocate(var ctor) { | 566 static dynamic _allocate(var ctor) { |
565 return JS("", "new #()", ctor); | 567 return JS("", "new #()", ctor); |
566 } | 568 } |
567 | 569 |
568 static SendPort spawnFunction(void topLevelFunction(message), message) { | 570 static SendPort spawnFunction(void topLevelFunction(message), message) { |
569 final name = _getJSFunctionName(topLevelFunction); | 571 final name = _getJSFunctionName(topLevelFunction); |
570 if (name == null) { | 572 if (name == null) { |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 _handle = null; | 1376 _handle = null; |
1375 } else { | 1377 } else { |
1376 throw new UnsupportedError("Canceling a timer."); | 1378 throw new UnsupportedError("Canceling a timer."); |
1377 } | 1379 } |
1378 } | 1380 } |
1379 | 1381 |
1380 bool get isActive => _handle != null; | 1382 bool get isActive => _handle != null; |
1381 } | 1383 } |
1382 | 1384 |
1383 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; | 1385 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; |
OLD | NEW |