Skip to content

Commit f5e4bad

Browse files
committed
In version for .NET Core was fixed a error that occurred during the recursive execution and evaluation of JS files
1 parent 26c4f60 commit f5e4bad

File tree

22 files changed

+808
-255
lines changed

22 files changed

+808
-255
lines changed

src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs

+46-17
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,49 @@ private WrapperException WrapJsException(OriginalException originalException,
250250
|| errorValueType == JsValueType.Object)
251251
{
252252
EdgeJsValue messagePropertyValue = errorValue.GetProperty("message");
253-
description = messagePropertyValue.ConvertToString().ToString();
253+
string localDescription = messagePropertyValue.ConvertToString().ToString();
254+
if (!string.IsNullOrWhiteSpace(localDescription))
255+
{
256+
description = localDescription;
257+
}
254258

255259
EdgeJsValue namePropertyValue = errorValue.GetProperty("name");
256260
type = namePropertyValue.ValueType == JsValueType.String ?
257-
namePropertyValue.ConvertToString().ToString() : string.Empty;
261+
namePropertyValue.ToString() : string.Empty;
258262

259-
EdgeJsPropertyId stackPropertyId = EdgeJsPropertyId.FromString("stack");
260-
if (errorValue.HasProperty(stackPropertyId))
263+
EdgeJsPropertyId descriptionPropertyId = EdgeJsPropertyId.FromString("description");
264+
if (errorValue.HasProperty(descriptionPropertyId))
261265
{
262-
EdgeJsPropertyId descriptionPropertyId = EdgeJsPropertyId.FromString("description");
263-
if (errorValue.HasProperty(descriptionPropertyId))
266+
EdgeJsValue descriptionPropertyValue = errorValue.GetProperty(descriptionPropertyId);
267+
localDescription = descriptionPropertyValue.ConvertToString().ToString();
268+
if (!string.IsNullOrWhiteSpace(localDescription))
264269
{
265-
EdgeJsValue descriptionPropertyValue = errorValue.GetProperty(descriptionPropertyId);
266-
if (descriptionPropertyValue.ValueType == JsValueType.String
267-
&& descriptionPropertyValue.StringLength > 0)
268-
{
269-
description = descriptionPropertyValue.ConvertToString().ToString();
270-
}
270+
description = localDescription;
271271
}
272+
}
272273

274+
if (type == JsErrorType.Syntax)
275+
{
276+
errorCode = JsErrorCode.ScriptCompile;
277+
}
278+
else
279+
{
280+
EdgeJsPropertyId numberPropertyId = EdgeJsPropertyId.FromString("number");
281+
if (errorValue.HasProperty(numberPropertyId))
282+
{
283+
EdgeJsValue numberPropertyValue = errorValue.GetProperty(numberPropertyId);
284+
int errorNumber = numberPropertyValue.ValueType == JsValueType.Number ?
285+
numberPropertyValue.ToInt32() : 0;
286+
errorCode = (JsErrorCode)errorNumber;
287+
}
288+
}
289+
290+
EdgeJsPropertyId stackPropertyId = EdgeJsPropertyId.FromString("stack");
291+
if (errorValue.HasProperty(stackPropertyId))
292+
{
273293
EdgeJsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
274294
string messageWithTypeAndCallStack = stackPropertyValue.ValueType == JsValueType.String ?
275-
stackPropertyValue.ConvertToString().ToString() : string.Empty;
295+
stackPropertyValue.ToString() : string.Empty;
276296
string messageWithType = errorValue.ConvertToString().ToString();
277297
string rawCallStack = messageWithTypeAndCallStack
278298
.TrimStart(messageWithType)
@@ -301,36 +321,45 @@ private WrapperException WrapJsException(OriginalException originalException,
301321
if (errorValue.HasProperty(urlPropertyId))
302322
{
303323
EdgeJsValue urlPropertyValue = errorValue.GetProperty(urlPropertyId);
304-
documentName = urlPropertyValue.ConvertToString().ToString();
324+
documentName = urlPropertyValue.ValueType == JsValueType.String ?
325+
urlPropertyValue.ToString() : string.Empty;
305326
}
306327

307328
EdgeJsPropertyId linePropertyId = EdgeJsPropertyId.FromString("line");
308329
if (errorValue.HasProperty(linePropertyId))
309330
{
310331
EdgeJsValue linePropertyValue = errorValue.GetProperty(linePropertyId);
311-
lineNumber = linePropertyValue.ConvertToNumber().ToInt32() + 1;
332+
lineNumber = linePropertyValue.ValueType == JsValueType.Number ?
333+
linePropertyValue.ToInt32() + 1 : 0;
312334
}
313335

314336
EdgeJsPropertyId columnPropertyId = EdgeJsPropertyId.FromString("column");
315337
if (errorValue.HasProperty(columnPropertyId))
316338
{
317339
EdgeJsValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
318-
columnNumber = columnPropertyValue.ConvertToNumber().ToInt32() + 1;
340+
columnNumber = columnPropertyValue.ValueType == JsValueType.Number ?
341+
columnPropertyValue.ToInt32() + 1 : 0;
319342
}
320343

321344
string sourceLine = string.Empty;
322345
EdgeJsPropertyId sourcePropertyId = EdgeJsPropertyId.FromString("source");
323346
if (errorValue.HasProperty(sourcePropertyId))
324347
{
325348
EdgeJsValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
326-
sourceLine = sourcePropertyValue.ConvertToString().ToString();
349+
sourceLine = sourcePropertyValue.ValueType == JsValueType.String ?
350+
sourcePropertyValue.ToString() : string.Empty; ;
327351
}
328352

329353
sourceFragment = TextHelpers.GetTextFragmentFromLine(sourceLine, columnNumber);
330354
message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, documentName,
331355
lineNumber, columnNumber, sourceFragment);
332356
}
333357
}
358+
else if (errorValueType == JsValueType.String)
359+
{
360+
message = errorValue.ToString();
361+
description = message;
362+
}
334363
else
335364
{
336365
message = errorValue.ConvertToString().ToString();

0 commit comments

Comments
 (0)