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
@@ -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));
}