Skip to content

v4.1.0

Latest
Compare
Choose a tag to compare
@lahma lahma released this 27 Oct 13:23
· 10 commits to main since this release
04466d0

This release contains a breaking change for interop for static fields and properties. They are no longer exposed as part of interop wrapper by default. You read more about the reasoning here.

To access public static fields or properties you should use registered TypeReferences.

Following example shows the new behavior:

[Fact]
public void StaticFieldsShouldFollowJsSemantics()
{
    _engine.Evaluate("Number.MAX_SAFE_INTEGER").AsNumber().Should().Be(NumberConstructor.MaxSafeInteger);
    _engine.Evaluate("new Number().MAX_SAFE_INTEGER").Should().Be(JsValue.Undefined);

    _engine.Execute("class MyJsClass { static MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; }");
    _engine.Evaluate("MyJsClass.MAX_SAFE_INTEGER").AsNumber().Should().Be(NumberConstructor.MaxSafeInteger);
    _engine.Evaluate("new MyJsClass().MAX_SAFE_INTEGER").Should().Be(JsValue.Undefined);

    _engine.SetValue("MyCsClass", typeof(MyClass));
    _engine.Evaluate("MyCsClass.MAX_SAFE_INTEGER").AsNumber().Should().Be(NumberConstructor.MaxSafeInteger);
    // NEW BEHAVIOR, NOW UNDEFINED
    _engine.Evaluate("new MyCsClass().MAX_SAFE_INTEGER").Should().Be(JsValue.Undefined);
}

private class MyClass
{
    public static JsNumber MAX_SAFE_INTEGER = new JsNumber(NumberConstructor.MaxSafeInteger);
}

If you want to expose static instance fields and properties as part of instance wrappers, you need to configure the engine to do so:

var engine = new Engine(options =>
{
    options.Interop.ObjectWrapperReportedFieldBindingFlags |= BindingFlags.Static;
    options.Interop.ObjectWrapperReportedPropertyBindingFlags |= BindingFlags.Static;
});

Static methods can still be accessed as before, but you could limit exposing them too if you wish to do so:

var engine = new Engine(options =>
{
    options.Interop.ObjectWrapperReportedMethodBindingFlags = BindingFlags.Instance | BindingFlags.Public;
});

What's Changed

  • Fix Array.prototype.toString() stackoverflow by @xBaank in #1976
  • Promise.withResolvers() returned object had resolve and reject functions swapped by @tomatosalat0 in #1983
  • Made test of cancellation of engine execution more robust by @tomatosalat0 in #1984
  • Early out in ObjectPool to avoid loop execution by @tomatosalat0 in #1985
  • Optimize some character checks and ValueStringBuilder by @lahma in #1986
  • Make JsSet public by @kenlyon in #1987
  • Make JsMap public by @lahma in #1988
  • Exclude static fields and properties from ObjectWrapper by default by @lahma in #1981
  • Add Options.InteropOptions.BuildCallStackHandler by @scgm0 in #1793
  • Revert back to favoring SearchValues<char> by @lahma in #1990

New Contributors

Full Changelog: v4.0.3...v4.1.0