Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable object identity tracking by default under interop #1466

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Jint.Tests/Runtime/WeakSetMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void WeakMapSetShouldThrowForPrimitiveKey(JsValue key)
[Fact]
public void WeakSetWithInteropObject()
{
var engine = new Engine();
var engine = new Engine(options => options.Interop.TrackObjectWrapperIdentity = true);

engine.SetValue("context", new { Item = new Item { Value = "Test" } });

Expand All @@ -89,7 +89,7 @@ public void StringifyWithoutCircularReferences()
parent.Child = child;
child.Parent = parent;

var engine = new Engine();
var engine = new Engine(options => options.Interop.TrackObjectWrapperIdentity = true);

engine.SetValue("context", new { Parent = parent });

Expand Down
12 changes: 5 additions & 7 deletions Jint/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,18 @@ public class InteropOptions
public List<IObjectConverter> ObjectConverters { get; } = new();

/// <summary>
/// Whether identity map is persisted for object wrappers in order to maintain object identity.
/// Defaults to true.
/// Whether identity map is persisted for object wrappers in order to maintain object identity. This can cause
/// memory usage to grow when targeting large set and freeing of memory can be delayed due to ConditionalWeakTable semantics.
/// Defaults to false.
/// </summary>
public bool TrackObjectWrapperIdentity { get; set; } = true;
public bool TrackObjectWrapperIdentity { get; set; } = false;

/// <summary>
/// If no known type could be guessed, objects are by default wrapped as an
/// ObjectInstance using class ObjectWrapper. This function can be used to
/// change the behavior.
/// </summary>
public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target) =>
{
return new ObjectWrapper(engine, target);
};
public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target) => new ObjectWrapper(engine, target);

/// <summary>
///
Expand Down