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

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

Issue 2748713002: Invoke native methods directly (Closed)
Patch Set: Created 3 years, 9 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 5645 matching lines...) Expand 10 before | Expand all | Expand 10 after
5656 5656
5657 var result = _propertyName(name); 5657 var result = _propertyName(name);
5658 5658
5659 if (useExtension == null) { 5659 if (useExtension == null) {
5660 // Dart "extension" methods. Used for JS Array, Boolean, Number, String. 5660 // Dart "extension" methods. Used for JS Array, Boolean, Number, String.
5661 var baseType = type; 5661 var baseType = type;
5662 while (baseType is TypeParameterType) { 5662 while (baseType is TypeParameterType) {
5663 baseType = (baseType.element as TypeParameterElement).bound; 5663 baseType = (baseType.element as TypeParameterElement).bound;
5664 } 5664 }
5665 useExtension = baseType != null && 5665 useExtension = baseType != null &&
5666 _extensionTypes.hasNativeSubtype(baseType) && 5666 _extensionTypes.hasNativeSubtype(baseType) &&
Jennifer Messerly 2017/03/13 17:20:10 you might want to fold this check into isForwarded
vsm 2017/03/13 20:55:26 Done.
5667 !isForwardedNativeMember(baseType, name) &&
5667 !isObjectMember(name); 5668 !isObjectMember(name);
5668 } 5669 }
5669 5670
5670 return useExtension 5671 return useExtension
5671 ? js.call('#.#', [_extensionSymbolsModule, result]) 5672 ? js.call('#.#', [_extensionSymbolsModule, result])
5672 : result; 5673 : result;
5673 } 5674 }
5674 5675
5676 bool isForwardedNativeMember(DartType type, String name) {
5677 // Don't call extension members that just forward to the underlying
Jennifer Messerly 2017/03/13 17:20:10 this might be nicer as a doc comment?
vsm 2017/03/13 20:55:26 Done - see below.
5678 // native member. We limit this to non-renamed members as the receiver
5679 // may be a mock type.
5680
5681 // Note, this is an underlying assumption here that, if another native type
5682 // subtypes this one, it also forwards this member to its underlying native
5683 // one without renaming.
5684 if (type is InterfaceType) {
Jennifer Messerly 2017/03/13 17:20:11 this check could be moved to line 5665: `useExtens
vsm 2017/03/13 20:55:26 Done.
5685 var element = type.element;
5686 if (_extensionTypes.isNativeClass(element)) {
5687 var member = element.lookUpMethod(name, currentLibrary) ??
Jennifer Messerly 2017/03/13 17:20:11 this is a pretty slow lookup. it'll linear scan th
vsm 2017/03/13 20:55:26 Done.
5688 element.lookUpGetter(name, currentLibrary) ??
5689 element.lookUpSetter(name, currentLibrary);
5690
5691 // Fields on a native class are implicitly native.
5692 // Methods/getters/setters are marked external/native.
5693 if (member != null) {
5694 member = (member.isSynthetic && member is PropertyAccessorElement) ? m ember.variable : member;
Jennifer Messerly 2017/03/13 17:20:10 long line
vsm 2017/03/13 20:55:26 Done.
5695 if (member is FieldElement || member.isExternal) {
5696 var jsName = getAnnotationName(member, isJsName);
5697 return jsName == null || jsName == name;
5698 }
5699 }
5700 }
5701 }
5702 return false;
5703 }
5704
5675 JS.TemporaryId _emitPrivateNameSymbol(LibraryElement library, String name) { 5705 JS.TemporaryId _emitPrivateNameSymbol(LibraryElement library, String name) {
5676 return _privateNames 5706 return _privateNames
5677 .putIfAbsent(library, () => new HashMap()) 5707 .putIfAbsent(library, () => new HashMap())
5678 .putIfAbsent(name, () { 5708 .putIfAbsent(name, () {
5679 var id = new JS.TemporaryId(name); 5709 var id = new JS.TemporaryId(name);
5680 _moduleItems.add( 5710 _moduleItems.add(
5681 js.statement('const # = Symbol(#);', [id, js.string(id.name, "'")])); 5711 js.statement('const # = Symbol(#);', [id, js.string(id.name, "'")]));
5682 return id; 5712 return id;
5683 }); 5713 });
5684 } 5714 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
5960 if (targetIdentifier.staticElement is! PrefixElement) return false; 5990 if (targetIdentifier.staticElement is! PrefixElement) return false;
5961 var prefix = targetIdentifier.staticElement as PrefixElement; 5991 var prefix = targetIdentifier.staticElement as PrefixElement;
5962 5992
5963 // The library the prefix is referring to must come from a deferred import. 5993 // The library the prefix is referring to must come from a deferred import.
5964 var containingLibrary = resolutionMap 5994 var containingLibrary = resolutionMap
5965 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5995 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5966 .library; 5996 .library;
5967 var imports = containingLibrary.getImportsWithPrefix(prefix); 5997 var imports = containingLibrary.getImportsWithPrefix(prefix);
5968 return imports.length == 1 && imports[0].isDeferred; 5998 return imports.length == 1 && imports[0].isDeferred;
5969 } 5999 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/sdk/ddc_sdk.sum ('k') | pkg/dev_compiler/test/codegen_expected/sunflower/sunflower.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698