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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart

Issue 2852723002: dart:mirrors workaround for generic methods (Closed)
Patch Set: Created 3 years, 7 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
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 dynamic _defaultConstructorType(type) { 76 dynamic _defaultConstructorType(type) {
77 return JS('', '#.definiteFunctionType(#, [])', _dart, type); 77 return JS('', '#.definiteFunctionType(#, [])', _dart, type);
78 } 78 }
79 79
80 dynamic _getMixins(type) { 80 dynamic _getMixins(type) {
81 return JS('', '#.getMixins(#, [])', _dart, type); 81 return JS('', '#.getMixins(#, [])', _dart, type);
82 } 82 }
83 83
84 dynamic _getFunctionType(type) {
85 return JS('', '#.getFunctionTypeMirror(#)', _dart, type);
86 }
87
84 typedef T _Lazy<T>(); 88 typedef T _Lazy<T>();
85 89
86 dynamic _getESSymbol(Symbol symbol) => 90 dynamic _getESSymbol(Symbol symbol) =>
87 _internal.PrivateSymbol.getNativeSymbol(symbol); 91 _internal.PrivateSymbol.getNativeSymbol(symbol);
88 92
89 dynamic _getMember(Symbol symbol) { 93 dynamic _getMember(Symbol symbol) {
90 var privateSymbol = _getESSymbol(symbol); 94 var privateSymbol = _getESSymbol(symbol);
91 if (privateSymbol != null) { 95 if (privateSymbol != null) {
92 return privateSymbol; 96 return privateSymbol;
93 } 97 }
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 // Record metadata 624 // Record metadata
621 _metadata = new List<InstanceMirror>.unmodifiable( 625 _metadata = new List<InstanceMirror>.unmodifiable(
622 ftype.skip(1).map((a) => reflect(a))); 626 ftype.skip(1).map((a) => reflect(a)));
623 ftype = ftype[0]; 627 ftype = ftype[0];
624 } else { 628 } else {
625 _metadata = const []; 629 _metadata = const [];
626 } 630 }
627 631
628 // TODO(vsm): Handle generic function types properly. Or deprecate mirrors 632 // TODO(vsm): Handle generic function types properly. Or deprecate mirrors
629 // before we need to! 633 // before we need to!
630 if (JS('bool', 'typeof(#) == "function"', ftype)) { 634 ftype = _getFunctionType(ftype);
631 // Instantiate the generic version.
632 // TODO(vsm): Can't use arguments.length on arrow function.
633 ftype = JS('', '#.apply(null, #)', ftype, [dynamic, dynamic, dynamic]);
634 }
635 635
636 // TODO(vsm): Add named args. 636 // TODO(vsm): Add named args.
637 List args = ftype.args; 637 List args = ftype.args;
638 List opts = ftype.optionals; 638 List opts = ftype.optionals;
639 var params = new List<ParameterMirror>(args.length + opts.length); 639 var params = new List<ParameterMirror>(args.length + opts.length);
640 640
641 for (var i = 0; i < args.length; ++i) { 641 for (var i = 0; i < args.length; ++i) {
642 var type = args[i]; 642 var type = args[i];
643 var metadata = ftype.metadata[i]; 643 var metadata = ftype.metadata[i];
644 // TODO(vsm): Recover the param name. 644 // TODO(vsm): Recover the param name.
645 var param = 645 var param =
646 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata); 646 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata);
647 params[i] = param; 647 params[i] = param;
648 } 648 }
649 649
650 for (var i = 0; i < opts.length; ++i) { 650 for (var i = 0; i < opts.length; ++i) {
651 var type = opts[i]; 651 var type = opts[i];
652 var metadata = ftype.metadata[args.length + i]; 652 var metadata = ftype.metadata[args.length + i];
653 // TODO(vsm): Recover the param name. 653 // TODO(vsm): Recover the param name.
654 var param = 654 var param =
655 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata); 655 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata);
656 params[i + args.length] = param; 656 params[i + args.length] = param;
657 } 657 }
658 658
659 _params = new List.unmodifiable(params); 659 _params = new List.unmodifiable(params);
660 } 660 }
661 661
662 String toString() => "MethodMirror on '$_name'"; 662 String toString() => "MethodMirror on '$_name'";
663 } 663 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart ('k') | tests/lib_strong/mirrors/generic_method_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698