Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/OneScript.StandardLibrary/Tasks/BackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void ExecuteOnCurrentThread()
catch (ScriptException exception)
{
State = TaskStateEnum.CompletedWithErrors;
exception.RuntimeSpecificInfo = MachineInstance.Current.GetExecutionFrames();
ExceptionInfo = new ExceptionInfoContext(exception);
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/ScriptEngine/Machine/Contexts/StackTraceCollectionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This Source Code Form is subject to the terms of the
using System.Collections.Generic;
using System.Linq;
using OneScript.Contexts;
using OneScript.Exceptions;

namespace ScriptEngine.Machine.Contexts
{
Expand All @@ -30,6 +31,11 @@ internal StackTraceCollectionContext(IEnumerable<ExecutionFrameInfo> frames)
}).ToList();
}

/// <summary>
/// Возвращает количество кадров в стеке вызовов
/// </summary>
/// <returns>Число - Количество кадров в стеке вызовов</returns>
[ContextMethod("Количество", "Count")]
public override int Count()
{
return _frames.Count;
Expand All @@ -39,5 +45,23 @@ public override IEnumerator<StackTraceItemContext> GetEnumerator()
{
return _frames.GetEnumerator();
}

public override bool IsIndexed => true;

public override IValue GetIndexedValue(IValue index)
{
var idx = (int)index.AsNumber();

if (idx < 0 || idx >= Count())
throw IndexOutOfBoundsException();

return _frames[idx];
}

private static RuntimeException IndexOutOfBoundsException()
{
return new RuntimeException("Значение индекса выходит за пределы диапазона");
}

}
}
1 change: 1 addition & 0 deletions src/ScriptEngine/Machine/MachineInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,7 @@ private IValue PopRawValue()

public IList<ExecutionFrameInfo> GetExecutionFrames()
{
CreateFullCallstack();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот это кажется перформанс критикал будет. На каждый конверт из ссылки в сырое значение делать стек...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я не совсем понимаю о чём ты говоришь.
image

Вот в приведённых вызовах который из это "конверт из ссылки в сырое значение" ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Прошу прощения, тупанул. UI гитхаба скрывает то, что написано выше, и отображает серым, а там метод PopRawValue. И я подумал, что мы в этот опкод добавили CreateFullStack

return _fullCallstackCache;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/tasks.os
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ВсеТесты.Добавить("ТестДолжен_ПроверитьЧтоВозвращаетсяРезультатДелегата");
ВсеТесты.Добавить("ТестДолжен_ПроверитьЧтоРаботаетБлокировка");
ВсеТесты.Добавить("ТестДолжен_ПроверитьЧтоКодМожетОпределитьИДЗадания");
ВсеТесты.Добавить("ТестДолжен_ПроверитьЧтоВИнформацииОбОшибкеЕстьСтекВызовов");
ВсеТесты.Добавить("ТестДолжен_ПроверитьЧтоОбработчикиСобытийВызываютсяВФоновомЗадании");

Возврат ВсеТесты;
Expand Down Expand Up @@ -271,6 +272,23 @@

КонецПроцедуры

Процедура ТестДолжен_ПроверитьЧтоВИнформацииОбОшибкеЕстьСтекВызовов() Экспорт

Задание = ФоновыеЗадания.Выполнить(ЭтотОбъект, "ПроцедураСИсключением");
Задание.ОжидатьЗавершения();

СтекВызовов = Задание.ИнформацияОбОшибке.ПолучитьСтекВызовов();

юТест.ПроверитьТип(СтекВызовов, "КоллекцияКадровСтекаВызовов");

юТест.ПроверитьРавенство(СтекВызовов.Количество(), 1);

юТест.ПроверитьРавенство(СтекВызовов[0].Метод, "ПроцедураСИсключением");
юТест.ПроверитьЗаполненность(СтекВызовов[0].НомерСтроки);
юТест.ПроверитьРавенство(СтекВызовов[0].ИмяМодуля, ТекущийСценарий().Источник);

КонецПроцедуры

Процедура ТестДолжен_ПроверитьЧтоОбработчикиСобытийВызываютсяВФоновомЗадании() Экспорт

СобытиеВызвано = Ложь;
Expand Down