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

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

Issue 23045004: Throw when reflecting on elements not covered by a `MirrorsUsed` annotation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
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 52aca10326e72eb235fd37debd112a095ab4aadf..d4e77e545b6f3479a1cc60040f0a67b485718abc 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -260,7 +260,7 @@ class JsLibraryMirror extends JsDeclarationMirror with JsObjectMirror
InstanceMirror invoke(Symbol memberName,
List positionalArguments,
- [Map<Symbol,dynamic> namedArguments]) {
+ [Map<Symbol, dynamic> namedArguments]) {
if (namedArguments != null && !namedArguments.isEmpty) {
throw new UnsupportedError('Named arguments are not implemented.');
}
@@ -272,6 +272,12 @@ class JsLibraryMirror extends JsDeclarationMirror with JsObjectMirror
throw new NoSuchMethodError(
this, '${n(memberName)}', positionalArguments, null);
}
+ if (mirror is JsMethodMirror) {
+ JsMethodMirror method = mirror;
+ if (!method.canInvokeReflectively()) {
+ throw new UnsupportedError('reflection on ${memberName}');
ngeoffray 2013/08/29 07:45:49 Better error message.
karlklose 2013/08/29 15:33:37 Done.
+ }
+ }
return reflect(mirror._invoke(positionalArguments, namedArguments));
}
@@ -1010,6 +1016,9 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror
throw new NoSuchMethodError(
this, n(memberName), positionalArguments, null);
}
+ if (!mirror.canInvokeReflectively()) {
+ throw new UnsupportedError('reflection on ${memberName}');
ngeoffray 2013/08/29 07:45:49 Ditto.
karlklose 2013/08/29 15:33:37 Done.
+ }
return reflect(mirror._invoke(positionalArguments, namedArguments));
}
@@ -1061,6 +1070,16 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
bool isStatic) {
int length = descriptor.length;
var code = fieldCode(descriptor.codeUnitAt(length - 1));
+ if (code == 45) {
ngeoffray 2013/08/29 07:45:49 Put 45 in a variable, like int reflectionMarker =
karlklose 2013/08/29 15:33:37 Done.
+ // 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 {
+ // The field is not available for reflection.
+ return null;
+ }
bool isFinal = false;
if (code == 0) return null; // Inherited field.
bool hasGetter = (code & 3) != 0;
@@ -1113,6 +1132,7 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
}
static int fieldCode(int code) {
+ if (code == 45) return 45;
if (code >= 60 && code <= 64) return code - 59;
if (code >= 123 && code <= 126) return code - 117;
if (code >= 37 && code <= 43) return code - 27;
@@ -1248,6 +1268,10 @@ class JsMethodMirror extends JsDeclarationMirror implements MethodMirror {
return _parameters;
}
+ canInvokeReflectively() {
ngeoffray 2013/08/29 07:45:49 bool canInvokeReflectively() {
karlklose 2013/08/29 15:33:37 Done.
+ return JS('bool', r'#.$reflectable == true', _jsFunction);
ngeoffray 2013/08/29 07:45:49 JS_GET_NAME.
karlklose 2013/08/29 15:33:37 Done.
+ }
+
DeclarationMirror get owner => _owner;
TypeMirror get returnType {

Powered by Google App Engine
This is Rietveld 408576698