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

Unified Diff: pkg/compiler/lib/src/js_model/closure.dart

Issue 2999453002: Implement forEachParameter in closures, deal with not all closures being localFunctions (Closed)
Patch Set: . Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/kernel/element_map_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_model/closure.dart
diff --git a/pkg/compiler/lib/src/js_model/closure.dart b/pkg/compiler/lib/src/js_model/closure.dart
index 899411ec8a19fb0fa3ac8e79f599f2e413bc21fe..bcd5228727a63c5c9a660d39ffcd5cd06e360234 100644
--- a/pkg/compiler/lib/src/js_model/closure.dart
+++ b/pkg/compiler/lib/src/js_model/closure.dart
@@ -131,7 +131,12 @@ class KernelClosureConversionTask extends ClosureConversionTask<ir.Node> {
// We want the original declaration where that function is used to point
// to the correct closure class.
_closureRepresentationMap[closureClass.callMethod] = closureClass;
- Entity entity = localsMap.getLocalFunction(node.parent);
+ Entity entity;
+ if (node.parent is ir.Member) {
+ entity = _elementMap.getMember(node.parent);
+ } else {
+ entity = localsMap.getLocalFunction(node.parent);
+ }
assert(entity != null);
_closureRepresentationMap[entity] = closureClass;
}
@@ -337,7 +342,9 @@ class KernelClosureClass extends JsScopeInfo
this.library,
KernelScopeInfo info,
KernelToLocalsMap localsMap)
- : closureEntity = localsMap.getLocalFunction(closureSourceNode.parent),
+ : closureEntity = closureSourceNode.parent is ir.Member
+ ? null
+ : localsMap.getLocalFunction(closureSourceNode.parent),
super.from(info, localsMap);
ClassEntity get closureClassEntity => this;
@@ -434,15 +441,35 @@ class ClosureMemberData implements MemberData {
class ClosureFunctionData extends ClosureMemberData implements FunctionData {
final FunctionType functionType;
+ final ir.FunctionNode functionNode;
- ClosureFunctionData(MemberDefinition definition, this.functionType)
+ ClosureFunctionData(
+ ClosureMemberDefinition definition, this.functionType, this.functionNode)
: super(definition);
- @override
void forEachParameter(KernelToElementMapForBuilding elementMap,
void f(DartType type, String name, ConstantValue defaultValue)) {
- // TODO(johnniwinther,efortuna): Implement this.
- throw new UnimplementedError('ClosureFunctionData.forEachParameter');
+ void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) {
+ DartType type = elementMap.getDartType(node.type);
+ String name = node.name;
+ ConstantValue defaultValue;
+ if (isOptional) {
+ if (node.initializer != null) {
+ defaultValue = elementMap.getConstantValue(node.initializer);
+ } else {
+ defaultValue = new NullConstantValue();
+ }
+ }
+ f(type, name, defaultValue);
+ }
+
+ for (int i = 0; i < functionNode.positionalParameters.length; i++) {
+ handleParameter(functionNode.positionalParameters[i],
+ isOptional: i < functionNode.requiredParameterCount);
+ }
+ functionNode.namedParameters.toList()
+ ..sort(namedOrdering)
+ ..forEach(handleParameter);
}
@override
« no previous file with comments | « no previous file | pkg/compiler/lib/src/kernel/element_map_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698