Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: frog/lib/isolate.dart

Issue 9416119: Add some magic to _getJSFunctionName so it will work in Internet Explorer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * A native object that is shared across isolates. This object is visible to all 6 * A native object that is shared across isolates. This object is visible to all
7 * isolates running on the same worker (either UI or background web worker). 7 * isolates running on the same worker (either UI or background web worker).
8 * 8 *
9 * This is code that is intended to 'escape' the isolate boundaries in order to 9 * This is code that is intended to 'escape' the isolate boundaries in order to
10 * implement the semantics of friendly isolates in JavaScript. Without this we 10 * implement the semantics of friendly isolates in JavaScript. Without this we
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 static var _getJSConstructor(Isolate runnable) native """ 750 static var _getJSConstructor(Isolate runnable) native """
751 return runnable.constructor; 751 return runnable.constructor;
752 """; 752 """;
753 753
754 /** Extract the constructor name of a runnable */ 754 /** Extract the constructor name of a runnable */
755 // TODO(sigmund): find a browser-generic way to support this. 755 // TODO(sigmund): find a browser-generic way to support this.
756 static var _getJSConstructorName(Isolate runnable) native """ 756 static var _getJSConstructorName(Isolate runnable) native """
757 return runnable.constructor.name; 757 return runnable.constructor.name;
758 """; 758 """;
759 759
760 /** Find a constructor given it's name. */ 760 /** Find a constructor given its name. */
Siggi Cherem (dart-lang) 2012/02/22 23:46:49 thx :)
761 static var _getJSConstructorFromName(String factoryName) native """ 761 static var _getJSConstructorFromName(String factoryName) native """
762 return \$globalThis[factoryName]; 762 return \$globalThis[factoryName];
763 """; 763 """;
764 764
765 static var _getJSFunctionFromName(String functionName) native """ 765 static var _getJSFunctionFromName(String functionName) native """
766 return \$globalThis[functionName]; 766 return \$globalThis[functionName];
767 """; 767 """;
768 768
769 static String _getJSFunctionName(Function f) native "return f.name || null;"; 769 /** Get a string name for the function, if possible. The result for
Siggi Cherem (dart-lang) 2012/02/22 23:46:49 (nit) style of the comment block: if it's multilin
eub 2012/02/23 00:00:12 Done.
770 * anonymous functions is browser-dependent -- it may be "" or "anonymous"
771 * but you should probably not count on this. */
772 static String _getJSFunctionName(Function f) native """
kasperl 2012/02/23 06:53:35 Can't we simplify this whole thing by not using .n
Siggi Cherem (dart-lang) 2012/02/23 17:13:23 Yes, we debated a bit about this, and were afraid
kasperl 2012/02/27 11:28:24 Option (c) sounds good to me. That should be even
773 // Are we in a browser that implements the non-standard but
774 // oh-so-convenient function .name property?
Siggi Cherem (dart-lang) 2012/02/22 23:46:49 some of these comments are useful, but note that c
eub 2012/02/23 00:00:12 Removed a little chatter, and moved the implementa
775 if (typeof(f.name) === 'undefined') {
776 // No. Parse the name out of toString()!
777 //
778 // When there is a match, our capture is element 1 of the results list.
779 // If there is no match, match() returns null; we || this to a list
780 // whose element 1 is null so everything lines up without error.
781 // (Double-backslash in this string gives a backslash in the native JS.)
782 return (f.toString().match(/function (.+)\\(/) || [, null])[1];
783 } else {
784 // Yes. Use .name property.
785 return f.name || null;
786 }
787 """;
770 788
771 /** Create a new JavasSript object instance given it's constructor. */ 789 /** Create a new JavasSript object instance given it's constructor. */
772 static var _allocate(var ctor) native "return new ctor();"; 790 static var _allocate(var ctor) native "return new ctor();";
773 791
774 /** Starts a non-worker isolate. */ 792 /** Starts a non-worker isolate. */
775 static SendPort _startNonWorker(Isolate runnable, SendPort replyTo) { 793 static SendPort _startNonWorker(Isolate runnable, SendPort replyTo) {
776 // Spawn a new isolate and create the receive port in it. 794 // Spawn a new isolate and create the receive port in it.
777 final spawned = new IsolateContext(); 795 final spawned = new IsolateContext();
778 796
779 // Instead of just running the provided runnable, we create a 797 // Instead of just running the provided runnable, we create a
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 throw new UnsupportedOperationException( 906 throw new UnsupportedOperationException(
889 "only top-level functions can be spawned."); 907 "only top-level functions can be spawned.");
890 } 908 }
891 return new Isolate2Impl(IsolateNatives._spawn2(name, null, false)); 909 return new Isolate2Impl(IsolateNatives._spawn2(name, null, false));
892 } 910 }
893 911
894 factory Isolate2.fromUri(String uri) { 912 factory Isolate2.fromUri(String uri) {
895 return new Isolate2Impl(IsolateNatives._spawn2(null, uri, false)); 913 return new Isolate2Impl(IsolateNatives._spawn2(null, uri, false));
896 } 914 }
897 } 915 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698