| 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 /** Implementation of [Isolate2]. */ | 5 /** Implementation of [Isolate2]. */ |
| 6 class _Isolate2Impl implements Isolate2 { | 6 class _Isolate2Impl implements Isolate2 { |
| 7 SendPort sendPort; | 7 SendPort sendPort; |
| 8 | 8 |
| 9 _Isolate2Impl(this.sendPort); | 9 _Isolate2Impl(this.sendPort); |
| 10 } | 10 } |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 static var _getJSConstructor(Isolate runnable) native """ | 475 static var _getJSConstructor(Isolate runnable) native """ |
| 476 return runnable.constructor; | 476 return runnable.constructor; |
| 477 """; | 477 """; |
| 478 | 478 |
| 479 /** Extract the constructor name of a runnable */ | 479 /** Extract the constructor name of a runnable */ |
| 480 // TODO(sigmund): find a browser-generic way to support this. | 480 // TODO(sigmund): find a browser-generic way to support this. |
| 481 static var _getJSConstructorName(Isolate runnable) native """ | 481 static var _getJSConstructorName(Isolate runnable) native """ |
| 482 return runnable.constructor.name; | 482 return runnable.constructor.name; |
| 483 """; | 483 """; |
| 484 | 484 |
| 485 /** Find a constructor given it's name. */ | 485 /** Find a constructor given its name. */ |
| 486 static var _getJSConstructorFromName(String factoryName) native """ | 486 static var _getJSConstructorFromName(String factoryName) native """ |
| 487 return \$globalThis[factoryName]; | 487 return \$globalThis[factoryName]; |
| 488 """; | 488 """; |
| 489 | 489 |
| 490 static var _getJSFunctionFromName(String functionName) native """ | 490 static var _getJSFunctionFromName(String functionName) native """ |
| 491 return \$globalThis[functionName]; | 491 return \$globalThis[functionName]; |
| 492 """; | 492 """; |
| 493 | 493 |
| 494 static String _getJSFunctionName(Function f) native "return f.name || null;"; | 494 /** |
| 495 * Get a string name for the function, if possible. The result for |
| 496 * anonymous functions is browser-dependent -- it may be "" or "anonymous" |
| 497 * but you should probably not count on this. |
| 498 */ |
| 499 static String _getJSFunctionName(Function f) |
| 500 // Comments on the code, outside of the string so they won't bulk up |
| 501 // the native output: |
| 502 // |
| 503 // Are we in a browser that implements the non-standard but |
| 504 // oh-so-convenient function .name property? If not, parse the name |
| 505 // out of toString(). |
| 506 // |
| 507 // When there is a match, our capture is element 1 of the results list. |
| 508 // If there is no match, match() returns null; we || this to a list |
| 509 // whose element 1 is null so everything lines up without error. |
| 510 // |
| 511 // TODO(eub): remove the toString workaround by attaching names to |
| 512 // functions where they could be needed. For a simple |
| 513 // conservative approximation of "needed", see Siggi's option (c) |
| 514 // in discussion on the CL, 9416119. |
| 515 native @""" |
| 516 if (typeof(f.name) === 'undefined') { |
| 517 return (f.toString().match(/function (.+)\(/) || [, null])[1]; |
| 518 } else { |
| 519 return f.name || null; |
| 520 } |
| 521 """; |
| 495 | 522 |
| 496 /** Create a new JavasSript object instance given it's constructor. */ | 523 /** Create a new JavaScript object instance given its constructor. */ |
| 497 static var _allocate(var ctor) native "return new ctor();"; | 524 static var _allocate(var ctor) native "return new ctor();"; |
| 498 | 525 |
| 499 /** Starts a non-worker isolate. */ | 526 /** Starts a non-worker isolate. */ |
| 500 static SendPort _startNonWorker(Isolate runnable, SendPort replyTo) { | 527 static SendPort _startNonWorker(Isolate runnable, SendPort replyTo) { |
| 501 // Spawn a new isolate and create the receive port in it. | 528 // Spawn a new isolate and create the receive port in it. |
| 502 final spawned = new IsolateContext(); | 529 final spawned = new IsolateContext(); |
| 503 | 530 |
| 504 // Instead of just running the provided runnable, we create a | 531 // Instead of just running the provided runnable, we create a |
| 505 // new cloned instance of it with a fresh state in the spawned | 532 // new cloned instance of it with a fresh state in the spawned |
| 506 // isolate. This way, we do not get cross-isolate references | 533 // isolate. This way, we do not get cross-isolate references |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 'command': 'start2', | 616 'command': 'start2', |
| 590 'id': workerId, | 617 'id': workerId, |
| 591 // Note: we serialize replyPort twice because the child worker needs to | 618 // Note: we serialize replyPort twice because the child worker needs to |
| 592 // first deserialize the worker id, before it can correctly deserialize | 619 // first deserialize the worker id, before it can correctly deserialize |
| 593 // the port (port deserialization is sensitive to what is the current | 620 // the port (port deserialization is sensitive to what is the current |
| 594 // workerId). | 621 // workerId). |
| 595 'replyTo': _serializeMessage(replyPort), | 622 'replyTo': _serializeMessage(replyPort), |
| 596 'functionName': functionName })); | 623 'functionName': functionName })); |
| 597 } | 624 } |
| 598 } | 625 } |
| OLD | NEW |