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

Unified Diff: lib/isolate/frog/isolateimpl.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/isolate/frog/isolateimpl.dart
===================================================================
--- lib/isolate/frog/isolateimpl.dart (revision 4647)
+++ lib/isolate/frog/isolateimpl.dart (working copy)
@@ -482,7 +482,7 @@
return runnable.constructor.name;
""";
- /** Find a constructor given it's name. */
+ /** Find a constructor given its name. */
static var _getJSConstructorFromName(String factoryName) native """
return \$globalThis[factoryName];
""";
@@ -491,9 +491,36 @@
return \$globalThis[functionName];
""";
- static String _getJSFunctionName(Function f) native "return f.name || null;";
+ /**
+ * Get a string name for the function, if possible. The result for
+ * anonymous functions is browser-dependent -- it may be "" or "anonymous"
+ * but you should probably not count on this.
+ */
+ static String _getJSFunctionName(Function f)
+ // Comments on the code, outside of the string so they won't bulk up
+ // the native output:
+ //
+ // Are we in a browser that implements the non-standard but
+ // oh-so-convenient function .name property? If not, parse the name
+ // out of toString().
+ //
+ // When there is a match, our capture is element 1 of the results list.
+ // If there is no match, match() returns null; we || this to a list
+ // whose element 1 is null so everything lines up without error.
+ //
+ // TODO(eub): remove the toString workaround by attaching names to
+ // functions where they could be needed. For a simple
+ // conservative approximation of "needed", see Siggi's option (c)
+ // in discussion on the CL, 9416119.
+ native @"""
+ if (typeof(f.name) === 'undefined') {
+ return (f.toString().match(/function (.+)\(/) || [, null])[1];
+ } else {
+ return f.name || null;
+ }
+ """;
- /** Create a new JavasSript object instance given it's constructor. */
+ /** Create a new JavaScript object instance given its constructor. */
static var _allocate(var ctor) native "return new ctor();";
/** Starts a non-worker isolate. */
« 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