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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2944003003: Fixes for super tearoff in constructor (Closed)
Patch Set: Created 3 years, 6 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 2775 matching lines...) Expand 10 before | Expand all | Expand 10 after
2786 return new JS.PropertyAccess(dynType, member); 2786 return new JS.PropertyAccess(dynType, member);
2787 } 2787 }
2788 2788
2789 // For instance members, we add implicit-this. 2789 // For instance members, we add implicit-this.
2790 // For method tear-offs, we ensure it's a bound method. 2790 // For method tear-offs, we ensure it's a bound method.
2791 var tearOff = element is MethodElement && !inInvocationContext(node); 2791 var tearOff = element is MethodElement && !inInvocationContext(node);
2792 if (tearOff) { 2792 if (tearOff) {
2793 // To be safe always use the symbolized name when binding on a native 2793 // To be safe always use the symbolized name when binding on a native
2794 // class as bind assumes the name will match the name class sigatures 2794 // class as bind assumes the name will match the name class sigatures
2795 // which is symbolized for native classes. 2795 // which is symbolized for native classes.
2796
2796 var safeName = _emitMemberName(name, 2797 var safeName = _emitMemberName(name,
2797 isStatic: isStatic, 2798 isStatic: isStatic,
2798 type: type, 2799 type: type,
2799 element: accessor, 2800 element: accessor,
2800 alwaysSymbolizeNative: true); 2801 alwaysSymbolizeNative: true);
2801 return _callHelper('bind(this, #)', safeName); 2802 return _callHelper('bind(this, #)', safeName);
2802 } 2803 }
2803 return js.call('this.#', member); 2804 return js.call('this.#', member);
2804 } 2805 }
2805 2806
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after
4813 // subclasses cannot override x. 4814 // subclasses cannot override x.
4814 jsTarget = annotate(new JS.This(), target); 4815 jsTarget = annotate(new JS.This(), target);
4815 } 4816 }
4816 4817
4817 JS.Expression result; 4818 JS.Expression result;
4818 if (accessor is MethodElement && !isStatic) { 4819 if (accessor is MethodElement && !isStatic) {
4819 // Tear-off methods: explicitly bind it. 4820 // Tear-off methods: explicitly bind it.
4820 // To be safe always use the symbolized name when binding on a native 4821 // To be safe always use the symbolized name when binding on a native
4821 // class as bind assumes the name will match the name class signatures 4822 // class as bind assumes the name will match the name class signatures
4822 // which is symbolized for native classes. 4823 // which is symbolized for native classes.
4824
4823 var safeName = _emitMemberName(memberName, 4825 var safeName = _emitMemberName(memberName,
4824 type: getStaticType(target), 4826 type: getStaticType(target),
4825 isStatic: isStatic, 4827 isStatic: isStatic,
4826 element: accessor, 4828 element: accessor,
4827 alwaysSymbolizeNative: true); 4829 alwaysSymbolizeNative: true);
4828 if (isSuper) { 4830 if (isSuper) {
4829 result = 4831 if (!_superAllowed && jsTarget is JS.Super) {
Jennifer Messerly 2017/06/19 20:24:52 You could refactor this entire code block, replaci
vsm 2017/06/19 20:36:20 Done.
4830 _callHelper('bind(this, #, #.#)', [safeName, jsTarget, safeName]); 4832 var superName = _getSuperHelper(accessor, safeName)
4833 ..sourceInformation = jsTarget.sourceInformation;
4834 result = _callHelper('bind(this, #, #)', [safeName, superName]);
4835 } else {
4836 result =
4837 _callHelper('bind(this, #, #.#)', [safeName, jsTarget, safeName]);
4838 }
4831 } else if (_isObjectMemberCall(target, memberName)) { 4839 } else if (_isObjectMemberCall(target, memberName)) {
4832 result = _callHelper('bind(#, #, #.#)', 4840 result = _callHelper('bind(#, #, #.#)',
4833 [jsTarget, _propertyName(memberName), _runtimeModule, memberName]); 4841 [jsTarget, _propertyName(memberName), _runtimeModule, memberName]);
4834 } else { 4842 } else {
4835 result = _callHelper('bind(#, #)', [jsTarget, safeName]); 4843 result = _callHelper('bind(#, #)', [jsTarget, safeName]);
4836 } 4844 }
4837 } else if (_isObjectMemberCall(target, memberName)) { 4845 } else if (_isObjectMemberCall(target, memberName)) {
4838 result = _callHelper('#(#)', [memberName, jsTarget]); 4846 result = _callHelper('#(#)', [memberName, jsTarget]);
4839 } else { 4847 } else {
4840 result = _emitTargetAccess(jsTarget, name, accessor); 4848 result = _emitTargetAccess(jsTarget, name, accessor);
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
5863 if (targetIdentifier.staticElement is! PrefixElement) return false; 5871 if (targetIdentifier.staticElement is! PrefixElement) return false;
5864 var prefix = targetIdentifier.staticElement as PrefixElement; 5872 var prefix = targetIdentifier.staticElement as PrefixElement;
5865 5873
5866 // The library the prefix is referring to must come from a deferred import. 5874 // The library the prefix is referring to must come from a deferred import.
5867 var containingLibrary = resolutionMap 5875 var containingLibrary = resolutionMap
5868 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5876 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5869 .library; 5877 .library;
5870 var imports = containingLibrary.getImportsWithPrefix(prefix); 5878 var imports = containingLibrary.getImportsWithPrefix(prefix);
5871 return imports.length == 1 && imports[0].isDeferred; 5879 return imports.length == 1 && imports[0].isDeferred;
5872 } 5880 }
OLDNEW
« no previous file with comments | « no previous file | tests/language_strong/super_tearoff_test.dart » ('j') | tests/language_strong/super_tearoff_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698