Skip to content

Commit 58011ac

Browse files
authored
Merge pull request #886 from Mr-Rm/fix/array
проверка параметров конструктора Массива
2 parents 4ad3251 + a4c50ca commit 58011ac

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ScriptEngine.HostedScript/Library/ArrayImpl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@ public static ArrayImpl Constructor(IValue[] dimensions)
218218
ArrayImpl cloneable = null;
219219
for (int dim = dimensions.Length - 1; dim >= 0; dim--)
220220
{
221+
if (dimensions[dim] == null)
222+
throw RuntimeException.InvalidNthArgumentType(dim + 1);
223+
221224
int bound = (int)dimensions[dim].AsNumber();
225+
if (bound <= 0)
226+
throw RuntimeException.InvalidNthArgumentValue(dim + 1);
227+
222228
var newInst = new ArrayImpl();
223229
FillArray(newInst, bound);
224230
if(cloneable != null)

src/ScriptEngine/Machine/RuntimeExceptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ public static RuntimeException InvalidArgumentType(string argName)
110110
return new RuntimeException(String.Format("Неверный тип аргумента '{0}'", argName));
111111
}
112112

113-
public static RuntimeException InvalidArgumentType(int argNum, string argName="" )
113+
public static RuntimeException InvalidNthArgumentType(int argNum)
114+
{
115+
return new RuntimeException(String.Format("Неверный тип аргумента номер {0}", argNum));
116+
}
117+
118+
public static RuntimeException InvalidArgumentType(int argNum, string argName )
114119
{
115120
return new RuntimeException(String.Format("Неверный тип аргумента номер {0} '{1}'", argNum, argName ));
116121
}
@@ -120,6 +125,11 @@ public static RuntimeException InvalidArgumentValue()
120125
return new RuntimeException("Неверное значение аргумента");
121126
}
122127

128+
public static RuntimeException InvalidNthArgumentValue(int argNum)
129+
{
130+
return new RuntimeException(String.Format("Неверное значение аргумента номер {0}", argNum));
131+
}
132+
123133
public static RuntimeException InvalidArgumentValue(object value)
124134
{
125135
return new RuntimeException("Неверное значение аргумента {"+value.ToString()+"}");

0 commit comments

Comments
 (0)