| 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 convertDartClosureToJS, | 10 import 'dart:_js_helper' show convertDartClosureToJS, |
| 11 Null; | 11 Null; |
| 12 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, | 12 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, |
| 13 JS, | 13 JS, |
| 14 JS_CREATE_ISOLATE, | 14 JS_CREATE_ISOLATE, |
| 15 JS_CURRENT_ISOLATE_CONTEXT, |
| 15 JS_CURRENT_ISOLATE, | 16 JS_CURRENT_ISOLATE, |
| 16 JS_SET_CURRENT_ISOLATE, | 17 JS_SET_CURRENT_ISOLATE, |
| 17 IsolateContext; | 18 IsolateContext; |
| 18 | 19 |
| 19 ReceivePort lazyPort; | 20 ReceivePort lazyPort; |
| 20 | 21 |
| 21 class CloseToken { | 22 class CloseToken { |
| 22 /// This token is sent from [IsolateSink]s to [IsolateStream]s to ask them to | 23 /// This token is sent from [IsolateSink]s to [IsolateStream]s to ask them to |
| 23 /// close themselves. | 24 /// close themselves. |
| 24 const CloseToken(); | 25 const CloseToken(); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 static String thisScript = computeThisScript(); | 419 static String thisScript = computeThisScript(); |
| 419 | 420 |
| 420 /// Associates an ID with a native worker object. | 421 /// Associates an ID with a native worker object. |
| 421 static final Expando<int> workerIds = new Expando<int>(); | 422 static final Expando<int> workerIds = new Expando<int>(); |
| 422 | 423 |
| 423 /** | 424 /** |
| 424 * The src url for the script tag that loaded this code. Used to create | 425 * The src url for the script tag that loaded this code. Used to create |
| 425 * JavaScript workers. | 426 * JavaScript workers. |
| 426 */ | 427 */ |
| 427 static String computeThisScript() { | 428 static String computeThisScript() { |
| 428 var currentScript = JS('', r'$.$currentScript'); | 429 var currentScript = JS('', r'#.$currentScript', JS_CURRENT_ISOLATE()); |
| 429 if (currentScript != null) { | 430 if (currentScript != null) { |
| 430 return JS('String', 'String(#.src)', currentScript); | 431 return JS('String', 'String(#.src)', currentScript); |
| 431 } | 432 } |
| 432 | 433 |
| 433 // TODO(ahe): The following is for supporting command-line engines | 434 // TODO(ahe): The following is for supporting command-line engines |
| 434 // such as d8 and jsshell. We should move this code to a helper | 435 // such as d8 and jsshell. We should move this code to a helper |
| 435 // library that is only loaded when testing on those engines. | 436 // library that is only loaded when testing on those engines. |
| 436 | 437 |
| 437 var stack = JS('String|Null', 'new Error().stack'); | 438 var stack = JS('String|Null', 'new Error().stack'); |
| 438 if (stack == null) { | 439 if (stack == null) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 549 } |
| 549 } | 550 } |
| 550 } | 551 } |
| 551 | 552 |
| 552 static void _consoleLog(msg) { | 553 static void _consoleLog(msg) { |
| 553 JS("void", r"#.console.log(#)", globalThis, msg); | 554 JS("void", r"#.console.log(#)", globalThis, msg); |
| 554 } | 555 } |
| 555 | 556 |
| 556 /** Find a constructor given its name. */ | 557 /** Find a constructor given its name. */ |
| 557 static dynamic _getJSConstructorFromName(String factoryName) { | 558 static dynamic _getJSConstructorFromName(String factoryName) { |
| 558 return JS("", r"$[#]", factoryName); | 559 return JS("", "#[#]", JS_CURRENT_ISOLATE(), factoryName); |
| 559 } | 560 } |
| 560 | 561 |
| 561 static dynamic _getJSFunctionFromName(String functionName) { | 562 static dynamic _getJSFunctionFromName(String functionName) { |
| 562 return JS("", r"$[#]", functionName); | 563 return JS("", "#[#]", JS_CURRENT_ISOLATE(), functionName); |
| 563 } | 564 } |
| 564 | 565 |
| 565 /** | 566 /** |
| 566 * Get a string name for the function, if possible. The result for | 567 * Get a string name for the function, if possible. The result for |
| 567 * anonymous functions is browser-dependent -- it may be "" or "anonymous" | 568 * anonymous functions is browser-dependent -- it may be "" or "anonymous" |
| 568 * but you should probably not count on this. | 569 * but you should probably not count on this. |
| 569 */ | 570 */ |
| 570 static String _getJSFunctionName(Function f) { | 571 static String _getJSFunctionName(Function f) { |
| 571 return JS("String|Null", r"(#['$name'] || #)", f, null); | 572 return JS("String|Null", r"(#['$name'] || #)", f, null); |
| 572 } | 573 } |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 JS('void', '#.clearInterval(#)', globalThis, _handle); | 1411 JS('void', '#.clearInterval(#)', globalThis, _handle); |
| 1411 } | 1412 } |
| 1412 _handle = null; | 1413 _handle = null; |
| 1413 } else { | 1414 } else { |
| 1414 throw new UnsupportedError("Canceling a timer."); | 1415 throw new UnsupportedError("Canceling a timer."); |
| 1415 } | 1416 } |
| 1416 } | 1417 } |
| 1417 } | 1418 } |
| 1418 | 1419 |
| 1419 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; | 1420 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; |
| OLD | NEW |