Skip to content

Commit 5cdcfa5

Browse files
committed
Fixed a error, that occurred in the Classic mode during removing the embedded host objects and types
1 parent 1318942 commit 5cdcfa5

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,25 @@ public override void RemoveVariable(string variableName)
725725
{
726726
try
727727
{
728-
InnerSetVariableValue(variableName, null);
729-
730-
if (_hostItems.ContainsKey(variableName))
728+
if (_engineMode == JsEngineMode.Classic)
731729
{
732-
_hostItems.Remove(variableName);
730+
if (_hostItems.ContainsKey(variableName))
731+
{
732+
_hostItems.Remove(variableName);
733+
}
734+
else
735+
{
736+
InnerSetVariableValue(variableName, null);
737+
}
738+
}
739+
else
740+
{
741+
InnerSetVariableValue(variableName, null);
742+
743+
if (_hostItems.ContainsKey(variableName))
744+
{
745+
_hostItems.Remove(variableName);
746+
}
733747
}
734748
}
735749
catch (ActiveScriptException e)

test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,37 @@ public virtual void InteractionOfEmbeddedCustomValueTypeAndDelegateInstancesIsCo
553553

554554
#endregion
555555

556+
#region Removal
557+
558+
[Test]
559+
public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceTypeIsCorrect()
560+
{
561+
// Arrange
562+
var person = new Person("Vasya", "Pupkin");
563+
564+
// Act
565+
Exception currentException = null;
566+
567+
using (var jsEngine = CreateJsEngine())
568+
{
569+
jsEngine.EmbedHostObject("person", person);
570+
571+
try
572+
{
573+
jsEngine.RemoveVariable("person");
574+
}
575+
catch (Exception e)
576+
{
577+
currentException = e;
578+
}
579+
}
580+
581+
// Assert
582+
Assert.Null(currentException);
583+
}
584+
585+
#endregion
586+
556587
#endregion
557588

558589

@@ -1034,6 +1065,37 @@ public virtual void EmbeddingOfCustomReferenceTypeWithMethodIsCorrect()
10341065

10351066
#endregion
10361067

1068+
#region Removal
1069+
1070+
[Test]
1071+
public virtual void RemovingOfEmbeddedCustomReferenceTypeIsCorrect()
1072+
{
1073+
// Arrange
1074+
Type personType = typeof(Person);
1075+
1076+
// Act
1077+
Exception currentException = null;
1078+
1079+
using (var jsEngine = CreateJsEngine())
1080+
{
1081+
jsEngine.EmbedHostType("Person", personType);
1082+
1083+
try
1084+
{
1085+
jsEngine.RemoveVariable("Person");
1086+
}
1087+
catch (Exception e)
1088+
{
1089+
currentException = e;
1090+
}
1091+
}
1092+
1093+
// Assert
1094+
Assert.Null(currentException);
1095+
}
1096+
1097+
#endregion
1098+
10371099
#endregion
10381100
}
10391101
}

0 commit comments

Comments
 (0)