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

Side by Side Diff: tests/compiler/dart2js/kernel/impact_test.dart

Issue 2681123004: Handle Native("...") annotations in KernelBehaviorBuilder. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « pkg/compiler/lib/src/patch_parser.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library dart2js.kernel.impact_test; 5 library dart2js.kernel.impact_test;
6 6
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'package:compiler/src/commandline_options.dart'; 8 import 'package:compiler/src/commandline_options.dart';
9 import 'package:compiler/src/common.dart'; 9 import 'package:compiler/src/common.dart';
10 import 'package:compiler/src/common/names.dart'; 10 import 'package:compiler/src/common/names.dart';
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 testForwardingConstructorTyped(); 176 testForwardingConstructorTyped();
177 testForwardingConstructorGeneric(); 177 testForwardingConstructorGeneric();
178 testEnum(); 178 testEnum();
179 testStaticGenericMethod(); 179 testStaticGenericMethod();
180 testInstanceGenericMethod(); 180 testInstanceGenericMethod();
181 testDynamicPrivateMethodInvoke(); 181 testDynamicPrivateMethodInvoke();
182 testJSCall(); 182 testJSCall();
183 testNativeMethod(); 183 testNativeMethod();
184 testNativeMethodCreates(); 184 testNativeMethodCreates();
185 testNativeMethodReturns(); 185 testNativeMethodReturns();
186 testNativeField(null);
186 } 187 }
187 188
188 testEmpty() {} 189 testEmpty() {}
189 testNull() => null; 190 testNull() => null;
190 testTrue() => true; 191 testTrue() => true;
191 testFalse() => false; 192 testFalse() => false;
192 testInt() => 42; 193 testInt() => 42;
193 testDouble() => 37.5; 194 testDouble() => 37.5;
194 testString() => 'foo'; 195 testString() => 'foo';
195 testStringInterpolation() => '${0}'; 196 testStringInterpolation() => '${0}';
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 610 }
610 611
611 testDynamicPrivateMethodInvoke([o]) => o._privateMethod(); 612 testDynamicPrivateMethodInvoke([o]) => o._privateMethod();
612 testJSCall() => JS('int|bool', '#', null); 613 testJSCall() => JS('int|bool', '#', null);
613 @JSName('foo') 614 @JSName('foo')
614 testNativeMethod() native; 615 testNativeMethod() native;
615 @Creates('int|Null|JSArray') 616 @Creates('int|Null|JSArray')
616 testNativeMethodCreates() native; 617 testNativeMethodCreates() native;
617 @Returns('String|Null|JSArray') 618 @Returns('String|Null|JSArray')
618 testNativeMethodReturns() native; 619 testNativeMethodReturns() native;
620
621 @Native("NativeClass")
622 class NativeClass {
623 @annotation_Creates_SerializedScriptValue
624 final Object field;
625
626 factory NativeClass._() { throw new UnsupportedError("Not supported"); }
627 }
628 testNativeField(NativeClass c) => c.field;
619 ''', 629 ''',
620 'sdk/tests/compiler/dart2js_native/helper.dart': ''' 630 'sdk/tests/compiler/dart2js_native/helper.dart': '''
631 import 'dart:_js_helper';
621 class Class { 632 class Class {
622 const Class.generative(); 633 const Class.generative();
623 factory Class.fact() => null; 634 factory Class.fact() => null;
624 const factory Class.redirect() = Class.generative; 635 const factory Class.redirect() = Class.generative;
625 } 636 }
626 class GenericClass<X, Y> { 637 class GenericClass<X, Y> {
627 const GenericClass.generative(); 638 const GenericClass.generative();
628 factory GenericClass.fact() => null; 639 factory GenericClass.fact() => null;
629 const factory GenericClass.redirect() = GenericClass<X, Y>.generative; 640 const factory GenericClass.redirect() = GenericClass<X, Y>.generative;
630 641
631 Map<X, T> genericMethod<T>(T arg) => { null: arg }; 642 Map<X, T> genericMethod<T>(T arg) => { null: arg };
632 } 643 }
633 typedef Typedef(); 644 typedef Typedef();
634 typedef X GenericTypedef<X, Y>(Y y); 645 typedef X GenericTypedef<X, Y>(Y y);
635 ''', 646
647 const String _serializedScriptValue =
648 'num|String|bool|'
649 'JSExtendableArray|=Object';
650 const annotation_Creates_SerializedScriptValue =
651 const Creates(_serializedScriptValue);''',
636 }; 652 };
637 653
638 main(List<String> args) { 654 main(List<String> args) {
639 bool fullTest = args.contains('--full'); 655 bool fullTest = args.contains('--full');
640 asyncTest(() async { 656 asyncTest(() async {
641 enableDebugMode(); 657 enableDebugMode();
642 Uri entryPoint = 658 Uri entryPoint =
643 Uri.parse('memory:sdk/tests/compiler/dart2js_native/main.dart'); 659 Uri.parse('memory:sdk/tests/compiler/dart2js_native/main.dart');
644 Compiler compiler = compilerFor( 660 Compiler compiler = compilerFor(
645 entryPoint: entryPoint, 661 entryPoint: entryPoint,
646 memorySourceFiles: SOURCE, 662 memorySourceFiles: SOURCE,
647 options: [ 663 options: [
648 fullTest ? Flags.analyzeAll : Flags.analyzeOnly, 664 fullTest ? Flags.analyzeAll : Flags.analyzeOnly,
649 Flags.useKernel, 665 Flags.useKernel,
650 Flags.enableAssertMessage 666 Flags.enableAssertMessage
651 ]); 667 ]);
652 compiler.resolution.retainCachesForTesting = true; 668 compiler.resolution.retainCachesForTesting = true;
653 Expect.isTrue(await compiler.run(entryPoint)); 669 Expect.isTrue(await compiler.run(entryPoint));
654 JavaScriptBackend backend = compiler.backend; 670 JavaScriptBackend backend = compiler.backend;
655 KernelElementAdapter kernelElementAdapter = 671 KernelElementAdapter kernelElementAdapter =
656 new KernelWorldBuilder(compiler.reporter, backend.kernelTask.program); 672 new KernelWorldBuilder(compiler.reporter, backend.kernelTask.program);
657 673
658 checkLibrary(compiler, kernelElementAdapter, compiler.mainApp, 674 checkLibrary(compiler, kernelElementAdapter, compiler.mainApp,
659 fullTest: fullTest); 675 fullTest: fullTest);
660 if (fullTest) { 676 compiler.libraryLoader.libraries.forEach((LibraryElement library) {
661 // TODO(johnniwinther): Handle all libraries for `!fullTest`. 677 if (library == compiler.mainApp) return;
662 compiler.libraryLoader.libraries.forEach((LibraryElement library) { 678 checkLibrary(compiler, kernelElementAdapter, library, fullTest: fullTest);
663 if (library == compiler.mainApp) return; 679 });
664 checkLibrary(compiler, kernelElementAdapter, library,
665 fullTest: fullTest);
666 });
667 }
668 }); 680 });
669 } 681 }
670 682
671 void checkLibrary(Compiler compiler, KernelElementAdapter kernelElementAdapter, 683 void checkLibrary(Compiler compiler, KernelElementAdapter kernelElementAdapter,
672 LibraryElement library, 684 LibraryElement library,
673 {bool fullTest: false}) { 685 {bool fullTest: false}) {
674 library.forEachLocalMember((AstElement element) { 686 library.forEachLocalMember((AstElement element) {
675 if (element.isClass) { 687 if (element.isClass) {
676 ClassElement cls = element; 688 ClassElement cls = element;
677 cls.forEachLocalMember((AstElement member) { 689 cls.forEachLocalMember((AstElement member) {
678 checkElement(compiler, kernelElementAdapter, member, 690 checkElement(compiler, kernelElementAdapter, member,
679 fullTest: fullTest); 691 fullTest: fullTest);
680 }); 692 });
681 } else if (element.isTypedef) { 693 } else if (element.isTypedef) {
682 // Skip typedefs. 694 // Skip typedefs.
683 } else { 695 } else {
684 checkElement(compiler, kernelElementAdapter, element, fullTest: fullTest); 696 checkElement(compiler, kernelElementAdapter, element, fullTest: fullTest);
685 } 697 }
686 }); 698 });
687 } 699 }
688 700
689 void checkElement(Compiler compiler, KernelElementAdapter kernelElementAdapter, 701 void checkElement(Compiler compiler, KernelElementAdapter kernelElementAdapter,
690 AstElement element, 702 AstElement element,
691 {bool fullTest: false}) { 703 {bool fullTest: false}) {
692 if (!fullTest) { 704 if (!fullTest && element.library.isPlatformLibrary) {
693 if (element.library.isPlatformLibrary) { 705 return;
694 // TODO(johnniwinther): Enqueue these elements for `!fullTest`.
695 // Test only selected elements in web-related platform libraries since
696 // this unittest otherwise takes too long to run.
697 switch (element.library.canonicalUri.path) {
698 case 'html':
699 if ('$element' ==
700 'function(_ValidatingTreeSanitizer#_sanitizeUntrustedElement)') {
701 break;
702 }
703 return;
704 case 'web_gl':
705 if ('$element' ==
706 'function(RenderingContext#getFramebufferAttachmentParameter)') {
707 break;
708 }
709 return;
710 case 'indexed_db':
711 if ('$element' == 'field(ObjectStore#keyPath)') {
712 break;
713 }
714 return;
715 case 'web_audio':
716 return;
717 }
718 }
719 } 706 }
720 if (element.isConstructor) { 707 if (element.isConstructor) {
721 ConstructorElement constructor = element; 708 ConstructorElement constructor = element;
722 if (constructor.isRedirectingFactory) { 709 if (constructor.isRedirectingFactory) {
723 // Skip redirecting constructors for now; they might not be supported. 710 // Skip redirecting constructors for now; they might not be supported.
724 return; 711 return;
725 } 712 }
726 } 713 }
727 if (!fullTest && !compiler.resolution.hasResolutionImpact(element)) { 714 if (!fullTest && !compiler.resolution.hasResolutionImpact(element)) {
728 return; 715 return;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 visitList(type.optionalParameterTypes), 864 visitList(type.optionalParameterTypes),
878 type.namedParameters, 865 type.namedParameters,
879 visitList(type.namedParameterTypes)); 866 visitList(type.namedParameterTypes));
880 } 867 }
881 } 868 }
882 869
883 /// Perform unaliasing of all typedefs nested within a [ResolutionDartType]. 870 /// Perform unaliasing of all typedefs nested within a [ResolutionDartType].
884 ResolutionDartType unalias(ResolutionDartType type) { 871 ResolutionDartType unalias(ResolutionDartType type) {
885 return const Unaliaser().visit(type); 872 return const Unaliaser().visit(type);
886 } 873 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/patch_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698