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

Unified Diff: pkg/compiler/lib/src/patch_parser.dart

Issue 1318043005: Support user generated custom native JS classes. (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
Index: pkg/compiler/lib/src/patch_parser.dart
diff --git a/pkg/compiler/lib/src/patch_parser.dart b/pkg/compiler/lib/src/patch_parser.dart
index a2ec63cf7006cdbfc964892a24ed6e9844cfe6db..0b60945f2a97c3217fc30c035982289926ac683a 100644
--- a/pkg/compiler/lib/src/patch_parser.dart
+++ b/pkg/compiler/lib/src/patch_parser.dart
@@ -133,6 +133,8 @@ import 'elements/modelx.dart' show
LibraryElementX,
MetadataAnnotationX,
SetterElementX;
+import 'js_backend/js_backend.dart' show
+ JavaScriptBackend;
import 'library_loader.dart' show
LibraryLoader;
import 'parser/listener.dart' show
@@ -303,6 +305,7 @@ void patchElement(Compiler compiler,
patch, MessageKind.PATCH_NON_EXISTING, {'name': patch.name});
return;
}
+
if (!(origin.isClass ||
origin.isConstructor ||
origin.isFunction ||
@@ -365,6 +368,12 @@ checkNativeAnnotation(Compiler compiler, ClassElement cls) {
const NativeAnnotationHandler());
}
+checkJsInteropAnnotation(Compiler compiler, element) {
+ EagerAnnotationHandler.checkAnnotation(compiler, element,
+ const JsInteropAnnotationHandler());
+}
+
+
/// Abstract interface for pre-resolution detection of metadata.
///
/// The detection is handled in two steps:
@@ -397,12 +406,19 @@ abstract class EagerAnnotationHandler<T> {
if (result != null) {
// TODO(johnniwinther): Perform this check in
// [Compiler.onLibrariesLoaded].
- compiler.enqueuer.resolution.addDeferredAction(element, () {
+ // TODO(jacobr): annotation resolution needs to be refactored.
+ actionCallback() {
annotation.ensureResolved(compiler.resolution);
handler.validate(
compiler, element, annotation,
compiler.constants.getConstantValue(annotation.constant));
- });
+ }
+ if (compiler.enqueuer.resolution.queueIsClosed) {
+ actionCallback();
Siggi Cherem (dart-lang) 2015/10/06 22:38:02 I was hoping that now that you moved the logic to
Jacob 2015/10/13 01:19:24 me too.. reverted.
+ } else {
+ compiler.enqueuer.resolution.addDeferredAction(element,
+ actionCallback);
+ }
return result;
}
}
@@ -452,6 +468,37 @@ class NativeAnnotationHandler implements EagerAnnotationHandler<String> {
}
}
+/// Annotation handler for pre-resolution detection of `@Js(...)`
+/// annotations.
+class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> {
+ const JsInteropAnnotationHandler();
+
+ bool hasJsNameAnnotation(MetadataAnnotation annotation) =>
+ annotation.beginToken != null && annotation.beginToken.next.value == 'Js';
+
+ bool apply(Compiler compiler,
+ Element element,
+ MetadataAnnotation annotation) {
+ bool hasJsInterop = hasJsNameAnnotation(annotation);
+ if (hasJsInterop) {
+ element.setHasJsInterop();
+ }
+ return hasJsInterop == true ? true : null;
Siggi Cherem (dart-lang) 2015/10/06 22:38:02 might be worth a tiny comment on why not return fa
Jacob 2015/10/13 01:19:24 Done.
+ }
+
+ @override
+ void validate(Compiler compiler,
+ Element element,
+ MetadataAnnotation annotation,
+ ConstantValue constant) {
+ JavaScriptBackend backend = compiler.backend;
+ if (constant.getType(compiler.coreTypes).element !=
+ backend.jsAnnotationClass) {
+ compiler.internalError(annotation, 'Invalid @Js(...) annotation.');
+ }
+ }
+}
+
/// Annotation handler for pre-resolution detection of `@patch` annotations.
class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> {
const PatchAnnotationHandler();

Powered by Google App Engine
This is Rietveld 408576698