#pragma once
#include "DebuggerLocation.h"
#include "JSObject.h"
namespace JSC {
class DebuggerCallFrame;
class JSScope;
class DebuggerScope final : public JSNonFinalObject {
public:
using Base = JSNonFinalObject;
static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetOwnPropertyNames;
template<typename CellType, SubspaceAccess mode>
static IsoSubspace* subspaceFor(VM& vm)
{
return vm.debuggerScopeSpace<mode>();
}
JS_EXPORT_PRIVATE static DebuggerScope* create(VM& vm, JSScope* scope);
static void visitChildren(JSCell*, SlotVisitor&);
static String className(const JSObject*, VM&);
static String toStringName(const JSObject*, JSGlobalObject*);
static bool getOwnPropertySlot(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&);
static bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&);
static bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&);
static void getOwnPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArray&, DontEnumPropertiesMode);
static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
DECLARE_EXPORT_INFO;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject)
{
return Structure::create(vm, globalObject, jsNull(), TypeInfo(ObjectType, StructureFlags), info());
}
class iterator {
public:
iterator(DebuggerScope* node)
: m_node(node)
{
}
DebuggerScope* get() { return m_node; }
iterator& operator++() { m_node = m_node->next(); return *this; }
bool operator==(const iterator& other) const { return m_node == other.m_node; }
bool operator!=(const iterator& other) const { return m_node != other.m_node; }
private:
DebuggerScope* m_node;
};
iterator begin();
iterator end();
DebuggerScope* next();
void invalidateChain();
bool isValid() const { return !!m_scope; }
bool isCatchScope() const;
bool isFunctionNameScope() const;
bool isWithScope() const;
bool isGlobalScope() const;
bool isClosureScope() const;
bool isGlobalLexicalEnvironment() const;
bool isNestedLexicalScope() const;
String name() const;
DebuggerLocation location() const;
JSValue caughtValue(JSGlobalObject*) const;
private:
DebuggerScope(VM&, Structure*, JSScope*);
void finishCreation(VM&);
JSScope* jsScope() const { return m_scope.get(); }
WriteBarrier<JSScope> m_scope;
WriteBarrier<DebuggerScope> m_next;
friend class DebuggerCallFrame;
};
inline DebuggerScope::iterator DebuggerScope::begin()
{
return iterator(this);
}
inline DebuggerScope::iterator DebuggerScope::end()
{
return iterator(nullptr);
}
}