| 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:_js_embedded_names' show | 7 import 'dart:_js_embedded_names' show |
| 8 CLASS_ID_EXTRACTOR, | 8 CLASS_ID_EXTRACTOR, |
| 9 CLASS_FIELDS_EXTRACTOR, | 9 CLASS_FIELDS_EXTRACTOR, |
| 10 CURRENT_SCRIPT, | 10 CURRENT_SCRIPT, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 * isolates running under the same manager (either UI or background web worker). | 150 * isolates running under the same manager (either UI or background web worker). |
| 151 * | 151 * |
| 152 * This is code that is intended to 'escape' the isolate boundaries in order to | 152 * This is code that is intended to 'escape' the isolate boundaries in order to |
| 153 * implement the semantics of isolates in JavaScript. Without this we would have | 153 * implement the semantics of isolates in JavaScript. Without this we would have |
| 154 * been forced to implement more code (including the top-level event loop) in | 154 * been forced to implement more code (including the top-level event loop) in |
| 155 * JavaScript itself. | 155 * JavaScript itself. |
| 156 */ | 156 */ |
| 157 // TODO(eub, sigmund): move the "manager" to be entirely in JS. | 157 // TODO(eub, sigmund): move the "manager" to be entirely in JS. |
| 158 // Running any Dart code outside the context of an isolate gives it | 158 // Running any Dart code outside the context of an isolate gives it |
| 159 // the chance to break the isolate abstraction. | 159 // the chance to break the isolate abstraction. |
| 160 _Manager get _globalState => JS("_Manager", "init.globalState"); | 160 // TODO(vsm): This was changed from init.globalState. |
| 161 // See: https://github.com/dart-lang/dev_compiler/issues/164 |
| 162 _Manager get _globalState => JS("_Manager", "dart.globalState"); |
| 161 | 163 |
| 162 set _globalState(_Manager val) { | 164 set _globalState(_Manager val) { |
| 163 JS("void", "init.globalState = #", val); | 165 // TODO(vsm): This was changed from init.globalState. |
| 166 // See: https://github.com/dart-lang/dev_compiler/issues/164 |
| 167 JS("void", "dart.globalState = #", val); |
| 164 } | 168 } |
| 165 | 169 |
| 166 /** State associated with the current manager. See [globalState]. */ | 170 /** State associated with the current manager. See [globalState]. */ |
| 167 // TODO(sigmund): split in multiple classes: global, thread, main-worker states? | 171 // TODO(sigmund): split in multiple classes: global, thread, main-worker states? |
| 168 class _Manager { | 172 class _Manager { |
| 169 | 173 |
| 170 /** Next available isolate id within this [_Manager]. */ | 174 /** Next available isolate id within this [_Manager]. */ |
| 171 int nextIsolateId = 0; | 175 int nextIsolateId = 0; |
| 172 | 176 |
| 173 /** id assigned to this [_Manager]. */ | 177 /** id assigned to this [_Manager]. */ |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 return true; | 645 return true; |
| 642 } | 646 } |
| 643 | 647 |
| 644 /** | 648 /** |
| 645 * Runs multiple iterations of the run-loop. If possible, each iteration is | 649 * Runs multiple iterations of the run-loop. If possible, each iteration is |
| 646 * run asynchronously. | 650 * run asynchronously. |
| 647 */ | 651 */ |
| 648 void _runHelper() { | 652 void _runHelper() { |
| 649 if (globalWindow != null) { | 653 if (globalWindow != null) { |
| 650 // Run each iteration from the browser's top event loop. | 654 // Run each iteration from the browser's top event loop. |
| 651 void next() { | 655 // TODO(vsm): Revert to original pattern. |
| 656 // See: https://github.com/dart-lang/dev_compiler/issues/177 |
| 657 Function next = () { |
| 652 if (!runIteration()) return; | 658 if (!runIteration()) return; |
| 653 Timer.run(next); | 659 Timer.run(next); |
| 654 } | 660 }; |
| 655 next(); | 661 next(); |
| 656 } else { | 662 } else { |
| 657 // Run synchronously until no more iterations are available. | 663 // Run synchronously until no more iterations are available. |
| 658 while (runIteration()) {} | 664 while (runIteration()) {} |
| 659 } | 665 } |
| 660 } | 666 } |
| 661 | 667 |
| 662 /** | 668 /** |
| 663 * Call [_runHelper] but ensure that worker exceptions are propragated. | 669 * Call [_runHelper] but ensure that worker exceptions are propragated. |
| 664 */ | 670 */ |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 static String thisScript = computeThisScript(); | 750 static String thisScript = computeThisScript(); |
| 745 | 751 |
| 746 /// Associates an ID with a native worker object. | 752 /// Associates an ID with a native worker object. |
| 747 static final Expando<int> workerIds = new Expando<int>(); | 753 static final Expando<int> workerIds = new Expando<int>(); |
| 748 | 754 |
| 749 /** | 755 /** |
| 750 * The src url for the script tag that loaded this Used to create | 756 * The src url for the script tag that loaded this Used to create |
| 751 * JavaScript workers. | 757 * JavaScript workers. |
| 752 */ | 758 */ |
| 753 static String computeThisScript() { | 759 static String computeThisScript() { |
| 754 var currentScript = JS_EMBEDDED_GLOBAL('', CURRENT_SCRIPT); | 760 // See: https://github.com/dart-lang/dev_compiler/issues/164 |
| 761 // var currentScript = JS_EMBEDDED_GLOBAL('', CURRENT_SCRIPT); |
| 762 var currentScript = JS('var', 'document.currentScript'); |
| 755 if (currentScript != null) { | 763 if (currentScript != null) { |
| 756 return JS('String', 'String(#.src)', currentScript); | 764 return JS('String', 'String(#.src)', currentScript); |
| 757 } | 765 } |
| 758 if (Primitives.isD8) return computeThisScriptD8(); | 766 if (Primitives.isD8) return computeThisScriptD8(); |
| 759 if (Primitives.isJsshell) return computeThisScriptJsshell(); | 767 if (Primitives.isJsshell) return computeThisScriptJsshell(); |
| 760 // A worker has no script tag - so get an url from a stack-trace. | 768 // A worker has no script tag - so get an url from a stack-trace. |
| 761 if (_globalState.isWorker) return computeThisScriptFromTrace(); | 769 if (_globalState.isWorker) return computeThisScriptFromTrace(); |
| 762 return null; | 770 return null; |
| 763 } | 771 } |
| 764 | 772 |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 } | 1453 } |
| 1446 | 1454 |
| 1447 bool operator==(Object other) { | 1455 bool operator==(Object other) { |
| 1448 if (identical(other, this)) return true; | 1456 if (identical(other, this)) return true; |
| 1449 if (other is CapabilityImpl) { | 1457 if (other is CapabilityImpl) { |
| 1450 return identical(_id, other._id); | 1458 return identical(_id, other._id); |
| 1451 } | 1459 } |
| 1452 return false; | 1460 return false; |
| 1453 } | 1461 } |
| 1454 } | 1462 } |
| OLD | NEW |