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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 25741005: Implement ObjectMirror.[] (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix mistake in merge conflict Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_mirrors.dart » ('j') | sdk/lib/mirrors/mirrors.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 import "dart:collection"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 implements IsolateMirror { 152 implements IsolateMirror {
153 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary); 153 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary);
154 154
155 final String debugName; 155 final String debugName;
156 final bool isCurrent = true; 156 final bool isCurrent = true;
157 final LibraryMirror rootLibrary; 157 final LibraryMirror rootLibrary;
158 158
159 String toString() => "IsolateMirror on '$debugName'"; 159 String toString() => "IsolateMirror on '$debugName'";
160 } 160 }
161 161
162 class _InvocationTrampoline implements Function {
163 ObjectMirror _receiver;
164 Symbol _selector;
165 _InvocationTrampoline(this._receiver, this._selector);
166 noSuchMethod(Invocation msg) {
167 if (msg.memberName != #call) return super.noSuchMethod(msg);
168 return _receiver.invoke(_selector,
169 msg.positionalArguments,
170 msg.namedArguments);
171 }
172 }
173
162 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl 174 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl
163 implements ObjectMirror { 175 implements ObjectMirror {
164 _LocalObjectMirrorImpl(this._reflectee); 176 _LocalObjectMirrorImpl(this._reflectee);
165 177
166 final _reflectee; // May be a MirrorReference or an ordinary object. 178 final _reflectee; // May be a MirrorReference or an ordinary object.
167 179
168 InstanceMirror invoke(Symbol memberName, 180 InstanceMirror invoke(Symbol memberName,
169 List positionalArguments, 181 List positionalArguments,
170 [Map<Symbol, dynamic> namedArguments]) { 182 [Map<Symbol, dynamic> namedArguments]) {
171 183
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 return other is _LocalInstanceMirrorImpl && 312 return other is _LocalInstanceMirrorImpl &&
301 identical(_reflectee, other._reflectee); 313 identical(_reflectee, other._reflectee);
302 } 314 }
303 315
304 int get hashCode { 316 int get hashCode {
305 // Avoid hash collisions with the reflectee. This constant is in Smi range 317 // Avoid hash collisions with the reflectee. This constant is in Smi range
306 // and happens to be the inner padding from RFC 2104. 318 // and happens to be the inner padding from RFC 2104.
307 return identityHashCode(_reflectee) ^ 0x36363636; 319 return identityHashCode(_reflectee) ^ 0x36363636;
308 } 320 }
309 321
322 Function operator [](Symbol selector) {
323 bool found = false;
324 for (ClassMirror c = type; c != null; c = c.superclass) {
325 var target = c.methods[selector];
326 if (target != null && !target.isStatic) {
327 found = true;
328 break;
329 }
330 }
331 if (!found) return null;
332 return new _InvocationTrampoline(this, selector);
333 }
334
310 // Override to include the receiver in the arguments. 335 // Override to include the receiver in the arguments.
311 InstanceMirror invoke(Symbol memberName, 336 InstanceMirror invoke(Symbol memberName,
312 List positionalArguments, 337 List positionalArguments,
313 [Map<Symbol, dynamic> namedArguments]) { 338 [Map<Symbol, dynamic> namedArguments]) {
314 int numPositionalArguments = positionalArguments.length + 1; // Receiver. 339 int numPositionalArguments = positionalArguments.length + 1; // Receiver.
315 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 340 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
316 int numArguments = numPositionalArguments + numNamedArguments; 341 int numArguments = numPositionalArguments + numNamedArguments;
317 List arguments = new List(numArguments); 342 List arguments = new List(numArguments);
318 arguments[0] = _reflectee; // Receiver. 343 arguments[0] = _reflectee; // Receiver.
319 arguments.setRange(1, numPositionalArguments, positionalArguments); 344 arguments.setRange(1, numPositionalArguments, positionalArguments);
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 ClassMirror get originalDeclaration { 654 ClassMirror get originalDeclaration {
630 if (isOriginalDeclaration) { 655 if (isOriginalDeclaration) {
631 return this; 656 return this;
632 } else { 657 } else {
633 return reflectClass(_reflectedType); 658 return reflectClass(_reflectedType);
634 } 659 }
635 } 660 }
636 661
637 String toString() => "ClassMirror on '${_n(simpleName)}'"; 662 String toString() => "ClassMirror on '${_n(simpleName)}'";
638 663
664 Function operator [](Symbol selector) {
665 var target = methods[selector];
666 if (target == null || !target.isStatic) return null;
667 return new _InvocationTrampoline(this, selector);
668 }
669
639 InstanceMirror newInstance(Symbol constructorName, 670 InstanceMirror newInstance(Symbol constructorName,
640 List positionalArguments, 671 List positionalArguments,
641 [Map<Symbol, dynamic> namedArguments]) { 672 [Map<Symbol, dynamic> namedArguments]) {
642 // Native code will add the 1 or 2 implicit arguments depending on whether 673 // Native code will add the 1 or 2 implicit arguments depending on whether
643 // we end up invoking a factory or constructor respectively. 674 // we end up invoking a factory or constructor respectively.
644 int numPositionalArguments = positionalArguments.length; 675 int numPositionalArguments = positionalArguments.length;
645 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 676 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
646 int numArguments = numPositionalArguments + numNamedArguments; 677 int numArguments = numPositionalArguments + numNamedArguments;
647 List arguments = new List(numArguments); 678 List arguments = new List(numArguments);
648 arguments.setRange(0, numPositionalArguments, positionalArguments); 679 arguments.setRange(0, numPositionalArguments, positionalArguments);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 1016
986 bool operator ==(other) { 1017 bool operator ==(other) {
987 return this.runtimeType == other.runtimeType && 1018 return this.runtimeType == other.runtimeType &&
988 this._reflectee == other._reflectee; 1019 this._reflectee == other._reflectee;
989 } 1020 }
990 1021
991 int get hashCode => simpleName.hashCode; 1022 int get hashCode => simpleName.hashCode;
992 1023
993 String toString() => "LibraryMirror on '${_n(simpleName)}'"; 1024 String toString() => "LibraryMirror on '${_n(simpleName)}'";
994 1025
1026 Function operator [](Symbol selector) {
1027 if (!functions.containsKey(selector)) return null;
1028 return new _InvocationTrampoline(this, selector);
1029 }
1030
995 _invoke(reflectee, memberName, arguments, argumentNames) 1031 _invoke(reflectee, memberName, arguments, argumentNames)
996 native 'LibraryMirror_invoke'; 1032 native 'LibraryMirror_invoke';
997 1033
998 _invokeGetter(reflectee, getterName) 1034 _invokeGetter(reflectee, getterName)
999 native 'LibraryMirror_invokeGetter'; 1035 native 'LibraryMirror_invokeGetter';
1000 1036
1001 _invokeSetter(reflectee, setterName, value) 1037 _invokeSetter(reflectee, setterName, value)
1002 native 'LibraryMirror_invokeSetter'; 1038 native 'LibraryMirror_invokeSetter';
1003 1039
1004 _computeMembers(reflectee) 1040 _computeMembers(reflectee)
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 if (typeMirror == null) { 1357 if (typeMirror == null) {
1322 typeMirror = makeLocalTypeMirror(key); 1358 typeMirror = makeLocalTypeMirror(key);
1323 _instanitationCache[key] = typeMirror; 1359 _instanitationCache[key] = typeMirror;
1324 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1360 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1325 _declarationCache[key] = typeMirror; 1361 _declarationCache[key] = typeMirror;
1326 } 1362 }
1327 } 1363 }
1328 return typeMirror; 1364 return typeMirror;
1329 } 1365 }
1330 } 1366 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_mirrors.dart » ('j') | sdk/lib/mirrors/mirrors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698