| 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 final emptyList = new UnmodifiableListView([]); | 9 final emptyList = new UnmodifiableListView([]); |
| 10 final emptyMap = new _UnmodifiableMapView({}); | 10 final emptyMap = new _UnmodifiableMapView({}); |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 _LocalClosureMirror(reflectee) : super(reflectee); | 439 _LocalClosureMirror(reflectee) : super(reflectee); |
| 440 | 440 |
| 441 MethodMirror _function; | 441 MethodMirror _function; |
| 442 MethodMirror get function { | 442 MethodMirror get function { |
| 443 if (_function == null) { | 443 if (_function == null) { |
| 444 _function = _computeFunction(reflectee); | 444 _function = _computeFunction(reflectee); |
| 445 } | 445 } |
| 446 return _function; | 446 return _function; |
| 447 } | 447 } |
| 448 | 448 |
| 449 // TODO(12602): Remove this special case. | |
| 450 delegate(Invocation invocation) { | |
| 451 if (invocation.isMethod && (invocation.memberName == #call)) { | |
| 452 return this.apply(invocation.positionalArguments, | |
| 453 invocation.namedArguments).reflectee; | |
| 454 } | |
| 455 return super.delegate(invocation); | |
| 456 } | |
| 457 | |
| 458 InstanceMirror apply(List<Object> positionalArguments, | 449 InstanceMirror apply(List<Object> positionalArguments, |
| 459 [Map<Symbol, Object> namedArguments]) { | 450 [Map<Symbol, Object> namedArguments]) { |
| 460 // TODO(12602): When closures get an ordinary call method, this can be | 451 return this.invoke(#call, positionalArguments, namedArguments); |
| 461 // replaced with | |
| 462 // return this.invoke(#call, positionalArguments, namedArguments); | |
| 463 // and the native ClosureMirror_apply can be removed. | |
| 464 int numPositionalArguments = positionalArguments.length + 1; // Receiver. | |
| 465 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | |
| 466 int numArguments = numPositionalArguments + numNamedArguments; | |
| 467 List arguments = new List(numArguments); | |
| 468 arguments[0] = _reflectee; // Receiver. | |
| 469 arguments.setRange(1, numPositionalArguments, positionalArguments); | |
| 470 List names = new List(numNamedArguments); | |
| 471 int argumentIndex = numPositionalArguments; | |
| 472 int nameIndex = 0; | |
| 473 if (numNamedArguments > 0) { | |
| 474 namedArguments.forEach((name, value) { | |
| 475 arguments[argumentIndex++] = value; | |
| 476 names[nameIndex++] = _n(name); | |
| 477 }); | |
| 478 } | |
| 479 | |
| 480 // It is tempting to implement this in terms of Function.apply, but then | |
| 481 // lazy compilation errors would be fatal. | |
| 482 return reflect(_apply(arguments, names)); | |
| 483 } | 452 } |
| 484 | 453 |
| 485 InstanceMirror findInContext(Symbol name, {ifAbsent: null}) { | 454 InstanceMirror findInContext(Symbol name, {ifAbsent: null}) { |
| 486 List<String> parts = _n(name).split(".").toList(growable: false); | 455 List<String> parts = _n(name).split(".").toList(growable: false); |
| 487 if (parts.length > 3) { | 456 if (parts.length > 3) { |
| 488 throw new ArgumentError("Invalid symbol: ${name}"); | 457 throw new ArgumentError("Invalid symbol: ${name}"); |
| 489 } | 458 } |
| 490 List tuple = _computeFindInContext(_reflectee, parts); | 459 List tuple = _computeFindInContext(_reflectee, parts); |
| 491 if (tuple.length == 0) { | 460 if (tuple.length == 0) { |
| 492 throw new UnsupportedError( | 461 throw new UnsupportedError( |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 if (typeMirror == null) { | 1599 if (typeMirror == null) { |
| 1631 typeMirror = makeLocalTypeMirror(key); | 1600 typeMirror = makeLocalTypeMirror(key); |
| 1632 _instanitationCache[key] = typeMirror; | 1601 _instanitationCache[key] = typeMirror; |
| 1633 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1602 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1634 _declarationCache[key] = typeMirror; | 1603 _declarationCache[key] = typeMirror; |
| 1635 } | 1604 } |
| 1636 } | 1605 } |
| 1637 return typeMirror; | 1606 return typeMirror; |
| 1638 } | 1607 } |
| 1639 } | 1608 } |
| OLD | NEW |