-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check cyclic references when evaluating ToObject
- Loading branch information
Showing
6 changed files
with
113 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using Jint.Native; | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Collections | ||
{ | ||
/// <summary> | ||
/// Helps traversing objects and checks for cyclic references. | ||
/// </summary> | ||
internal sealed class ObjectTraverseStack | ||
{ | ||
private readonly Engine _engine; | ||
private readonly Stack<object> _stack = new(); | ||
|
||
public ObjectTraverseStack(Engine engine) | ||
{ | ||
_engine = engine; | ||
} | ||
|
||
public void Enter(JsValue value) | ||
{ | ||
if (value is null) | ||
{ | ||
ExceptionHelper.ThrowArgumentNullException(nameof(value)); | ||
} | ||
|
||
if (_stack.Contains(value)) | ||
{ | ||
ExceptionHelper.ThrowTypeError(_engine.Realm, "Cyclic reference detected."); | ||
} | ||
|
||
_stack.Push(value); | ||
} | ||
|
||
public void Exit() | ||
{ | ||
_stack.Pop(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters