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

Unified Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 61683007: Reapply "Retain types of toplevel and instance variables for reflection." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix: use '-' instead of ':' as a separator in the field descriptor. Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_emitter/declarations.dart ('k') | tests/lib/lib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/js_mirrors.dart
diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart
index de6c903c59627614bfd391aa292bca300d9660d8..002865d56e9cbba0c43b4502b35e0f461118022f 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -1432,7 +1432,6 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror
}
class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
- static final int REFLECTION_MARKER = 45;
// TODO(ahe): The values in these fields are virtually untested.
final String _jsName;
@@ -1440,10 +1439,12 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
final bool isStatic;
final _metadataFunction;
final DeclarationMirror _owner;
+ final int _type;
List _metadata;
JsVariableMirror(Symbol simpleName,
this._jsName,
+ this._type,
this.isFinal,
this.isStatic,
this._metadataFunction,
@@ -1454,18 +1455,16 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
metadataFunction,
JsDeclarationMirror owner,
bool isStatic) {
- int length = descriptor.length;
- var code = fieldCode(descriptor.codeUnitAt(length - 1));
- if (code == REFLECTION_MARKER) {
- // If the field descriptor has a reflection marker, remove it by
- // changing length and getting the real getter/setter code. The
- // descriptor will be truncated below.
- length--;
- code = fieldCode(descriptor.codeUnitAt(length - 1));
- } else {
+ List<String> fieldInformation = descriptor.split('-');
+ if (fieldInformation.length == 1) {
// The field is not available for reflection.
+ // TODO(ahe): Should return an unreflectable field.
return null;
}
+
+ String field = fieldInformation[0];
+ int length = field.length;
+ var code = fieldCode(field.codeUnitAt(length - 1));
bool isFinal = false;
if (code == 0) return null; // Inherited field.
bool hasGetter = (code & 3) != 0;
@@ -1473,11 +1472,11 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
isFinal = !hasSetter;
length--;
String jsName;
- String accessorName = jsName = descriptor.substring(0, length);
- int divider = descriptor.indexOf(':');
+ String accessorName = jsName = field.substring(0, length);
+ int divider = field.indexOf(':');
if (divider > 0) {
accessorName = accessorName.substring(0, divider);
- jsName = descriptor.substring(divider + 1);
+ jsName = field.substring(divider + 1);
}
var unmangledName;
if (isStatic) {
@@ -1497,14 +1496,21 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
}
}
}
- return new JsVariableMirror(
- s(unmangledName), jsName, isFinal, isStatic, metadataFunction, owner);
+ int type = int.parse(fieldInformation[1]);
+ return new JsVariableMirror(s(unmangledName),
+ jsName,
+ type,
+ isFinal,
+ isStatic,
+ metadataFunction,
+ owner);
}
String get _prettyName => 'VariableMirror';
- // TODO(ahe): Improve this information and test it.
- TypeMirror get type => JsMirrorSystem._dynamicType;
+ TypeMirror get type {
+ return typeMirrorFromRuntimeTypeRepresentation(owner, getMetadata(_type));
+ }
DeclarationMirror get owner => _owner;
@@ -1518,7 +1524,6 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
}
static int fieldCode(int code) {
- if (code == REFLECTION_MARKER) return code;
if (code >= 60 && code <= 64) return code - 59;
if (code >= 123 && code <= 126) return code - 117;
if (code >= 37 && code <= 43) return code - 27;
@@ -1989,17 +1994,17 @@ List<JsVariableMirror> parseCompactFieldSpecification(
bool isStatic,
List<Mirror> result) {
List fieldsMetadata = null;
- List<String> fieldNames;
+ List<String> fields;
if (fieldSpecification is List) {
- fieldNames = splitFields(fieldSpecification[0], ',');
+ fields = splitFields(fieldSpecification[0], ',');
fieldsMetadata = fieldSpecification.sublist(1);
} else if (fieldSpecification is String) {
- fieldNames = splitFields(fieldSpecification, ',');
+ fields = splitFields(fieldSpecification, ',');
} else {
- fieldNames = [];
+ fields = [];
}
int fieldNumber = 0;
- for (String field in fieldNames) {
+ for (String field in fields) {
var metadata;
if (fieldsMetadata != null) {
metadata = fieldsMetadata[fieldNumber++];
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_emitter/declarations.dart ('k') | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698