JS: make defensive copy of argument list in JsInvocation and JsNew constructor
This commit is contained in:
@@ -14,8 +14,8 @@ public final class JsInvocation extends JsExpression.JsExpressionHasArguments {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression qualifier;
|
private JsExpression qualifier;
|
||||||
|
|
||||||
public JsInvocation(@NotNull JsExpression qualifier, @NotNull List<JsExpression> arguments) {
|
public JsInvocation(@NotNull JsExpression qualifier, @NotNull List<? extends JsExpression> arguments) {
|
||||||
super(arguments);
|
super(new SmartList<JsExpression>(arguments));
|
||||||
this.qualifier = qualifier;
|
this.qualifier = qualifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public final class JsNew extends JsExpression.JsExpressionHasArguments {
|
|||||||
this(constructorExpression, new SmartList<JsExpression>());
|
this(constructorExpression, new SmartList<JsExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsNew(JsExpression constructorExpression, List<JsExpression> arguments) {
|
public JsNew(JsExpression constructorExpression, List<? extends JsExpression> arguments) {
|
||||||
super(arguments);
|
super(new SmartList<JsExpression>(arguments));
|
||||||
this.constructorExpression = constructorExpression;
|
this.constructorExpression = constructorExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-5
@@ -200,21 +200,25 @@ object ConstructorCallCase : FunctionCallCase() {
|
|||||||
val invocationArguments = mutableListOf<JsExpression>()
|
val invocationArguments = mutableListOf<JsExpression>()
|
||||||
|
|
||||||
val constructorDescriptor = callableDescriptor as ClassConstructorDescriptor
|
val constructorDescriptor = callableDescriptor as ClassConstructorDescriptor
|
||||||
if (context.shouldBeDeferred(constructorDescriptor)) {
|
|
||||||
context.deferConstructorCall(constructorDescriptor, invocationArguments)
|
if (!context.shouldBeDeferred(constructorDescriptor)) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
val closure = context.getClassOrConstructorClosure(constructorDescriptor)
|
val closure = context.getClassOrConstructorClosure(constructorDescriptor)
|
||||||
invocationArguments += closure?.map { context.getArgumentForClosureConstructor(it) }.orEmpty()
|
invocationArguments += closure?.map { context.getArgumentForClosureConstructor(it) }.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
invocationArguments += argumentsInfo.getArguments()
|
invocationArguments += argumentsInfo.getArguments()
|
||||||
return if (constructorDescriptor.isPrimary || AnnotationsUtils.isNativeObject(constructorDescriptor)) {
|
val result = if (constructorDescriptor.isPrimary || AnnotationsUtils.isNativeObject(constructorDescriptor)) {
|
||||||
JsNew(functionRef, invocationArguments)
|
JsNew(functionRef, invocationArguments)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JsInvocation(functionRef, invocationArguments)
|
JsInvocation(functionRef, invocationArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.shouldBeDeferred(constructorDescriptor)) {
|
||||||
|
context.deferConstructorCall(constructorDescriptor, result.arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -95,9 +95,9 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
|
|||||||
|
|
||||||
JsExpression constructorRef = context.getInnerReference(constructor);
|
JsExpression constructorRef = context.getInnerReference(constructor);
|
||||||
|
|
||||||
JsExpression returnExpression = new JsNew(constructorRef, constructorArguments);
|
JsNew returnExpression = new JsNew(constructorRef, constructorArguments);
|
||||||
if (context.shouldBeDeferred(constructor)) {
|
if (context.shouldBeDeferred(constructor)) {
|
||||||
context.deferConstructorCall(constructor, constructorArguments);
|
context.deferConstructorCall(constructor, returnExpression.getArguments());
|
||||||
}
|
}
|
||||||
functionObj.getBody().getStatements().add(new JsReturn(returnExpression));
|
functionObj.getBody().getStatements().add(new JsReturn(returnExpression));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user