Skip to content

How do I get the return object in 7.5? #672

Description

@MF91WorkPS

Hi,

after an update of ClearScript from version 7.4.5 to the current version 7.5 an automatic test partially fails, because the new version does not return the expected objects. The test setup with the failing test cases in .NET 9 with xUnit is:

using Microsoft.ClearScript;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.V8;
using Xunit;

[Theory]
[InlineData("test1.js", "test(); function test() {return \"test\";}", "test")]
[InlineData("test2.js", "test(); function test() {return true;}", true)]
[InlineData("test3.js", "test(); function test() {return false;}", false)]
public void RunTests(string scriptName, string scriptCode, object expectedResult)
{
    //Assign
    using var runtime = new V8Runtime("V8RuntimeTest");
    using var engine = new V8ScriptEngine("V8ScriptEngineTest");

    //Act
    var info = new DocumentInfo(scriptName) { Category = ModuleCategory.Standard };
    var actualResult = engine.Evaluate(info, scriptCode);

    //Assert
    Assert.Equal(expectedResult, actualResult);
}

Depending on the version, the following results are returned:

Script Code Returns in 7.4.5 Returns in 7.5
test1.js test(); function test() {return "test";} "test" Microsoft.ClearScript.Undefined
test2.js test(); function test() {return true;} true Microsoft.ClearScript.Undefined
test3.js test(); function test() {return false;} false Microsoft.ClearScript.Undefined

This is an issue for us, because we for example use ClearScript for user-defined data conversion scripts. Is it an intended change that the object is no longer returned? If yes, is there a way I get the return value by using a configuration setting or updating my code?

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions