Skip to content

Commit 3dad640

Browse files
committed
Fixed a error due to which the global object to become read-only after embedding of the host objects and types
1 parent 957737b commit 3dad640

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ private void InnerEmbedHostItem(string itemName, object value)
535535

536536
try
537537
{
538-
_activeScriptWrapper.AddNamedItem(itemName, ScriptItemFlags.IsVisible | ScriptItemFlags.GlobalMembers);
538+
_activeScriptWrapper.AddNamedItem(itemName, ScriptItemFlags.IsVisible);
539539
}
540540
catch
541541
{

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<IncludeSymbols>true</IncludeSymbols>
2626
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2727
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
28-
<PackageReleaseNotes>In JsRT modes improved a performance of .NET methods projection.</PackageReleaseNotes>
28+
<PackageReleaseNotes>Fixed a error due to which the global object to become read-only after embedding of the host objects and types.</PackageReleaseNotes>
2929
<NeutralLanguage>en-US</NeutralLanguage>
3030
<PackageOutputPath>../../nuget</PackageOutputPath>
3131
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/readme.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
In JsRT modes improved a performance of .NET methods projection.
24+
Fixed a error due to which the global object to become read-only after embedding
25+
of the host objects and types.
2526

2627
============
2728
PROJECT SITE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace MsieJavaScriptEngine.Test.Common.Interop
2+
{
3+
public class SomeClass
4+
{
5+
public int SomeProperty { get; set; } = 123;
6+
public string SomeOtherProperty { get; set; } = "abc";
7+
8+
public static SomeClass Instance { get; } = new SomeClass();
9+
}
10+
}

test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs

+70
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,41 @@ public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceType()
877877

878878
#endregion
879879

880+
#region Special cases
881+
882+
[Test]
883+
public virtual void EmbeddingOfInstanceOfCustomReferenceTypeAndModificationOfGlobalObject()
884+
{
885+
// Arrange
886+
var someObj = new SomeClass();
887+
888+
const string modifyingCode = @"(function () {
889+
'use strict';
890+
891+
var global = typeof self != 'undefined' && self.Math == Math ?
892+
self : Function('return this')();
893+
894+
global['foo'] = 'bar';
895+
})();";
896+
const string variableName = "foo";
897+
const string targetOutput = "bar";
898+
899+
// Act
900+
string output;
901+
902+
using (var jsEngine = CreateJsEngine())
903+
{
904+
jsEngine.EmbedHostObject("someObj", someObj);
905+
jsEngine.Execute(modifyingCode);
906+
output = jsEngine.GetVariableValue<string>(variableName);
907+
}
908+
909+
// Assert
910+
Assert.AreEqual(targetOutput, output);
911+
}
912+
913+
#endregion
914+
880915
#endregion
881916

882917

@@ -1443,6 +1478,41 @@ public virtual void RemovingOfEmbeddedCustomReferenceType()
14431478

14441479
#endregion
14451480

1481+
#region Special cases
1482+
1483+
[Test]
1484+
public virtual void EmbeddingOfCustomReferenceTypeAndModificationOfGlobalObject()
1485+
{
1486+
// Arrange
1487+
var someType = typeof(SomeClass);
1488+
1489+
const string modifyingCode = @"(function () {
1490+
'use strict';
1491+
1492+
var global = typeof self != 'undefined' && self.Math == Math ?
1493+
self : Function('return this')();
1494+
1495+
global.foo = 'baz';
1496+
})();";
1497+
const string variableName = "foo";
1498+
const string targetOutput = "baz";
1499+
1500+
// Act
1501+
string output;
1502+
1503+
using (var jsEngine = CreateJsEngine())
1504+
{
1505+
jsEngine.EmbedHostType("SomeType", someType);
1506+
jsEngine.Execute(modifyingCode);
1507+
output = jsEngine.GetVariableValue<string>(variableName);
1508+
}
1509+
1510+
// Assert
1511+
Assert.AreEqual(targetOutput, output);
1512+
}
1513+
1514+
#endregion
1515+
14461516
#endregion
14471517
}
14481518
}

0 commit comments

Comments
 (0)