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

Unified Diff: pkg/compiler/lib/src/js_backend/js_interop_analysis.dart

Issue 1409033005: Add @anonymous annotation and restrict object literal constructors to only anonymous classes. This … (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: ptal Created 5 years, 2 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
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend_helpers.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
diff --git a/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart b/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
index 15916f90251c72b06ad98013aa606395eb009d3c..65a49c860c848a5b5a6176a510fee0ef5095984a 100644
--- a/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
+++ b/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
@@ -23,6 +23,7 @@ import '../elements/elements.dart'
FieldElement,
FunctionElement,
LibraryElement,
+ ParameterElement,
MetadataAnnotation;
import '../js/js.dart' as jsAst;
@@ -83,11 +84,39 @@ class JsInteropAnalysis {
}
}
+ bool hasAnonymousAnnotation(Element element) {
+ if (backend.helpers.jsAnonymousClass == null) return false;
+ return element.metadata.any((MetadataAnnotation annotation) {
+ ConstantValue constant = backend.compiler.constants.getConstantValue(
+ annotation.constant);
+ if (constant == null ||
+ constant is! ConstructedConstantValue) return false;
+ ConstructedConstantValue constructedConstant = constant;
+ return constructedConstant.type.element ==
+ backend.helpers.jsAnonymousClass;
+ });
+ }
+
+ void _checkFunctionParameters(FunctionElement fn) {
+ if (fn.hasFunctionSignature &&
+ fn.functionSignature.optionalParametersAreNamed) {
+ backend.reporter.reportErrorMessage(fn,
+ MessageKind.JS_INTEROP_METHOD_WITH_NAMED_ARGUMENTS, {
+ 'method': fn.name
+ });
+ }
+ }
+
void processJsInteropAnnotationsInLibrary(LibraryElement library) {
processJsInteropAnnotation(library);
library.implementation.forEachLocalMember((Element element) {
processJsInteropAnnotation(element);
- if (!element.isClass || !backend.isJsInterop(element)) return;
+ if (!backend.isJsInterop(element)) return;
+ if (element is FunctionElement) {
+ _checkFunctionParameters(element);
+ }
+
+ if (!element.isClass) return;
ClassElement classElement = element;
@@ -108,12 +137,30 @@ class JsInteropAnalysis {
backend.isJsInterop(classElement) &&
member is FunctionElement) {
FunctionElement fn = member;
- if (!fn.isExternal && !fn.isAbstract) {
+ if (!fn.isExternal && !fn.isAbstract && !fn.isConstructor &&
+ !fn.isStatic) {
backend.reporter.reportErrorMessage(
fn,
MessageKind.JS_INTEROP_CLASS_NON_EXTERNAL_MEMBER,
{'cls': classElement.name, 'member': member.name});
}
+
+ if (fn.isFactoryConstructor && hasAnonymousAnnotation(classElement)) {
+ fn.functionSignature.orderedForEachParameter(
+ (ParameterElement parameter) {
+ if (!parameter.isNamed) {
+ backend.reporter.reportErrorMessage(parameter,
+ MessageKind
+ .JS_OBJECT_LITERAL_CONSTRUCTOR_WITH_POSITIONAL_ARGUMENTS,
+ {
+ 'parameter': parameter.name,
+ 'cls': classElement.name
+ });
+ }
+ });
+ } else {
+ _checkFunctionParameters(fn);
+ }
}
});
});
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend_helpers.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698