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

Side by Side Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 25741005: Implement ObjectMirror.[] (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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:async'; 7 import 'dart:async';
8 import 'dart:collection' show UnmodifiableListView; 8 import 'dart:collection' show UnmodifiableListView;
9 import 'dart:mirrors'; 9 import 'dart:mirrors';
10 10
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 414
415 List<InstanceMirror> get metadata { 415 List<InstanceMirror> get metadata {
416 if (_cachedMetadata != null) return _cachedMetadata; 416 if (_cachedMetadata != null) return _cachedMetadata;
417 preserveMetadata(); 417 preserveMetadata();
418 return _cachedMetadata = 418 return _cachedMetadata =
419 new UnmodifiableListView<InstanceMirror>(_metadata.map(reflect)); 419 new UnmodifiableListView<InstanceMirror>(_metadata.map(reflect));
420 } 420 }
421 421
422 // TODO(ahe): Test this getter. 422 // TODO(ahe): Test this getter.
423 DeclarationMirror get owner => null; 423 DeclarationMirror get owner => null;
424
425 Function operator [](Symbol selector) {
426 if (!functions.containsKey(selector)) return null;
427 return new _InvocationTrampoline(this, selector);
428 }
424 } 429 }
425 430
426 String n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 431 String n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
427 432
428 Symbol s(String name) { 433 Symbol s(String name) {
429 if (name == null) return null; 434 if (name == null) return null;
430 return new _symbol_dev.Symbol.unvalidated(name); 435 return new _symbol_dev.Symbol.unvalidated(name);
431 } 436 }
432 437
433 Symbol setterSymbol(Symbol symbol) => s("${n(symbol)}="); 438 Symbol setterSymbol(Symbol symbol) => s("${n(symbol)}=");
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 ClassMirror get originalDeclaration => this; 618 ClassMirror get originalDeclaration => this;
614 619
615 // TODO(ahe): Implement this. 620 // TODO(ahe): Implement this.
616 List<TypeVariableMirror> get typeVariables { 621 List<TypeVariableMirror> get typeVariables {
617 throw new UnimplementedError(); 622 throw new UnimplementedError();
618 } 623 }
619 624
620 List<TypeMirror> get typeArguments => new List(); 625 List<TypeMirror> get typeArguments => new List();
621 } 626 }
622 627
628 // TODO(13766): Implement Function.
629 class _InvocationTrampoline /*implements Function*/ {
630 ObjectMirror _receiver;
631 Symbol _selector;
632 _InvocationTrampoline(this._receiver, this._selector);
633 noSuchMethod(Invocation msg) {
ahe 2013/10/03 07:26:35 In no way can we use "noSuchMethod" in implementat
634 if (msg.memberName != #call) return super.noSuchMethod(msg);
635 return _receiver.invoke(_selector,
636 msg.positionalArguments,
637 msg.namedArguments);
638 }
639 }
640
623 abstract class JsObjectMirror implements ObjectMirror { 641 abstract class JsObjectMirror implements ObjectMirror {
624 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value) { 642 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value) {
625 return new Future<InstanceMirror>(() => this.setField(fieldName, value)); 643 return new Future<InstanceMirror>(() => this.setField(fieldName, value));
626 } 644 }
627 645
628 Future<InstanceMirror> getFieldAsync(Symbol fieldName) { 646 Future<InstanceMirror> getFieldAsync(Symbol fieldName) {
629 return new Future<InstanceMirror>(() => this.getField(fieldName)); 647 return new Future<InstanceMirror>(() => this.getField(fieldName));
630 } 648 }
631 649
632 Future<InstanceMirror> invokeAsync(Symbol memberName, 650 Future<InstanceMirror> invokeAsync(Symbol memberName,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 786
769 InstanceMirror getField(Symbol fieldName) { 787 InstanceMirror getField(Symbol fieldName) {
770 String reflectiveName = n(fieldName); 788 String reflectiveName = n(fieldName);
771 return _invoke(fieldName, JSInvocationMirror.GETTER, reflectiveName, []); 789 return _invoke(fieldName, JSInvocationMirror.GETTER, reflectiveName, []);
772 } 790 }
773 791
774 delegate(Invocation invocation) { 792 delegate(Invocation invocation) {
775 return JSInvocationMirror.invokeFromMirror(invocation, reflectee); 793 return JSInvocationMirror.invokeFromMirror(invocation, reflectee);
776 } 794 }
777 795
796 Function operator [](Symbol selector) {
797 bool found = false;
798 for (ClassMirror c = type; c != null; c = c.superclass) {
799 var target = c.methods[selector];
800 if (target != null && !target.isStatic) {
801 found = true;
802 break;
803 }
804 }
805 if (!found) return null;
806 return new _InvocationTrampoline(this, selector);
807 }
808
778 operator ==(other) { 809 operator ==(other) {
779 return other is JsInstanceMirror && 810 return other is JsInstanceMirror &&
780 identical(reflectee, other.reflectee); 811 identical(reflectee, other.reflectee);
781 } 812 }
782 813
783 int get hashCode { 814 int get hashCode {
784 // If the reflectee is a built-in type, use the base-level hashCode to 815 // If the reflectee is a built-in type, use the base-level hashCode to
785 // preserve the illusion that, e.g. doubles, with the same value are 816 // preserve the illusion that, e.g. doubles, with the same value are
786 // identical. Otherwise, use the primitive identity hash to maintain 817 // identical. Otherwise, use the primitive identity hash to maintain
787 // correctness even if a user-defined hashCode returns different values for 818 // correctness even if a user-defined hashCode returns different values for
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 typeMirrorFromRuntimeTypeRepresentation(JS('', 'init.metadata[#]', 1356 typeMirrorFromRuntimeTypeRepresentation(JS('', 'init.metadata[#]',
1326 typeVars[i+1])); 1357 typeVars[i+1]));
1327 var typeMirror = 1358 var typeMirror =
1328 new JsTypeVariableMirror(s(typeVars[i]), upperBound, this); 1359 new JsTypeVariableMirror(s(typeVars[i]), upperBound, this);
1329 result.add(typeMirror); 1360 result.add(typeMirror);
1330 } 1361 }
1331 return _cachedTypeVariables = new UnmodifiableListView(result); 1362 return _cachedTypeVariables = new UnmodifiableListView(result);
1332 } 1363 }
1333 1364
1334 List<TypeMirror> get typeArguments => new List(); 1365 List<TypeMirror> get typeArguments => new List();
1366
1367 Function operator [](Symbol selector) {
1368 var target = methods[selector];
1369 if (target == null || !target.isStatic) return null;
1370 return new _InvocationTrampoline(this, selector);
1371 }
1335 } 1372 }
1336 1373
1337 class JsVariableMirror extends JsDeclarationMirror implements VariableMirror { 1374 class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
1338 static final int REFLECTION_MARKER = 45; 1375 static final int REFLECTION_MARKER = 45;
1339 1376
1340 // TODO(ahe): The values in these fields are virtually untested. 1377 // TODO(ahe): The values in these fields are virtually untested.
1341 final String _jsName; 1378 final String _jsName;
1342 final bool isFinal; 1379 final bool isFinal;
1343 final bool isStatic; 1380 final bool isStatic;
1344 final _metadataFunction; 1381 final _metadataFunction;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 1984
1948 // TODO(ahe): Remove this class and call noSuchMethod instead. 1985 // TODO(ahe): Remove this class and call noSuchMethod instead.
1949 class UnimplementedNoSuchMethodError extends Error 1986 class UnimplementedNoSuchMethodError extends Error
1950 implements NoSuchMethodError { 1987 implements NoSuchMethodError {
1951 final String _message; 1988 final String _message;
1952 1989
1953 UnimplementedNoSuchMethodError(this._message); 1990 UnimplementedNoSuchMethodError(this._message);
1954 1991
1955 String toString() => "Unsupported operation: $_message"; 1992 String toString() => "Unsupported operation: $_message";
1956 } 1993 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698