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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 142193005: Fix JS-backend when MirrorsUsed target a static field, but there is no mirrors usage. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Extract function that finds static field targets. Created 6 years, 11 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/compiler/implementation/js_backend/backend.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
index 56bf967f898966410c89688f59d86c500995affa..35abf1ce879121bac08a65ded890548d4548ad89 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
@@ -1744,13 +1744,47 @@ class JavaScriptBackend extends Backend {
return isTypedArray(mask) || mask.containsMask(indexing, compiler);
}
+ /// Returns all static fields that are referenced through [targetsUsed].
+ /// If the target is a library or class all nested static fields are
+ /// included too.
+ Iterable<Element> _findStaticFieldTargets() {
+ List staticFields = [];
+
+ void addFieldsInContainer(ScopeContainerElement container) {
+ container.forEachLocalMember((Element member) {
+ if (!member.isInstanceMember() && member.isField()) {
+ staticFields.add(member);
+ } else if (member.isClass()) {
+ addFieldsInContainer(member);
+ }
+ });
+ }
+
+ for (Element target in targetsUsed) {
+ if (target == null) continue;
+ if (target.isField()) {
+ staticFields.add(target);
+ } else if (target.isLibrary() || target.isClass()) {
+ addFieldsInContainer(target);
+ }
+ }
+ return staticFields;
+ }
+
/// Called when [enqueuer] is empty, but before it is closed.
void onQueueEmpty(Enqueuer enqueuer) {
if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) {
preMirrorsMethodCount = generatedCode.length;
}
- if (isTreeShakingDisabled) enqueuer.enqueueEverything();
+ if (isTreeShakingDisabled) {
+ enqueuer.enqueueEverything();
+ } else if (!targetsUsed.isEmpty && enqueuer.isResolutionQueue) {
+ // Add all static elements (not classes) that have been requested for
+ // reflection. If there is no mirror-usage these are probably not
+ // necessary, but the backend relies on them being resolved.
+ enqueuer.enqueueReflectiveStaticFields(_findStaticFieldTargets());
+ }
if (mustPreserveNames) compiler.log('Preserving names.');

Powered by Google App Engine
This is Rietveld 408576698