Added defensive code to make V8-related API objects resurrection-safe, fixing Issue #51.
This commit is contained in:
Родитель
9c43958098
Коммит
e9b6e92a00
|
@ -259,6 +259,7 @@ namespace V8 {
|
|||
if (m_pspContext != nullptr)
|
||||
{
|
||||
delete m_pspContext;
|
||||
m_pspContext = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -184,6 +184,7 @@ namespace V8 {
|
|||
if (m_pspIsolate != nullptr)
|
||||
{
|
||||
delete m_pspIsolate;
|
||||
m_pspIsolate = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,6 +283,7 @@ namespace V8 {
|
|||
if (m_pspHolder != nullptr)
|
||||
{
|
||||
delete m_pspHolder;
|
||||
m_pspHolder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ namespace V8 {
|
|||
if (m_pspHolder != nullptr)
|
||||
{
|
||||
delete m_pspHolder;
|
||||
m_pspHolder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -747,6 +747,48 @@ namespace Microsoft.ClearScript.Test
|
|||
Assert.IsFalse(wr.IsAlive);
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BugFix")]
|
||||
public void BugFix_Resurrection_V8ScriptEngine()
|
||||
{
|
||||
for (var index = 0; index < 256; index++)
|
||||
{
|
||||
var wrapper = new ResurrectionTestWrapper(new V8ScriptEngine());
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BugFix")]
|
||||
public void BugFix_Resurrection_V8Runtime()
|
||||
{
|
||||
for (var index = 0; index < 256; index++)
|
||||
{
|
||||
var wrapper = new ResurrectionTestWrapper(new V8Runtime());
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BugFix")]
|
||||
public void BugFix_Resurrection_V8Script()
|
||||
{
|
||||
for (var index = 0; index < 256; index++)
|
||||
{
|
||||
var tempEngine = new V8ScriptEngine();
|
||||
var wrapper = new ResurrectionTestWrapper(tempEngine.Compile("function foo() {}"));
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BugFix")]
|
||||
public void BugFix_Resurrection_V8ScriptItem()
|
||||
{
|
||||
for (var index = 0; index < 256; index++)
|
||||
{
|
||||
var tempEngine = new V8ScriptEngine();
|
||||
var wrapper = new ResurrectionTestWrapper(tempEngine.Script.Math);
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
@ -779,6 +821,21 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
public class ResurrectionTestWrapper
|
||||
{
|
||||
private readonly IDisposable target;
|
||||
|
||||
public ResurrectionTestWrapper(IDisposable target)
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
~ResurrectionTestWrapper()
|
||||
{
|
||||
target.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче