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

Unified Diff: lib/src/compiler/code_generator.dart

Issue 2201973002: fix optional params to mock methods, allow all signatures (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix getters and setters Created 4 years, 5 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
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index bdbdbc6b3531ba7a55484df8c5a2cbe873002ef6..b1ee1f69cec6b851ef16941c982486a0047766f7 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -1404,44 +1404,48 @@ class CodeGenerator extends GeneralizingAstVisitor
///
/// It will generate an `eatFood` that looks like:
///
- /// eatFood(food) {
+ /// eatFood(...args) {
/// return core.bool.as(this.noSuchMethod(
- /// new dart.InvocationImpl('eatFood', [food])));
+ /// new dart.InvocationImpl('eatFood', args)));
/// }
JS.Method _implementMockMethod(ExecutableElement method) {
- var positionalArgs = <JS.Identifier>[]
- ..addAll(
- method.type.normalParameterNames.map((a) => new JS.Identifier(a)))
- ..addAll(
- method.type.optionalParameterNames.map((a) => new JS.Identifier(a)));
-
- var fnArgs = positionalArgs.toList();
-
var invocationProps = <JS.Property>[];
addProperty(String name, JS.Expression value) {
invocationProps.add(new JS.Property(js.string(name), value));
}
+ var args = new JS.TemporaryId('args');
+ var fnArgs = <JS.Parameter>[];
+ JS.Expression positionalArgs;;
+
if (method.type.namedParameterTypes.isNotEmpty) {
- fnArgs.add(namedArgumentTemp);
- addProperty('namedArguments', namedArgumentTemp);
+ addProperty(
+ 'namedArguments', js.call('dart.extractNamedArgs(#)', [args]));
}
if (method is MethodElement) {
addProperty('isMethod', js.boolean(true));
+
+ fnArgs.add(new JS.RestParameter(args));
+ positionalArgs = args;
} else {
var property = method as PropertyAccessorElement;
if (property.isGetter) {
addProperty('isGetter', js.boolean(true));
+
+ positionalArgs = new JS.ArrayInitializer([]);
} else if (property.isSetter) {
addProperty('isSetter', js.boolean(true));
+
+ fnArgs.add(args);
+ positionalArgs = new JS.ArrayInitializer([args]);
}
}
- var fnBody =
- js.call('this.noSuchMethod(new dart.InvocationImpl(#, #, #))', [
+ var fnBody = js.call(
+ 'this.noSuchMethod(new dart.InvocationImpl(#, #, #))', [
_elementMemberName(method),
- new JS.ArrayInitializer(positionalArgs),
+ positionalArgs,
new JS.ObjectInitializer(invocationProps)
]);

Powered by Google App Engine
This is Rietveld 408576698