| 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 /** | 5 /** |
| 6 * Concepts used here: | 6 * Concepts used here: |
| 7 * | 7 * |
| 8 * "manager" - A manager contains one or more isolates, schedules their | 8 * "manager" - A manager contains one or more isolates, schedules their |
| 9 * execution, and performs other plumbing on their behalf. The isolate | 9 * execution, and performs other plumbing on their behalf. The isolate |
| 10 * present at the creation of the manager is designated as its "root isolate". | 10 * present at the creation of the manager is designated as its "root isolate". |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 static Dynamic _getJSFunctionFromName(String functionName) native """ | 516 static Dynamic _getJSFunctionFromName(String functionName) native """ |
| 517 return \$globalThis[functionName]; | 517 return \$globalThis[functionName]; |
| 518 """; | 518 """; |
| 519 | 519 |
| 520 /** | 520 /** |
| 521 * Get a string name for the function, if possible. The result for | 521 * Get a string name for the function, if possible. The result for |
| 522 * anonymous functions is browser-dependent -- it may be "" or "anonymous" | 522 * anonymous functions is browser-dependent -- it may be "" or "anonymous" |
| 523 * but you should probably not count on this. | 523 * but you should probably not count on this. |
| 524 */ | 524 */ |
| 525 static String _getJSFunctionName(Function f) | 525 static String _getJSFunctionName(Function f) |
| 526 // Comments on the code, outside of the string so they won't bulk up | 526 native @"return f.$name || (void 0);"; |
| 527 // the native output: | |
| 528 // | |
| 529 // Are we in a browser that implements the non-standard but | |
| 530 // oh-so-convenient function .name property? If not, parse the name | |
| 531 // out of toString(). | |
| 532 // | |
| 533 // When there is a match, our capture is element 1 of the results list. | |
| 534 // If there is no match, match() returns null; we || this to a list | |
| 535 // whose element 1 is null so everything lines up without error. | |
| 536 // | |
| 537 // TODO(eub): remove the toString workaround by attaching names to | |
| 538 // functions where they could be needed. For a simple | |
| 539 // conservative approximation of "needed", see Siggi's option (c) | |
| 540 // in discussion on the CL, 9416119. | |
| 541 native @""" | |
| 542 if (typeof(f.name) === 'undefined') { | |
| 543 return (f.toString().match(/function (.+)\(/) || [, (void 0)])[1]; | |
| 544 } else { | |
| 545 return f.name || (void 0); | |
| 546 } | |
| 547 """; | |
| 548 | 527 |
| 549 /** Create a new JavaScript object instance given its constructor. */ | 528 /** Create a new JavaScript object instance given its constructor. */ |
| 550 static Dynamic _allocate(var ctor) native "return new ctor();"; | 529 static Dynamic _allocate(var ctor) native "return new ctor();"; |
| 551 | 530 |
| 552 /** Starts a non-worker isolate. */ | 531 /** Starts a non-worker isolate. */ |
| 553 static SendPort _startNonWorker(Isolate runnable, SendPort replyTo) { | 532 static SendPort _startNonWorker(Isolate runnable, SendPort replyTo) { |
| 554 // Spawn a new isolate and create the receive port in it. | 533 // Spawn a new isolate and create the receive port in it. |
| 555 final spawned = new _IsolateContext(); | 534 final spawned = new _IsolateContext(); |
| 556 | 535 |
| 557 // Instead of just running the provided runnable, we create a | 536 // Instead of just running the provided runnable, we create a |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 'command': 'start2', | 627 'command': 'start2', |
| 649 'id': workerId, | 628 'id': workerId, |
| 650 // Note: we serialize replyPort twice because the child worker needs to | 629 // Note: we serialize replyPort twice because the child worker needs to |
| 651 // first deserialize the worker id, before it can correctly deserialize | 630 // first deserialize the worker id, before it can correctly deserialize |
| 652 // the port (port deserialization is sensitive to what is the current | 631 // the port (port deserialization is sensitive to what is the current |
| 653 // workerId). | 632 // workerId). |
| 654 'replyTo': _serializeMessage(replyPort), | 633 'replyTo': _serializeMessage(replyPort), |
| 655 'functionName': functionName })); | 634 'functionName': functionName })); |
| 656 } | 635 } |
| 657 } | 636 } |
| OLD | NEW |