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

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: Address Nicolas' comments. 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..86f1f418215b19702b0fd24c501047d79c437c56 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -25,6 +25,7 @@ import 'dart:_js_helper' show
createRuntimeType,
createUnmangledInvocationMirror,
getMangledTypeName,
+ throwInvalidReflectionError,
runtimeTypeToString;
import 'dart:_interceptors' show
Interceptor,
@@ -260,7 +261,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 +273,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()) {
+ throwInvalidReflectionError(memberName);
+ }
+ }
return reflect(mirror._invoke(positionalArguments, namedArguments));
}
@@ -1010,6 +1017,9 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror
throw new NoSuchMethodError(
this, n(memberName), positionalArguments, null);
}
+ if (!mirror.canInvokeReflectively()) {
+ throwInvalidReflectionError(memberName);
+ }
return reflect(mirror._invoke(positionalArguments, namedArguments));
}
@@ -1039,6 +1049,8 @@ 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;
final bool isFinal;
@@ -1061,6 +1073,16 @@ class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
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 {
+ // 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 +1135,7 @@ 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;
@@ -1248,6 +1271,10 @@ class JsMethodMirror extends JsDeclarationMirror implements MethodMirror {
return _parameters;
}
+ bool canInvokeReflectively() {
+ return JS('bool', '#[#] != false', _jsFunction, JS_GET_NAME("REFLECTABLE"));
+ }
+
DeclarationMirror get owner => _owner;
TypeMirror get returnType {
« no previous file with comments | « sdk/lib/_internal/lib/js_helper.dart ('k') | tests/compiler/dart2js_extra/mirror_invalid_field_access2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698