Skip to content

Commit 8a4abb5

Browse files
committed
Fixed a error, that occurred during setting a value to field of embedded type
1 parent 553258d commit 8a4abb5

File tree

9 files changed

+129
-24
lines changed

9 files changed

+129
-24
lines changed

src/MsieJavaScriptEngine/HostItemBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ protected object InvokeStandardMember(string name, BindingFlags invokeAttr, Bind
8787
{
8888
BindingFlags processedInvokeAttr = invokeAttr;
8989
if ((processedInvokeAttr.HasFlag(BindingFlags.GetProperty)
90+
|| processedInvokeAttr.HasFlag(BindingFlags.SetProperty)
9091
|| processedInvokeAttr.HasFlag(BindingFlags.PutDispProperty))
9192
&& !_properties.Any(p => p.Name == name)
9293
&& _fields.Any(p => p.Name == name))
@@ -96,6 +97,11 @@ protected object InvokeStandardMember(string name, BindingFlags invokeAttr, Bind
9697
processedInvokeAttr &= ~BindingFlags.GetProperty;
9798
processedInvokeAttr |= BindingFlags.GetField;
9899
}
100+
else if (processedInvokeAttr.HasFlag(BindingFlags.SetProperty))
101+
{
102+
processedInvokeAttr &= ~BindingFlags.SetProperty;
103+
processedInvokeAttr |= BindingFlags.SetField;
104+
}
99105
else if (processedInvokeAttr.HasFlag(BindingFlags.PutDispProperty))
100106
{
101107
processedInvokeAttr &= ~BindingFlags.PutDispProperty;

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<RepositoryUrl>https://github.com/Taritsyn/MsieJavaScriptEngine</RepositoryUrl>
2121
<RepositoryType>git</RepositoryType>
2222
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
23-
<PackageReleaseNotes>Fixed a error, that occurred in the `Classic` mode during calling an embedded delegate, which does not return a result.</PackageReleaseNotes>
23+
<PackageReleaseNotes>1. Fixed a error, that occurred in the `Classic` mode during calling an embedded delegate, which does not return a result;
24+
2. Fixed a error, that occurred during setting a value to field of embedded type.</PackageReleaseNotes>
2425
<NeutralLanguage>en-US</NeutralLanguage>
2526
<PackageOutputPath>../../nuget</PackageOutputPath>
2627
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/readme.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
Fixed a error, that occurred in the `Classic` mode during calling an embedded
25-
delegate, which does not return a result.
24+
1. Fixed a error, that occurred in the `Classic` mode during calling an embedded
25+
delegate, which does not return a result;
26+
2. Fixed a error, that occurred during setting a value to field of embedded
27+
type.
2628

2729
============
2830
PROJECT SITE
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MsieJavaScriptEngine.Test.Common.Interop.Logging
2+
{
3+
public class DefaultLogger
4+
{
5+
public static ILogger Current = new NullLogger();
6+
}
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MsieJavaScriptEngine.Test.Common.Interop.Logging
2+
{
3+
public interface ILogger
4+
{
5+
void Error(string category, string message,
6+
string filePath = "", int lineNumber = 0, int columnNumber = 0,
7+
string sourceFragment = "");
8+
9+
void Warn(string category, string message,
10+
string filePath = "", int lineNumber = 0, int columnNumber = 0,
11+
string sourceFragment = "");
12+
13+
void Debug(string category, string message, string filePath = "");
14+
15+
void Info(string category, string message, string filePath = "");
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace MsieJavaScriptEngine.Test.Common.Interop.Logging
2+
{
3+
public sealed class NullLogger : ILogger
4+
{
5+
public void Error(string category, string message,
6+
string filePath = "", int lineNumber = 0, int columnNumber = 0,
7+
string sourceFragment = "")
8+
{ }
9+
10+
public void Warn(string category, string message,
11+
string filePath = "", int lineNumber = 0, int columnNumber = 0,
12+
string sourceFragment = "")
13+
{ }
14+
15+
public void Debug(string category, string message, string filePath = "")
16+
{ }
17+
18+
public void Info(string category, string message, string filePath = "")
19+
{ }
20+
21+
public override string ToString()
22+
{
23+
return "[null logger]";
24+
}
25+
}
26+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Text;
3+
4+
namespace MsieJavaScriptEngine.Test.Common.Interop.Logging
5+
{
6+
public sealed class ThrowExceptionLogger : ILogger
7+
{
8+
public void Error(string category, string message, string filePath = "",
9+
int lineNumber = 0, int columnNumber = 0, string sourceFragment = "")
10+
{
11+
var errorBuilder = new StringBuilder();
12+
errorBuilder.AppendLine("Category: " + category);
13+
errorBuilder.AppendLine("Message: " + message);
14+
15+
if (!string.IsNullOrWhiteSpace(filePath))
16+
{
17+
errorBuilder.AppendLine("File: " + filePath);
18+
}
19+
20+
if (lineNumber > 0)
21+
{
22+
errorBuilder.AppendLine("Line number: " + lineNumber);
23+
}
24+
25+
if (columnNumber > 0)
26+
{
27+
errorBuilder.AppendLine("Column number: " + columnNumber);
28+
}
29+
30+
if (!string.IsNullOrWhiteSpace(sourceFragment))
31+
{
32+
errorBuilder.AppendLine("Source fragment:" + Environment.NewLine + sourceFragment);
33+
}
34+
35+
string errorMessage = errorBuilder.ToString();
36+
errorBuilder.Clear();
37+
38+
throw new InvalidOperationException(errorMessage);
39+
}
40+
41+
public void Warn(string category, string message,
42+
string filePath = "", int lineNumber = 0, int columnNumber = 0,
43+
string sourceFragment = "")
44+
{ }
45+
46+
public void Debug(string category, string message, string filePath = "")
47+
{ }
48+
49+
public void Info(string category, string message, string filePath = "")
50+
{ }
51+
52+
public override string ToString()
53+
{
54+
return "[throw exception logger]";
55+
}
56+
}
57+
}

test/MsieJavaScriptEngine.Test.Common/Interop/SimpleSingleton.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#if NETCOREAPP1_0
1515
using MsieJavaScriptEngine.Test.Common.Interop.Drawing;
1616
#endif
17+
using MsieJavaScriptEngine.Test.Common.Interop.Logging;
1718

1819
namespace MsieJavaScriptEngine.Test.Common
1920
{
@@ -934,17 +935,22 @@ public virtual void EmbeddingOfCustomValueTypeWithFieldIsCorrect()
934935
public virtual void EmbeddingOfCustomReferenceTypeWithFieldIsCorrect()
935936
{
936937
// Arrange
937-
Type simpleSingletonType = typeof(SimpleSingleton);
938+
Type defaultLoggerType = typeof(DefaultLogger);
939+
Type throwExceptionLoggerType = typeof(ThrowExceptionLogger);
940+
const string updateCode = "DefaultLogger.Current = new ThrowExceptionLogger();";
938941

939-
const string input = "SimpleSingleton.Instance.ToString()";
940-
const string targetOutput = "[simple singleton]";
942+
const string input = "DefaultLogger.Current.ToString()";
943+
const string targetOutput = "[throw exception logger]";
941944

942945
// Act
943946
string output;
944947

945948
using (var jsEngine = CreateJsEngine())
946949
{
947-
jsEngine.EmbedHostType("SimpleSingleton", simpleSingletonType);
950+
jsEngine.EmbedHostType("DefaultLogger", defaultLoggerType);
951+
jsEngine.EmbedHostType("ThrowExceptionLogger", throwExceptionLoggerType);
952+
jsEngine.Execute(updateCode);
953+
948954
output = jsEngine.Evaluate<string>(input);
949955
}
950956

0 commit comments

Comments
 (0)