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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 } | 325 } |
326 } | 326 } |
327 if (!found) { | 327 if (!found) { |
328 throw new ArgumentError( | 328 throw new ArgumentError( |
329 "${MirrorSystem.getName(type.simpleName)} has no instance method " | 329 "${MirrorSystem.getName(type.simpleName)} has no instance method " |
330 "${MirrorSystem.getName(selector)}"); | 330 "${MirrorSystem.getName(selector)}"); |
331 } | 331 } |
332 return new _InvocationTrampoline(this, selector); | 332 return new _InvocationTrampoline(this, selector); |
333 } | 333 } |
334 | 334 |
335 // TODO(16539): Make these weak. | |
kasperl
2014/02/05 08:34:26
I guess there's no need for complex weak handling
rmacnak
2014/02/05 18:53:41
Soft would do as well. Though I wonder if this wou
| |
336 static Map _getFieldClosures = new HashMap(); | |
337 static Map _setFieldClosures = new HashMap(); | |
338 | |
339 InstanceMirror getField(Symbol memberName) { | |
340 var f = _getFieldClosures[_n(memberName)]; | |
341 if (f == null) { | |
kasperl
2014/02/05 08:32:13
Consider splitting this method in two so it become
| |
342 var unwrapped = _n(memberName); | |
kasperl
2014/02/05 08:32:13
Cache _n(memberName) in a local?
kasperl
2014/02/05 09:05:40
I guess what I meant was: Use unwrapped consistent
| |
343 var at_pos = unwrapped.indexOf('@'); | |
kasperl
2014/02/05 08:32:13
Follow Dart coding style: at_pos -> atPosition or
| |
344 if (at_pos == -1) { | |
345 // Public symbol. | |
346 f = _eval('(x) => x.$unwrapped', null); | |
347 } else { | |
348 // Private symbol. | |
349 var withoutKey = unwrapped.substring(0, at_pos); | |
350 var privateKey = unwrapped.substring(at_pos); | |
351 f = _eval('(x) => x.$withoutKey', privateKey); | |
352 } | |
353 _getFieldClosures[_n(memberName)] = f; | |
354 } | |
355 return reflect(f(_reflectee)); | |
356 } | |
357 | |
358 InstanceMirror setField(Symbol memberName, arg) { | |
359 var f = _setFieldClosures[_n(memberName)]; | |
kasperl
2014/02/05 08:32:13
Cache _n(memberName) in a local?
| |
360 if (f == null) { | |
361 var unwrapped = _n(memberName); | |
362 var at_pos = unwrapped.indexOf('@'); | |
kasperl
2014/02/05 08:32:13
Follow Dart coding style: at_pos -> atPosition or
| |
363 if (at_pos == -1) { | |
364 // Public symbol. | |
365 f = _eval('(x, v) => x.$unwrapped = v', null); | |
366 } else { | |
367 // Private symbol. | |
368 var withoutKey = unwrapped.substring(0, at_pos); | |
369 var privateKey = unwrapped.substring(at_pos); | |
370 f = _eval('(x, v) => x.$withoutKey = v', privateKey); | |
371 } | |
372 _setFieldClosures[_n(memberName)] = f; | |
373 } | |
374 f(_reflectee, arg); | |
375 return reflect(arg); | |
376 } | |
377 | |
378 static _eval(expression, privateKey) | |
379 native "Mirrors_evalInLibraryWithPrivateKey"; | |
380 | |
335 // Override to include the receiver in the arguments. | 381 // Override to include the receiver in the arguments. |
336 InstanceMirror invoke(Symbol memberName, | 382 InstanceMirror invoke(Symbol memberName, |
337 List positionalArguments, | 383 List positionalArguments, |
338 [Map<Symbol, dynamic> namedArguments]) { | 384 [Map<Symbol, dynamic> namedArguments]) { |
339 int numPositionalArguments = positionalArguments.length + 1; // Receiver. | 385 int numPositionalArguments = positionalArguments.length + 1; // Receiver. |
340 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 386 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
341 int numArguments = numPositionalArguments + numNamedArguments; | 387 int numArguments = numPositionalArguments + numNamedArguments; |
342 List arguments = new List(numArguments); | 388 List arguments = new List(numArguments); |
343 arguments[0] = _reflectee; // Receiver. | 389 arguments[0] = _reflectee; // Receiver. |
344 arguments.setRange(1, numPositionalArguments, positionalArguments); | 390 arguments.setRange(1, numPositionalArguments, positionalArguments); |
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1492 if (typeMirror == null) { | 1538 if (typeMirror == null) { |
1493 typeMirror = makeLocalTypeMirror(key); | 1539 typeMirror = makeLocalTypeMirror(key); |
1494 _instanitationCache[key] = typeMirror; | 1540 _instanitationCache[key] = typeMirror; |
1495 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1541 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1496 _declarationCache[key] = typeMirror; | 1542 _declarationCache[key] = typeMirror; |
1497 } | 1543 } |
1498 } | 1544 } |
1499 return typeMirror; | 1545 return typeMirror; |
1500 } | 1546 } |
1501 } | 1547 } |
OLD | NEW |