| OLD | NEW |
| 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 Loading... |
| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // successive invocations. | 322 // successive invocations. |
| 311 var h = _reflectee is num ? _reflectee.hashCode : _identityHash(_reflectee); | 323 var h = _reflectee is num ? _reflectee.hashCode : _identityHash(_reflectee); |
| 312 // Avoid hash collisions with the reflectee. This constant is in Smi range | 324 // Avoid hash collisions with the reflectee. This constant is in Smi range |
| 313 // and happens to be the inner padding from RFC 2104. | 325 // and happens to be the inner padding from RFC 2104. |
| 314 return h ^ 0x36363636; | 326 return h ^ 0x36363636; |
| 315 } | 327 } |
| 316 | 328 |
| 317 static _identityHash(reflectee) | 329 static _identityHash(reflectee) |
| 318 native "InstanceMirror_identityHash"; | 330 native "InstanceMirror_identityHash"; |
| 319 | 331 |
| 332 Function operator [](Symbol selector) { |
| 333 bool found = false; |
| 334 for (ClassMirror c = type; c != null; c = c.superclass) { |
| 335 var target = c.methods[selector]; |
| 336 if (target != null && !target.isStatic) { |
| 337 found = true; |
| 338 break; |
| 339 } |
| 340 } |
| 341 if (!found) return null; |
| 342 return new _InvocationTrampoline(this, selector); |
| 343 } |
| 344 |
| 320 // Override to include the receiver in the arguments. | 345 // Override to include the receiver in the arguments. |
| 321 InstanceMirror invoke(Symbol memberName, | 346 InstanceMirror invoke(Symbol memberName, |
| 322 List positionalArguments, | 347 List positionalArguments, |
| 323 [Map<Symbol, dynamic> namedArguments]) { | 348 [Map<Symbol, dynamic> namedArguments]) { |
| 324 int numPositionalArguments = positionalArguments.length + 1; // Receiver. | 349 int numPositionalArguments = positionalArguments.length + 1; // Receiver. |
| 325 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 350 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
| 326 int numArguments = numPositionalArguments + numNamedArguments; | 351 int numArguments = numPositionalArguments + numNamedArguments; |
| 327 List arguments = new List(numArguments); | 352 List arguments = new List(numArguments); |
| 328 arguments[0] = _reflectee; // Receiver. | 353 arguments[0] = _reflectee; // Receiver. |
| 329 arguments.setRange(1, numPositionalArguments, positionalArguments); | 354 arguments.setRange(1, numPositionalArguments, positionalArguments); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 ClassMirror get originalDeclaration { | 664 ClassMirror get originalDeclaration { |
| 640 if (isOriginalDeclaration) { | 665 if (isOriginalDeclaration) { |
| 641 return this; | 666 return this; |
| 642 } else { | 667 } else { |
| 643 return reflectClass(_reflectedType); | 668 return reflectClass(_reflectedType); |
| 644 } | 669 } |
| 645 } | 670 } |
| 646 | 671 |
| 647 String toString() => "ClassMirror on '${_n(simpleName)}'"; | 672 String toString() => "ClassMirror on '${_n(simpleName)}'"; |
| 648 | 673 |
| 674 Function operator [](Symbol selector) { |
| 675 var target = methods[selector]; |
| 676 if (target == null || !target.isStatic) return null; |
| 677 return new _InvocationTrampoline(this, selector); |
| 678 } |
| 679 |
| 649 InstanceMirror newInstance(Symbol constructorName, | 680 InstanceMirror newInstance(Symbol constructorName, |
| 650 List positionalArguments, | 681 List positionalArguments, |
| 651 [Map<Symbol, dynamic> namedArguments]) { | 682 [Map<Symbol, dynamic> namedArguments]) { |
| 652 // Native code will add the 1 or 2 implicit arguments depending on whether | 683 // Native code will add the 1 or 2 implicit arguments depending on whether |
| 653 // we end up invoking a factory or constructor respectively. | 684 // we end up invoking a factory or constructor respectively. |
| 654 int numPositionalArguments = positionalArguments.length; | 685 int numPositionalArguments = positionalArguments.length; |
| 655 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 686 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
| 656 int numArguments = numPositionalArguments + numNamedArguments; | 687 int numArguments = numPositionalArguments + numNamedArguments; |
| 657 List arguments = new List(numArguments); | 688 List arguments = new List(numArguments); |
| 658 arguments.setRange(0, numPositionalArguments, positionalArguments); | 689 arguments.setRange(0, numPositionalArguments, positionalArguments); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1026 |
| 996 bool operator ==(other) { | 1027 bool operator ==(other) { |
| 997 return this.runtimeType == other.runtimeType && | 1028 return this.runtimeType == other.runtimeType && |
| 998 this._reflectee == other._reflectee; | 1029 this._reflectee == other._reflectee; |
| 999 } | 1030 } |
| 1000 | 1031 |
| 1001 int get hashCode => simpleName.hashCode; | 1032 int get hashCode => simpleName.hashCode; |
| 1002 | 1033 |
| 1003 String toString() => "LibraryMirror on '${_n(simpleName)}'"; | 1034 String toString() => "LibraryMirror on '${_n(simpleName)}'"; |
| 1004 | 1035 |
| 1036 Function operator [](Symbol selector) { |
| 1037 if (!functions.containsKey(selector)) return null; |
| 1038 return new _InvocationTrampoline(this, selector); |
| 1039 } |
| 1040 |
| 1005 _invoke(reflectee, memberName, arguments, argumentNames) | 1041 _invoke(reflectee, memberName, arguments, argumentNames) |
| 1006 native 'LibraryMirror_invoke'; | 1042 native 'LibraryMirror_invoke'; |
| 1007 | 1043 |
| 1008 _invokeGetter(reflectee, getterName) | 1044 _invokeGetter(reflectee, getterName) |
| 1009 native 'LibraryMirror_invokeGetter'; | 1045 native 'LibraryMirror_invokeGetter'; |
| 1010 | 1046 |
| 1011 _invokeSetter(reflectee, setterName, value) | 1047 _invokeSetter(reflectee, setterName, value) |
| 1012 native 'LibraryMirror_invokeSetter'; | 1048 native 'LibraryMirror_invokeSetter'; |
| 1013 | 1049 |
| 1014 _computeMembers(reflectee) | 1050 _computeMembers(reflectee) |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 if (typeMirror == null) { | 1367 if (typeMirror == null) { |
| 1332 typeMirror = makeLocalTypeMirror(key); | 1368 typeMirror = makeLocalTypeMirror(key); |
| 1333 _instanitationCache[key] = typeMirror; | 1369 _instanitationCache[key] = typeMirror; |
| 1334 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1370 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1335 _declarationCache[key] = typeMirror; | 1371 _declarationCache[key] = typeMirror; |
| 1336 } | 1372 } |
| 1337 } | 1373 } |
| 1338 return typeMirror; | 1374 return typeMirror; |
| 1339 } | 1375 } |
| 1340 } | 1376 } |
| OLD | NEW |