// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_DEBUG_DEBUG_SCOPES_H_ #define V8_DEBUG_DEBUG_SCOPES_H_ #include "src/debug/debug-frames.h" #include "src/parsing/parse-info.h" namespace v8 { namespace internal { class JavaScriptFrame; class ParseInfo; // Iterate over the actual scopes visible from a stack frame or from a closure. // The iteration proceeds from the innermost visible nested scope outwards. // All scopes are backed by an actual context except the local scope, // which is inserted "artificially" in the context chain. class ScopeIterator { public: enum ScopeType { ScopeTypeGlobal = 0, ScopeTypeLocal, ScopeTypeWith, ScopeTypeClosure, ScopeTypeCatch, ScopeTypeBlock, ScopeTypeScript, ScopeTypeEval, ScopeTypeModule }; static const int kScopeDetailsTypeIndex = 0; static const int kScopeDetailsObjectIndex = 1; static const int kScopeDetailsNameIndex = 2; static const int kScopeDetailsStartPositionIndex = 3; static const int kScopeDetailsEndPositionIndex = 4; static const int kScopeDetailsFunctionIndex = 5; static const int kScopeDetailsSize = 6; enum class ReparseStrategy { kScript, kFunctionLiteral, }; ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, ReparseStrategy strategy); ScopeIterator(Isolate* isolate, Handle function); ScopeIterator(Isolate* isolate, Handle generator); ~ScopeIterator(); Handle MaterializeScopeDetails(); // More scopes? bool Done() const { return context_.is_null(); } // Move to the next scope. void Next(); // Restart to the first scope and context. void Restart(); // Return the type of the current scope. ScopeType Type() const; // Indicates which variables should be visited. Either only variables from the // scope that are available on the stack, or all variables. enum class Mode { STACK, ALL }; // Return the JavaScript object with the content of the current scope. Handle ScopeObject(Mode mode); // Returns whether the current scope declares any variables. bool DeclaresLocals(Mode mode) const; // Set variable value and return true on success. bool SetVariableValue(Handle variable_name, Handle new_value); bool ClosureScopeHasThisReference() const; // Populate the set with collected non-local variable names. Handle GetLocals() { return locals_; } // Similar to JSFunction::GetName return the function's name or it's inferred // name. Handle GetFunctionDebugName() const; Handle