using Jint.Native; using Jint.Runtime.CallStack; using Environment = Jint.Runtime.Environments.Environment; namespace Jint.Runtime.Debugger; public sealed class CallFrame { private readonly CallStackExecutionContext _context; private SourceLocation _location; private readonly CallStackElement? _element; private readonly Lazy _scopeChain; internal CallFrame( CallStackElement? element, in CallStackExecutionContext context, in SourceLocation location, JsValue? returnValue) { _element = element; _context = context; _location = location; ReturnValue = returnValue; _scopeChain = new Lazy(() => new DebugScopes(Environment)); } private Environment Environment => _context.LexicalEnvironment; // TODO: CallFrameId /// /// Name of the function of this call frame. For global scope, this will be "(anonymous)". /// public string FunctionName => _element?.ToString() ?? "(anonymous)"; /// /// Source location of function of this call frame. /// /// For top level (global) call frames, as well as functions not defined in script, this will be null. public SourceLocation? FunctionLocation => (_element?.Function._functionDefinition?.Function as Node)?.Location; /// /// Currently executing source location in this call frame. /// public ref SourceLocation Location => ref _location; /// /// The scope chain of this call frame. /// public DebugScopes ScopeChain => _scopeChain.Value; /// /// The value of this in this call frame. /// public JsValue This { get { var environment = _context.GetThisEnvironment(); return environment.GetThisBinding(); } } /// /// The return value of this call frame. Will be null for call frames that aren't at the top of the stack, /// as well as if execution is not at a return point. /// public JsValue? ReturnValue { get; } }