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

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

Issue 23996002: Use interceptors to handle runtime types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment Created 7 years, 3 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (classMirrors == null) classMirrors = JsCache.allocate(); 427 if (classMirrors == null) classMirrors = JsCache.allocate();
428 var mirror = JsCache.fetch(classMirrors, mangledName); 428 var mirror = JsCache.fetch(classMirrors, mangledName);
429 if (mirror != null) return mirror; 429 if (mirror != null) return mirror;
430 disableTreeShaking(); 430 disableTreeShaking();
431 var constructorOrInterceptor = 431 var constructorOrInterceptor =
432 Primitives.getConstructorOrInterceptor(mangledName); 432 Primitives.getConstructorOrInterceptor(mangledName);
433 if (constructorOrInterceptor == null) { 433 if (constructorOrInterceptor == null) {
434 int index = JS('int|Null', 'init.functionAliases[#]', mangledName); 434 int index = JS('int|Null', 'init.functionAliases[#]', mangledName);
435 if (index != null) { 435 if (index != null) {
436 mirror = new JsTypedefMirror( 436 mirror = new JsTypedefMirror(
437 symbol, mangledName, JS('=Object', 'init.metadata[#]', index)); 437 symbol, mangledName, JS('', 'init.metadata[#]', index));
438 JsCache.update(classMirrors, mangledName, mirror); 438 JsCache.update(classMirrors, mangledName, mirror);
439 return mirror; 439 return mirror;
440 } 440 }
441 // Probably an intercepted class. 441 // Probably an intercepted class.
442 // TODO(ahe): How to handle intercepted classes? 442 // TODO(ahe): How to handle intercepted classes?
443 throw new UnsupportedError('Cannot find class for: ${n(symbol)}'); 443 throw new UnsupportedError('Cannot find class for: ${n(symbol)}');
444 } 444 }
445 var constructor = (constructorOrInterceptor is Interceptor) 445 var constructor = (constructorOrInterceptor is Interceptor)
446 ? JS('', '#.constructor', constructorOrInterceptor) 446 ? JS('', '#.constructor', constructorOrInterceptor)
447 : constructorOrInterceptor; 447 : constructorOrInterceptor;
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 } 1445 }
1446 1446
1447 class JsFunctionTypeMirror implements FunctionTypeMirror { 1447 class JsFunctionTypeMirror implements FunctionTypeMirror {
1448 final _typeData; 1448 final _typeData;
1449 String _cachedToString; 1449 String _cachedToString;
1450 TypeMirror _cachedReturnType; 1450 TypeMirror _cachedReturnType;
1451 UnmodifiableListView<ParameterMirror> _cachedParameters; 1451 UnmodifiableListView<ParameterMirror> _cachedParameters;
1452 1452
1453 JsFunctionTypeMirror(this._typeData); 1453 JsFunctionTypeMirror(this._typeData);
1454 1454
1455 bool get _hasReturnType => JS('bool', '"ret" in #', _typeData);
1456 get _returnType => JS('', '#.ret', _typeData);
1457
1458 bool get _isVoid => JS('bool', '!!#.void', _typeData);
1459
1460 bool get _hasArguments => JS('bool', '"args" in #', _typeData);
1461 List get _arguments => JS('JSExtendableArray', '#.args', _typeData);
1462
1463 bool get _hasOptionalArguments => JS('bool', '"opt" in #', _typeData);
1464 List get _optionalArguments => JS('JSExtendableArray', '#.opt', _typeData);
1465
1466 bool get _hasNamedArguments => JS('bool', '"named" in #', _typeData);
1467 get _namedArguments => JS('=Object', '#.named', _typeData);
1468
1469 TypeMirror get returnType { 1455 TypeMirror get returnType {
1470 if (_cachedReturnType != null) return _cachedReturnType; 1456 if (_cachedReturnType != null) return _cachedReturnType;
1471 if (_isVoid) return _cachedReturnType = JsMirrorSystem._voidType; 1457 if (_typeData.isVoid) return _cachedReturnType = JsMirrorSystem._voidType;
1472 if (!_hasReturnType) return _cachedReturnType = JsMirrorSystem._dynamicType; 1458 if (!_typeData.hasReturnType)
1459 return _cachedReturnType = JsMirrorSystem._dynamicType;
1473 return _cachedReturnType = 1460 return _cachedReturnType =
1474 typeMirrorFromRuntimeTypeRepresentation(_returnType); 1461 typeMirrorFromRuntimeTypeRepresentation(_typeData.returnType);
1475 } 1462 }
1476 1463
1477 List<ParameterMirror> get parameters { 1464 List<ParameterMirror> get parameters {
1478 if (_cachedParameters != null) return _cachedParameters; 1465 if (_cachedParameters != null) return _cachedParameters;
1479 List result = []; 1466 List result = [];
1480 int parameterCount = 0; 1467 int parameterCount = 0;
1481 if (_hasArguments) { 1468 if (_typeData.hasArguments) {
1482 for (var type in _arguments) { 1469 for (var type in _typeData.arguments) {
1483 result.add( 1470 result.add(
1484 new JsParameterMirror('argument${parameterCount++}', this, type)); 1471 new JsParameterMirror('argument${parameterCount++}', this, type));
1485 } 1472 }
1486 } 1473 }
1487 if (_hasOptionalArguments) { 1474 if (_typeData.hasOptionalArguments) {
1488 for (var type in _optionalArguments) { 1475 for (var type in _typeData.optionalArguments) {
1489 result.add( 1476 result.add(
1490 new JsParameterMirror('argument${parameterCount++}', this, type)); 1477 new JsParameterMirror('argument${parameterCount++}', this, type));
1491 } 1478 }
1492 } 1479 }
1493 if (_hasNamedArguments) { 1480 if (_typeData.hasNamedArguments) {
1494 for (var name in extractKeys(_namedArguments)) { 1481 for (var name in extractKeys(_typeData.namedArguments)) {
1495 var type = JS('', '#[#]', _namedArguments, name); 1482 var type = JS('', '#[#]', _typeData.namedArguments, name);
1496 result.add(new JsParameterMirror(name, this, type)); 1483 result.add(new JsParameterMirror(name, this, type));
1497 } 1484 }
1498 } 1485 }
1499 return _cachedParameters = new UnmodifiableListView<ParameterMirror>( 1486 return _cachedParameters = new UnmodifiableListView<ParameterMirror>(
1500 result); 1487 result);
1501 } 1488 }
1502 1489
1503 String toString() { 1490 String toString() {
1504 if (_cachedToString != null) return _cachedToString; 1491 if (_cachedToString != null) return _cachedToString;
1505 var s = "FunctionTypeMirror on '("; 1492 return _cachedToString = "FunctionTypeMirror on '$_typeData'";
1506 var sep = '';
1507 if (_hasArguments) {
1508 for (var argument in _arguments) {
1509 s += runtimeTypeToString(argument);
1510 s += sep;
1511 sep = ', ';
1512 }
1513 }
1514 if (_hasOptionalArguments) {
1515 s += '$sep[';
1516 sep = '';
1517 for (var argument in _optionalArguments) {
1518 s += runtimeTypeToString(argument);
1519 s += sep;
1520 sep = ', ';
1521 }
1522 s += ']';
1523 }
1524 if (_hasNamedArguments) {
1525 s += '$sep{';
1526 sep = '';
1527 for (var name in extractKeys(_namedArguments)) {
1528 s += '$name: ';
1529 s += runtimeTypeToString(JS('', '#[#]', _namedArguments, name));
1530 s += sep;
1531 sep = ', ';
1532 }
1533 s += '}';
1534 }
1535 s += ') -> ';
1536 if (_isVoid) {
1537 s += 'void';
1538 } else if (_hasReturnType) {
1539 s += runtimeTypeToString(_returnType);
1540 } else {
1541 s += 'dynamic';
1542 }
1543 return _cachedToString = "$s'";
1544 } 1493 }
1545 } 1494 }
1546 1495
1547 TypeMirror typeMirrorFromRuntimeTypeRepresentation(type) { 1496 TypeMirror typeMirrorFromRuntimeTypeRepresentation(type) {
1548 if (type == null) return JsMirrorSystem._dynamicType; 1497 if (type == null) return JsMirrorSystem._dynamicType;
1549 String representation = runtimeTypeToString(type); 1498 String representation = runtimeTypeToString(type);
1550 if (representation == null) return reflectClass(Function); 1499 if (representation == null) return reflectClass(Function);
1551 return reflectClass(createRuntimeType(representation)); 1500 return reflectClass(createRuntimeType(representation));
1552 } 1501 }
1553 1502
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 void operator []=(K key, V value) => _throw(); 1615 void operator []=(K key, V value) => _throw();
1667 1616
1668 V putIfAbsent(K key, V ifAbsent()) { _throw(); } 1617 V putIfAbsent(K key, V ifAbsent()) { _throw(); }
1669 1618
1670 void addAll(Map<K, V> other) => _throw(); 1619 void addAll(Map<K, V> other) => _throw();
1671 1620
1672 V remove(K key) { _throw(); } 1621 V remove(K key) { _throw(); }
1673 1622
1674 void clear() => _throw(); 1623 void clear() => _throw();
1675 } 1624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698