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

Side by Side Diff: pkg/compiler/lib/src/native/behavior.dart

Issue 1457383003: Alternative fix for the js-interop crash. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 native; 5 part of native;
6 6
7 /// This class is a temporary work-around until we get a more powerful DartType. 7 /// This class is a temporary work-around until we get a more powerful DartType.
8 class SpecialType { 8 class SpecialType {
9 final String name; 9 final String name;
10 const SpecialType._(this.name); 10 const SpecialType._(this.name);
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 isBuiltin: false, 639 isBuiltin: false,
640 validTags: const ['returns', 'creates']); 640 validTags: const ['returns', 'creates']);
641 641
642 return behavior; 642 return behavior;
643 } 643 }
644 644
645 static NativeBehavior ofMethod(FunctionElement method, Compiler compiler) { 645 static NativeBehavior ofMethod(FunctionElement method, Compiler compiler) {
646 FunctionType type = method.computeType(compiler.resolution); 646 FunctionType type = method.computeType(compiler.resolution);
647 var behavior = new NativeBehavior(); 647 var behavior = new NativeBehavior();
648 behavior.typesReturned.add(type.returnType); 648 behavior.typesReturned.add(type.returnType);
649 JavaScriptBackend backend = compiler.backend;
650 // Note: For dart:html and other internal libraries, we trust the return
651 // type and use it to limit what we enqueue. We are more conservative about
652 // JS interop types and assume any other JS interop type can be returned
653 // from an interop call or getter.
654 if (backend.isJsInterop(method)) {
655 behavior.typesReturned.add(
656 backend.helpers.jsJavaScriptObjectClass.thisType);
sra1 2015/11/20 19:06:24 It does seem crazy to do this for 'int'. Perhaps
Siggi Cherem (dart-lang) 2015/11/25 21:15:25 Agree - I can't do anything for int to be sound, b
657 behavior.typesInstantiated.add(
658 backend.helpers.jsJavaScriptObjectClass.thisType);
659 }
649 if (!type.returnType.isVoid) { 660 if (!type.returnType.isVoid) {
650 // Declared types are nullable. 661 // Declared types are nullable.
651 behavior.typesReturned.add(compiler.coreTypes.nullType); 662 behavior.typesReturned.add(compiler.coreTypes.nullType);
652 } 663 }
653 behavior._capture(type, compiler.resolution); 664 behavior._capture(type, compiler.resolution);
654 665
655 // TODO(sra): Optional arguments are currently missing from the 666 // TODO(sra): Optional arguments are currently missing from the
656 // DartType. This should be fixed so the following work-around can be 667 // DartType. This should be fixed so the following work-around can be
657 // removed. 668 // removed.
658 method.functionSignature.forEachOptionalParameter( 669 method.functionSignature.forEachOptionalParameter(
659 (ParameterElement parameter) { 670 (ParameterElement parameter) {
660 behavior._escape(parameter.type, compiler.resolution); 671 behavior._escape(parameter.type, compiler.resolution);
661 }); 672 });
662 673
663 behavior._overrideWithAnnotations(method, compiler); 674 behavior._overrideWithAnnotations(method, compiler);
664 return behavior; 675 return behavior;
665 } 676 }
666 677
667 static NativeBehavior ofFieldLoad(MemberElement field, Compiler compiler) { 678 static NativeBehavior ofFieldLoad(MemberElement field, Compiler compiler) {
668 Resolution resolution = compiler.resolution; 679 Resolution resolution = compiler.resolution;
669 DartType type = field.computeType(resolution); 680 DartType type = field.computeType(resolution);
670 var behavior = new NativeBehavior(); 681 var behavior = new NativeBehavior();
671 behavior.typesReturned.add(type); 682 behavior.typesReturned.add(type);
683 JavaScriptBackend backend = compiler.backend;
684 // See comment above on ofMethod
685 if (backend.isJsInterop(field)) {
686 behavior.typesReturned.add(
687 backend.helpers.jsJavaScriptObjectClass.thisType);
688 behavior.typesInstantiated.add(
689 backend.helpers.jsJavaScriptObjectClass.thisType);
690 }
672 // Declared types are nullable. 691 // Declared types are nullable.
673 behavior.typesReturned.add(resolution.coreTypes.nullType); 692 behavior.typesReturned.add(resolution.coreTypes.nullType);
674 behavior._capture(type, resolution); 693 behavior._capture(type, resolution);
675 behavior._overrideWithAnnotations(field, compiler); 694 behavior._overrideWithAnnotations(field, compiler);
676 return behavior; 695 return behavior;
677 } 696 }
678 697
679 static NativeBehavior ofFieldStore(MemberElement field, Compiler compiler) { 698 static NativeBehavior ofFieldStore(MemberElement field, Compiler compiler) {
680 Resolution resolution = compiler.resolution; 699 Resolution resolution = compiler.resolution;
681 DartType type = field.computeType(resolution); 700 DartType type = field.computeType(resolution);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 MessageKind.GENERIC, 829 MessageKind.GENERIC,
811 {'text': "Type '$typeString' not found."}); 830 {'text': "Type '$typeString' not found."});
812 return const DynamicType(); 831 return const DynamicType();
813 } 832 }
814 833
815 static _errorNode(locationNodeOrElement, Parsing parsing) { 834 static _errorNode(locationNodeOrElement, Parsing parsing) {
816 if (locationNodeOrElement is Node) return locationNodeOrElement; 835 if (locationNodeOrElement is Node) return locationNodeOrElement;
817 return locationNodeOrElement.parseNode(parsing); 836 return locationNodeOrElement.parseNode(parsing);
818 } 837 }
819 } 838 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_interop_analysis.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698