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
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
+9
-5
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user