JS: make defensive copy of argument list in JsInvocation and JsNew constructor

This commit is contained in:
Alexey Andreev
2016-12-29 17:28:22 +03:00
parent 51e5b5aac7
commit 0a9c536c01
4 changed files with 15 additions and 11 deletions
@@ -14,8 +14,8 @@ public final class JsInvocation extends JsExpression.JsExpressionHasArguments {
@NotNull
private JsExpression qualifier;
public JsInvocation(@NotNull JsExpression qualifier, @NotNull List<JsExpression> arguments) {
super(arguments);
public JsInvocation(@NotNull JsExpression qualifier, @NotNull List<? extends JsExpression> arguments) {
super(new SmartList<JsExpression>(arguments));
this.qualifier = qualifier;
}
@@ -17,8 +17,8 @@ public final class JsNew extends JsExpression.JsExpressionHasArguments {
this(constructorExpression, new SmartList<JsExpression>());
}
public JsNew(JsExpression constructorExpression, List<JsExpression> arguments) {
super(arguments);
public JsNew(JsExpression constructorExpression, List<? extends JsExpression> arguments) {
super(new SmartList<JsExpression>(arguments));
this.constructorExpression = constructorExpression;
}
@@ -200,21 +200,25 @@ object ConstructorCallCase : FunctionCallCase() {
val invocationArguments = mutableListOf<JsExpression>()
val constructorDescriptor = callableDescriptor as ClassConstructorDescriptor
if (context.shouldBeDeferred(constructorDescriptor)) {
context.deferConstructorCall(constructorDescriptor, invocationArguments)
}
else {
if (!context.shouldBeDeferred(constructorDescriptor)) {
val closure = context.getClassOrConstructorClosure(constructorDescriptor)
invocationArguments += closure?.map { context.getArgumentForClosureConstructor(it) }.orEmpty()
}
invocationArguments += argumentsInfo.getArguments()
return if (constructorDescriptor.isPrimary || AnnotationsUtils.isNativeObject(constructorDescriptor)) {
val result = if (constructorDescriptor.isPrimary || AnnotationsUtils.isNativeObject(constructorDescriptor)) {
JsNew(functionRef, invocationArguments)
}
else {
JsInvocation(functionRef, invocationArguments)
}
if (context.shouldBeDeferred(constructorDescriptor)) {
context.deferConstructorCall(constructorDescriptor, result.arguments)
}
return result
}
}
@@ -95,9 +95,9 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
JsExpression constructorRef = context.getInnerReference(constructor);
JsExpression returnExpression = new JsNew(constructorRef, constructorArguments);
JsNew returnExpression = new JsNew(constructorRef, constructorArguments);
if (context.shouldBeDeferred(constructor)) {
context.deferConstructorCall(constructor, constructorArguments);
context.deferConstructorCall(constructor, returnExpression.getArguments());
}
functionObj.getBody().getStatements().add(new JsReturn(returnExpression));
}