Chromium Code Reviews| Index: pkg/compiler/lib/src/js_backend/backend.dart |
| diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart |
| index 67a93675cb473c45c72901ead3210827fa22e69f..b5cbbb3f86303d8927615538e6424e9957050f2a 100644 |
| --- a/pkg/compiler/lib/src/js_backend/backend.dart |
| +++ b/pkg/compiler/lib/src/js_backend/backend.dart |
| @@ -233,6 +233,8 @@ class JavaScriptBackend extends Backend { |
| new Uri(scheme: 'dart', path: '_js_embedded_names'); |
| static final Uri DART_ISOLATE_HELPER = |
| new Uri(scheme: 'dart', path: '_isolate_helper'); |
| + static final Uri PACKAGE_JS = |
| + new Uri(scheme: 'package', path: 'js/js.dart'); |
| static final Uri PACKAGE_LOOKUP_MAP = |
| new Uri(scheme: 'package', path: 'lookup_map/lookup_map.dart'); |
| @@ -294,6 +296,8 @@ class JavaScriptBackend extends Backend { |
| ClassElement jsBoolClass; |
| ClassElement jsPlainJavaScriptObjectClass; |
| ClassElement jsUnknownJavaScriptObjectClass; |
| + ClassElement jsJavaScriptFunctionClass; |
| + ClassElement jsJavaScriptObjectClass; |
| ClassElement jsIndexableClass; |
| ClassElement jsMutableIndexableClass; |
| @@ -331,6 +335,8 @@ class JavaScriptBackend extends Backend { |
| ClassElement forceInlineClass; |
| ClassElement irRepresentationClass; |
| + ClassElement jsAnnotationClass; |
| + |
| Element getInterceptorMethod; |
| ClassElement jsInvocationMirrorClass; |
| @@ -619,6 +625,9 @@ class JavaScriptBackend extends Backend { |
| /// Codegen support for tree-shaking entries of `LookupMap`. |
| LookupMapAnalysis lookupMapAnalysis; |
| + /// Codegen support for typed JavaScript interop. |
| + JsInteropAnalysis jsInteropAnalysis; |
| + |
| /// Support for classifying `noSuchMethod` implementations. |
| NoSuchMethodRegistry noSuchMethodRegistry; |
| @@ -653,6 +662,8 @@ class JavaScriptBackend extends Backend { |
| typeVariableHandler = new TypeVariableHandler(compiler); |
| customElementsAnalysis = new CustomElementsAnalysis(this); |
| lookupMapAnalysis = new LookupMapAnalysis(this); |
| + jsInteropAnalysis = new JsInteropAnalysis(this); |
| + |
| noSuchMethodRegistry = new NoSuchMethodRegistry(this); |
| constantCompilerTask = new JavaScriptConstantTask(compiler); |
| resolutionCallbacks = new JavaScriptResolutionCallbacks(this); |
| @@ -674,7 +685,7 @@ class JavaScriptBackend extends Backend { |
| } |
| FunctionElement resolveExternalFunction(FunctionElement element) { |
| - if (isForeign(element)) return element; |
| + if (isForeign(element) || element.isJsInterop) return element; |
| return patchResolverTask.measure(() { |
| return patchResolverTask.resolveExternalFunction(element); |
| }); |
| @@ -902,6 +913,28 @@ class JavaScriptBackend extends Backend { |
| ClassElement cls, Enqueuer enqueuer) { |
| if (enqueuer.isResolutionQueue) { |
| cls.ensureResolved(resolution); |
| + if (cls.isJsInterop) { |
|
sra1
2015/10/06 21:42:17
Ideally this should be done earlier.
Add a TODO to
Jacob
2015/10/13 01:19:23
done.
|
| + if (!cls.implementsInterface(jsJavaScriptObjectClass)) { |
| + compiler.reportErrorMessage( |
| + cls, |
| + MessageKind.JS_INTEROP_CLASS_CANNOT_EXTEND_DART_CLASS, |
| + {'cls': cls.name}); |
| + return; |
| + } |
| + |
| + cls.forEachMember((ClassElement classElement, Element member) { |
| + if (member.isSynthesized) return; |
| + if (cls.isJsInterop && member is FunctionElement) { |
| + FunctionElement fn = member; |
| + if (!fn.isExternal && !fn.isAbstract) { |
| + compiler.reportErrorMessage( |
| + fn, |
| + MessageKind.JS_INTEROP_CLASS_NON_EXTERNAL_MEMBER, |
| + {'cls': cls.name, 'member': member.name}); |
| + } |
| + } |
| + }); |
| + } |
| cls.forEachMember((ClassElement classElement, Element member) { |
| if (member.name == Identifiers.call) { |
| compiler.reportErrorMessage( |
| @@ -1077,7 +1110,9 @@ class JavaScriptBackend extends Backend { |
| } else if (Elements.isNativeOrExtendsNative(cls)) { |
| enqueue(enqueuer, getNativeInterceptorMethod, registry); |
| enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
| + enqueueClass(enqueuer, jsJavaScriptObjectClass, registry); |
| enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); |
| + enqueueClass(enqueuer, jsJavaScriptFunctionClass, registry); |
| } else if (cls == mapLiteralClass) { |
| // For map literals, the dependency between the implementation class |
| // and [Map] is not visible, so we have to add it manually. |
| @@ -1154,10 +1189,14 @@ class JavaScriptBackend extends Backend { |
| addInterceptors(jsUInt31Class, enqueuer, registry); |
| addInterceptors(jsDoubleClass, enqueuer, registry); |
| addInterceptors(jsNumberClass, enqueuer, registry); |
| + } else if (cls == jsJavaScriptObjectClass) { |
| + addInterceptors(jsJavaScriptObjectClass, enqueuer, registry); |
| } else if (cls == jsPlainJavaScriptObjectClass) { |
| addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, registry); |
| } else if (cls == jsUnknownJavaScriptObjectClass) { |
| addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, registry); |
| + } else if (cls == jsJavaScriptFunctionClass) { |
| + addInterceptors(jsJavaScriptFunctionClass, enqueuer, registry); |
| } else if (Elements.isNativeOrExtendsNative(cls)) { |
| addInterceptorsForNativeClassMembers(cls, enqueuer); |
| } else if (cls == jsIndexingBehaviorInterface) { |
| @@ -1187,7 +1226,9 @@ class JavaScriptBackend extends Backend { |
| if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; |
| Registry registry = compiler.globalDependencies; |
| enqueue(enqueuer, getNativeInterceptorMethod, registry); |
| + enqueueClass(enqueuer, jsJavaScriptObjectClass, registry); |
| enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); |
| + enqueueClass(enqueuer, jsJavaScriptFunctionClass, registry); |
| needToInitializeIsolateAffinityTag = true; |
| needToInitializeDispatchProperty = true; |
| } |
| @@ -1223,6 +1264,7 @@ class JavaScriptBackend extends Backend { |
| onResolutionComplete() { |
| super.onResolutionComplete(); |
| + |
|
sra1
2015/10/06 21:42:17
remove extra line
Jacob
2015/10/13 01:19:23
Done.
|
| computeMembersNeededForReflection(); |
| rti.computeClassesNeedingRti(); |
| } |
| @@ -1550,6 +1592,7 @@ class JavaScriptBackend extends Backend { |
| } |
| ClassElement defaultSuperclass(ClassElement element) { |
| + if (element.isJsInterop) return jsJavaScriptObjectClass; |
| // Native classes inherit from Interceptor. |
| return element.isNative ? jsInterceptorClass : compiler.objectClass; |
| } |
| @@ -2178,6 +2221,8 @@ class JavaScriptBackend extends Backend { |
| jsExtendableArrayClass = findClass('JSExtendableArray'); |
| jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'); |
| jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'); |
| + jsJavaScriptObjectClass = findClass('JavaScriptObject'); |
| + jsJavaScriptFunctionClass = findClass('JavaScriptFunction'); |
| jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'); |
| jsIndexableClass = findClass('JSIndexable'); |
| jsMutableIndexableClass = findClass('JSMutableIndexable'); |
| @@ -2220,6 +2265,8 @@ class JavaScriptBackend extends Backend { |
| } else if (uri == Uris.dart__native_typed_data) { |
| typedArrayClass = findClass('NativeTypedArray'); |
| typedArrayOfIntClass = findClass('NativeTypedArrayOfInt'); |
| + } else if (uri == PACKAGE_JS) { |
| + jsAnnotationClass = find(library, 'Js'); |
| } |
| annotations.onLibraryScanned(library); |
| }); |
| @@ -2669,6 +2716,7 @@ class JavaScriptBackend extends Backend { |
| } |
| void onCodegenStart() { |
| + jsInteropAnalysis.onCodegenStart(); |
| lookupMapAnalysis.onCodegenStart(); |
| } |