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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 1213033002: Fix runtimeType.toString for tear-offs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
Index: sdk/lib/_internal/compiler/js_lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index 4270ab576d2e43084f28ac99258d89c433f6be9a..a0d51201a6a76c145e1d220881fa10b18bd80007 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -2284,11 +2284,14 @@ abstract class Closure implements Function {
// Object.create to create the desired prototype.
//
// TODO(sra): Perhaps cache the prototype to avoid the allocation.
- var prototype = isStatic
- ? JS('StaticClosure', 'Object.create(#.constructor.prototype)',
- new StaticClosure())
- : JS('BoundClosure', 'Object.create(#.constructor.prototype)',
- new BoundClosure(null, null, null, null));
+ TearOffClosure dummyObject = isStatic
+ ? new StaticClosure()
+ : new BoundClosure(null, null, null, null);
+
+ var prototype = JS(
+ 'TearOffClosure',
+ 'Object.create(#.constructor.prototype)',
+ dummyObject);
JS('', '#.\$initialize = #', prototype, JS('', '#.constructor', prototype));
var constructor = isStatic
@@ -2301,7 +2304,23 @@ abstract class Closure implements Function {
// It is necessary to set the constructor property, otherwise it will be
// "Object".
- JS('', '#.constructor = #', prototype, constructor);
+ // We want the constructor.name property to have the name of the
+ // StaticClosure or BoundClosure class.
+ // Most browsers (except IE10) don't allow to change the name of a function
+ // as such we can't just set the property. However, we can work around this
+ // by creating an empty object with the name property set to the correct
+ // value and then setting the prototype to the original constructor.
+ // This works for all browsers except IE10 which doesn't have a way to
+ // change the prototype. There we simply set the name.
+ if (JS('bool', 'typeof Object.setPrototypeOf != "undefined"')) {
+ String tearOffClassName = JS('String', '#.constructor.name', dummyObject);
+ JS('', '#.constructor = {name: #}', prototype, tearOffClassName);
+ JS('', 'Object.setPrototypeOf(#.constructor, #)', prototype, constructor);
+ } else {
+ // IE10.
+ JS('', '#.constructor = #', prototype, constructor);
+ JS('', '#.constructor.name = #', prototype, propertyName);
+ }
JS('', '#.prototype = #', constructor, prototype);

Powered by Google App Engine
This is Rietveld 408576698