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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « pkg/dev_compiler/test/browser/language_tests.js ('k') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart._js_mirrors; 5 library dart._js_mirrors;
6 6
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 import 'dart:_foreign_helper' show JS; 8 import 'dart:_foreign_helper' show JS;
9 import 'dart:_internal' as _internal; 9 import 'dart:_internal' as _internal;
10 10
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (typeArgs == null) { 432 if (typeArgs == null) {
433 _typeArguments = const []; 433 _typeArguments = const [];
434 } else { 434 } else {
435 _typeArguments = 435 _typeArguments =
436 new List.unmodifiable(typeArgs.map((t) => reflectType(_wrap(t)))); 436 new List.unmodifiable(typeArgs.map((t) => reflectType(_wrap(t))));
437 } 437 }
438 } 438 }
439 439
440 InstanceMirror newInstance(Symbol constructorName, List args, 440 InstanceMirror newInstance(Symbol constructorName, List args,
441 [Map<Symbol, dynamic> namedArgs]) { 441 [Map<Symbol, dynamic> namedArgs]) {
442 // TODO(vsm): Support factory constructors and named arguments. 442 // TODO(vsm): Support named arguments.
443 var name = getName(constructorName); 443 var name = getName(constructorName);
444 assert(namedArgs == null || namedArgs.isEmpty); 444 assert(namedArgs == null || namedArgs.isEmpty);
445 // Default constructors are mapped to new.
445 if (name == '') name = 'new'; 446 if (name == '') name = 'new';
446 var instance = JS('', 'new (#.#)(...#)', _unwrap(_cls), name, args); 447 var cls = _unwrap(_cls);
448 var ctr = JS('', '#.#', cls, name);
449 // Only generative Dart constructors are wired up as real JS constructors.
450 var instance = JS('bool', '#.prototype == #.prototype', cls, ctr)
451 // Generative
452 ? JS('', 'new #(...#)', ctr, args)
453 // Factory
454 : JS('', '#(...#)', ctr, args);
447 return reflect(instance); 455 return reflect(instance);
448 } 456 }
449 457
450 // TODO(vsm): Need to check for NSM, types on accessors below. Unlike the 458 // TODO(vsm): Need to check for NSM, types on accessors below. Unlike the
451 // InstanceMirror case, there is no dynamic helper to delegate to - we never 459 // InstanceMirror case, there is no dynamic helper to delegate to - we never
452 // need a dload, etc. on a static. 460 // need a dload, etc. on a static.
453 461
454 InstanceMirror getField(Symbol symbol) { 462 InstanceMirror getField(Symbol symbol) {
455 var name = getName(symbol); 463 var name = getName(symbol);
456 return reflect(JS('', '#[#]', _unwrap(_cls), name)); 464 return reflect(JS('', '#[#]', _unwrap(_cls), name));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 var param = 666 var param =
659 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata); 667 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata);
660 params[i + args.length] = param; 668 params[i + args.length] = param;
661 } 669 }
662 670
663 _params = new List.unmodifiable(params); 671 _params = new List.unmodifiable(params);
664 } 672 }
665 673
666 String toString() => "MethodMirror on '$_name'"; 674 String toString() => "MethodMirror on '$_name'";
667 } 675 }
OLDNEW
« 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