Skip to content

Commit b227c68

Browse files
committed
Fixed a error, that occurred in the Classic mode during calling an embedded delegate, which does not return a result
1 parent 1662b93 commit b227c68

File tree

4 files changed

+52
-40
lines changed

4 files changed

+52
-40
lines changed

src/MsieJavaScriptEngine/HostObject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ private object InvokeDelegate(Delegate del, object[] args)
3333

3434
object[] processedArgs = args;
3535

36-
if (_engineMode == JsEngineMode.Classic && processedArgs.Length > 0)
36+
if (_engineMode == JsEngineMode.Classic && processedArgs.Length > 0
37+
&& del.Method.ReturnType != typeof(void))
3738
{
3839
processedArgs = processedArgs.Skip(1).ToArray();
3940
}

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,7 @@
2020
<RepositoryUrl>https://github.com/Taritsyn/MsieJavaScriptEngine</RepositoryUrl>
2121
<RepositoryType>git</RepositoryType>
2222
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
23-
<PackageReleaseNotes>1. Format of the error messages was unified;
24-
2. Created a new exception classes: `JsCompilationException`, `JsEngineException`, `JsFatalException`, `JsInterruptedException`, `JsScriptException` and `JsUsageException`. These exceptions are responsible for handling errors, some of which were previously handled by the `JsRuntimeException` class;
25-
3. In the `JsException` class was added two new properties: `Category` and `Description`;
26-
4. From the `JsRuntimeException` class was removed one property - `ErrorCode`;
27-
5. In the `JsRuntimeException` class was added three new properties: `Type`, `DocumentName` and `CallStack`;
28-
6. `JsEngineLoadException` class now is inherited from the `JsEngineException` class;
29-
7. `Format` method of the `JsErrorHelpers` class was renamed to the `GenerateErrorDetails`;
30-
8. One part of the auxiliary code was removed, and other part moved to an external library - [AdvancedStringBuilder](https://github.com/Taritsyn/AdvancedStringBuilder);
31-
9. Added a ability to interrupt execution of the script;
32-
10. In JsRT modes added a ability to pre-compile scripts;
33-
11. In `MsieJsEngine` class was added `SupportsScriptPrecompilation` property and four new methods: `Interrupt`, `Precompile`, `PrecompileFile` and `PrecompileResource`;
34-
12. In JavaScript engine settings was added one new property - `MaxStackSize` (default `492` or `984` KB);
35-
13. Added support of .NET Standard 2.0 (only supported `ChakraIeJsRt` and `ChakraEdgeJsRt` modes).</PackageReleaseNotes>
23+
<PackageReleaseNotes>Fixed a error, that occurred in the `Classic` mode during calling an embedded delegate, which does not return a result.</PackageReleaseNotes>
3624
<NeutralLanguage>en-US</NeutralLanguage>
3725
<PackageOutputPath>../../nuget</PackageOutputPath>
3826
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/readme.txt

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,8 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
1. Format of the error messages was unified;
25-
2. Created a new exception classes: `JsCompilationException`,
26-
`JsEngineException`, `JsFatalException`, `JsInterruptedException`,
27-
`JsScriptException` and `JsUsageException`. These exceptions are responsible
28-
for handling errors, some of which were previously handled by the
29-
`JsRuntimeException` class;
30-
3. In the `JsException` class was added two new properties: `Category` and
31-
`Description`;
32-
4. From the `JsRuntimeException` class was removed one property - `ErrorCode`;
33-
5. In the `JsRuntimeException` class was added three new properties: `Type`,
34-
`DocumentName` and `CallStack`;
35-
6. `JsEngineLoadException` class now is inherited from the `JsEngineException`
36-
class;
37-
7. `Format` method of the `JsErrorHelpers` class was renamed to the
38-
`GenerateErrorDetails`;
39-
8. One part of the auxiliary code was removed, and other part moved to an
40-
external library - AdvancedStringBuilder;
41-
9. Added a ability to interrupt execution of the script;
42-
10. In JsRT modes added a ability to pre-compile scripts;
43-
11. In `MsieJsEngine` class was added `SupportsScriptPrecompilation` property
44-
and four new methods: `Interrupt`, `Precompile`, `PrecompileFile` and
45-
`PrecompileResource`;
46-
12. In JavaScript engine settings was added one new property - `MaxStackSize`
47-
(default `492` or `984` KB);
48-
13. Added support of .NET Standard 2.0 (only supported `ChakraIeJsRt` and
49-
`ChakraEdgeJsRt` modes).
24+
Fixed a error, that occurred in the `Classic` mode during calling an embedded
25+
delegate, which does not return a result.
5026

5127
============
5228
PROJECT SITE

test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#endif
66
using System.IO;
77
using System.Linq;
8+
using System.Text;
89

910
using NUnit.Framework;
1011

@@ -540,6 +541,52 @@ public virtual void EmbeddingOfInstanceOfDelegateWithTwoParametersIsCorrect()
540541
Assert.AreEqual(targetOutput, output);
541542
}
542543

544+
[Test]
545+
public virtual void EmbeddingOfInstanceOfDelegateWithoutResultIsCorrect()
546+
{
547+
// Arrange
548+
var logBuilder = new StringBuilder();
549+
Action<string> log = (string value) =>
550+
{
551+
logBuilder.AppendLine(value);
552+
};
553+
554+
const string input = @"(function(log, undefined) {
555+
var num = 2, count = 0;
556+
557+
log('-= Start code execution =-');
558+
559+
while (num != Infinity) {
560+
num = num * num;
561+
count++;
562+
}
563+
564+
log('-= End of code execution =-');
565+
566+
return count;
567+
}(log));";
568+
const int targetOutput = 10;
569+
string targetLogOutput = "-= Start code execution =-" + Environment.NewLine +
570+
"-= End of code execution =-" + Environment.NewLine;
571+
572+
// Act
573+
int output;
574+
string logOutput;
575+
576+
using (var jsEngine = CreateJsEngine())
577+
{
578+
jsEngine.EmbedHostObject("log", log);
579+
output = jsEngine.Evaluate<int>(input);
580+
581+
logOutput = logBuilder.ToString();
582+
logBuilder.Clear();
583+
}
584+
585+
// Assert
586+
Assert.AreEqual(targetOutput, output);
587+
Assert.AreEqual(targetLogOutput, logOutput);
588+
}
589+
543590
#endregion
544591

545592
#region Integration

0 commit comments

Comments
 (0)