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

Unified Diff: sdk/lib/_internal/compiler/implementation/native_handler.dart

Issue 235573006: Validate native tags (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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/native_handler.dart
diff --git a/sdk/lib/_internal/compiler/implementation/native_handler.dart b/sdk/lib/_internal/compiler/implementation/native_handler.dart
index 38577c948c4b4d9eb72308141131e60468c9db0a..f5caa613ec9f0cf6c12aaece4f46a86a157e437e 100644
--- a/sdk/lib/_internal/compiler/implementation/native_handler.dart
+++ b/sdk/lib/_internal/compiler/implementation/native_handler.dart
@@ -537,9 +537,28 @@ abstract class NativeEnqueuerBase implements NativeEnqueuer {
class NativeResolutionEnqueuer extends NativeEnqueuerBase {
+ Map<String, ClassElement> tagOwner = new Map<String, ClassElement>();
+
NativeResolutionEnqueuer(Enqueuer world, Compiler compiler)
: super(world, compiler, compiler.enableNativeLiveTypeAnalysis);
+ void processNativeClass(ClassElement classElement) {
+ super.processNativeClass(classElement);
+
+ // Since we map from dispatch tags to classes, a dispatch tag must be used
+ // on only one native class.
+ for (String tag in nativeTagsOfClass(classElement)) {
+ ClassElement owner = tagOwner[tag];
+ if (owner != null) {
+ compiler.reportError(classElement,
+ MessageKind.GENERIC,
+ {'text': "Tag '$tag' already in use by '${owner.name}'"});
+ } else {
+ tagOwner[tag] = classElement;
+ }
+ }
+ }
+
void logSummary(log(message)) {
log('Resolved ${registeredClasses.length} native elements used, '
'${unusedClasses.length} native elements dead.');
@@ -1048,6 +1067,22 @@ String checkForNativeClass(ElementListener listener) {
return nativeTagInfo;
}
+// The tags string contains comma-separated 'words' which are either dispatch
+// tags (having JavaScript identifier syntax) and directives that begin with
+// `!`.
+List<String> nativeTagsOfClassRaw(ClassElement cls) {
+ String quotedName = cls.nativeTagInfo;
+ return quotedName.substring(1, quotedName.length - 1).split(',');
+}
+
+List<String> nativeTagsOfClass(ClassElement cls) {
+ return nativeTagsOfClassRaw(cls).where((s) => !s.startsWith('!')).toList();
+}
+
+bool nativeTagsForcedNonLeaf(ClassElement cls) =>
+ nativeTagsOfClassRaw(cls).contains('!nonleaf');
+
+
final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$');
void handleSsaNative(SsaBuilder builder, Expression nativeBody) {
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart ('k') | sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698