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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart

Issue 2976133002: Support ClassMirror.newInstance on factory constructors (Closed)
Patch Set: Created 3 years, 5 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 | « pkg/dev_compiler/test/browser/language_tests.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
index f269881e051da2223274261f5330c44b738be676..1a6f26d8ac84d07897f405f94d7fd501c3b465ef 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
@@ -439,11 +439,19 @@ class JsClassMirror extends JsMirror implements ClassMirror {
InstanceMirror newInstance(Symbol constructorName, List args,
[Map<Symbol, dynamic> namedArgs]) {
- // TODO(vsm): Support factory constructors and named arguments.
+ // TODO(vsm): Support named arguments.
var name = getName(constructorName);
assert(namedArgs == null || namedArgs.isEmpty);
+ // Default constructors are mapped to new.
if (name == '') name = 'new';
- var instance = JS('', 'new (#.#)(...#)', _unwrap(_cls), name, args);
+ var cls = _unwrap(_cls);
+ var ctr = JS('', '#.#', cls, name);
+ // Only generative Dart constructors are wired up as real JS constructors.
+ var instance = JS('bool', '#.prototype == #.prototype', cls, ctr)
+ // Generative
+ ? JS('', 'new #(...#)', ctr, args)
+ // Factory
+ : JS('', '#(...#)', ctr, args);
return reflect(instance);
}
« no previous file with comments | « pkg/dev_compiler/test/browser/language_tests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698