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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/native_emitter.dart

Issue 1408043002: Move native and js interop properties from the element model to the JS backend (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class NativeEmitter { 7 class NativeEmitter {
8 8
9 // TODO(floitsch): the native-emitter should not know about ClassBuilders. 9 // TODO(floitsch): the native-emitter should not know about ClassBuilders.
10 final Map<Element, full_js_emitter.ClassBuilder> cachedBuilders; 10 final Map<Element, full_js_emitter.ClassBuilder> cachedBuilders;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 needed = true; 127 needed = true;
128 } else if (interceptorClassesNeededByConstants.contains(classElement)) { 128 } else if (interceptorClassesNeededByConstants.contains(classElement)) {
129 needed = true; 129 needed = true;
130 } else if (classesModifiedByEmitRTISupport.contains(classElement)) { 130 } else if (classesModifiedByEmitRTISupport.contains(classElement)) {
131 // TODO(9556): Remove this test when [emitRuntimeTypeSupport] no longer 131 // TODO(9556): Remove this test when [emitRuntimeTypeSupport] no longer
132 // adds information to a class prototype or constructor. 132 // adds information to a class prototype or constructor.
133 needed = true; 133 needed = true;
134 } else if (extensionPoints.containsKey(cls)) { 134 } else if (extensionPoints.containsKey(cls)) {
135 needed = true; 135 needed = true;
136 } 136 }
137 if (classElement.isJsInterop) { 137 if (backend.isJsInterop(classElement)) {
138 needed = true; // TODO(jacobr): we don't need all interop classes. 138 needed = true; // TODO(jacobr): we don't need all interop classes.
139 } else if (cls.isNative && native.nativeTagsForcedNonLeaf(classElement)) { 139 } else if (cls.isNative &&
140 backend.hasNativeTagsForcedNonLeaf(classElement)) {
140 needed = true; 141 needed = true;
141 nonLeafClasses.add(cls); 142 nonLeafClasses.add(cls);
142 } 143 }
143 144
144 if (needed || neededClasses.contains(cls)) { 145 if (needed || neededClasses.contains(cls)) {
145 neededClasses.add(cls); 146 neededClasses.add(cls);
146 neededClasses.add(cls.superclass); 147 neededClasses.add(cls.superclass);
147 nonLeafClasses.add(cls.superclass); 148 nonLeafClasses.add(cls.superclass);
148 } 149 }
149 } 150 }
150 151
151 // Collect all the tags that map to each native class. 152 // Collect all the tags that map to each native class.
152 153
153 Map<Class, Set<String>> leafTags = new Map<Class, Set<String>>(); 154 Map<Class, Set<String>> leafTags = new Map<Class, Set<String>>();
154 Map<Class, Set<String>> nonleafTags = new Map<Class, Set<String>>(); 155 Map<Class, Set<String>> nonleafTags = new Map<Class, Set<String>>();
155 156
156 for (Class cls in classes) { 157 for (Class cls in classes) {
157 if (!cls.isNative) continue; 158 if (!cls.isNative) continue;
158 if (cls.element.isJsInterop) continue; 159 if (backend.isJsInterop(cls.element)) continue;
159 List<String> nativeTags = native.nativeTagsOfClass(cls.element); 160 List<String> nativeTags = backend.getNativeTagsOfClass(cls.element);
160 161
161 if (nonLeafClasses.contains(cls) || 162 if (nonLeafClasses.contains(cls) ||
162 extensionPoints.containsKey(cls)) { 163 extensionPoints.containsKey(cls)) {
163 nonleafTags 164 nonleafTags
164 .putIfAbsent(cls, () => new Set<String>()) 165 .putIfAbsent(cls, () => new Set<String>())
165 .addAll(nativeTags); 166 .addAll(nativeTags);
166 } else { 167 } else {
167 Class sufficingInterceptor = cls; 168 Class sufficingInterceptor = cls;
168 while (!neededClasses.contains(sufficingInterceptor)) { 169 while (!neededClasses.contains(sufficingInterceptor)) {
169 sufficingInterceptor = sufficingInterceptor.superclass; 170 sufficingInterceptor = sufficingInterceptor.superclass;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 List<jsAst.Statement> statements = <jsAst.Statement>[]; 306 List<jsAst.Statement> statements = <jsAst.Statement>[];
306 potentiallyConvertDartClosuresToJs(statements, member, stubParameters); 307 potentiallyConvertDartClosuresToJs(statements, member, stubParameters);
307 308
308 String target; 309 String target;
309 jsAst.Expression receiver; 310 jsAst.Expression receiver;
310 List<jsAst.Expression> arguments; 311 List<jsAst.Expression> arguments;
311 312
312 assert(invariant(member, nativeMethods.contains(member))); 313 assert(invariant(member, nativeMethods.contains(member)));
313 // When calling a JS method, we call it with the native name, and only the 314 // When calling a JS method, we call it with the native name, and only the
314 // arguments up until the last one provided. 315 // arguments up until the last one provided.
315 target = member.fixedBackendName; 316 target = backend.getFixedBackendName(member);
316 317
317 if (isInterceptedMethod) { 318 if (isInterceptedMethod) {
318 receiver = argumentsBuffer[0]; 319 receiver = argumentsBuffer[0];
319 arguments = argumentsBuffer.sublist(1, 320 arguments = argumentsBuffer.sublist(1,
320 indexOfLastOptionalArgumentInParameters + 1); 321 indexOfLastOptionalArgumentInParameters + 1);
321 } else { 322 } else {
322 // Native methods that are not intercepted must be static. 323 // Native methods that are not intercepted must be static.
323 assert(invariant(member, member.isStatic)); 324 assert(invariant(member, member.isStatic));
324 arguments = argumentsBuffer.sublist(0, 325 arguments = argumentsBuffer.sublist(0,
325 indexOfLastOptionalArgumentInParameters + 1); 326 indexOfLastOptionalArgumentInParameters + 1);
326 if (member.isJsInterop) { 327 if (backend.isJsInterop(member)) {
327 // fixedBackendPath is allowed to have the form foo.bar.baz for 328 // fixedBackendPath is allowed to have the form foo.bar.baz for
328 // interop. This template is uncached to avoid possibly running out of 329 // interop. This template is uncached to avoid possibly running out of
329 // memory when Dart2Js is run in server mode. In reality the risk of 330 // memory when Dart2Js is run in server mode. In reality the risk of
330 // caching these templates causing an issue is very low as each class 331 // caching these templates causing an issue is very low as each class
331 // and library that uses typed JavaScript interop will create only 1 332 // and library that uses typed JavaScript interop will create only 1
332 // unique template. 333 // unique template.
333 receiver = js.uncachedExpressionTemplate( 334 receiver = js.uncachedExpressionTemplate(
334 backend.namer.fixedBackendPath(member)).instantiate([]); 335 backend.namer.fixedBackendPath(member)).instantiate([]);
335 } else { 336 } else {
336 receiver = js('this'); 337 receiver = js('this');
(...skipping 15 matching lines...) Expand all
352 353
353 bool requiresNativeIsCheck(Element element) { 354 bool requiresNativeIsCheck(Element element) {
354 // TODO(sra): Remove this function. It determines if a native type may 355 // TODO(sra): Remove this function. It determines if a native type may
355 // satisfy a check against [element], in which case an interceptor must be 356 // satisfy a check against [element], in which case an interceptor must be
356 // used. We should also use an interceptor if the check can't be satisfied 357 // used. We should also use an interceptor if the check can't be satisfied
357 // by a native class in case we get a native instance that tries to spoof 358 // by a native class in case we get a native instance that tries to spoof
358 // the type info. i.e the criteria for whether or not to use an interceptor 359 // the type info. i.e the criteria for whether or not to use an interceptor
359 // is whether the receiver can be native, not the type of the test. 360 // is whether the receiver can be native, not the type of the test.
360 if (element == null || !element.isClass) return false; 361 if (element == null || !element.isClass) return false;
361 ClassElement cls = element; 362 ClassElement cls = element;
362 if (Elements.isNativeOrExtendsNative(cls)) return true; 363 if (backend.isNativeOrExtendsNative(cls)) return true;
363 return isSupertypeOfNativeClass(element); 364 return isSupertypeOfNativeClass(element);
364 } 365 }
365 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698