PolyProtoAccessChain.h [plain text]
#pragma once
#include "StructureIDTable.h"
#include "VM.h"
#include <wtf/Vector.h>
namespace JSC {
class JSCell;
class JSGlobalObject;
class JSObject;
class PropertySlot;
class Structure;
class PolyProtoAccessChain {
WTF_MAKE_FAST_ALLOCATED;
public:
PolyProtoAccessChain(PolyProtoAccessChain&) = default;
static std::unique_ptr<PolyProtoAccessChain> create(JSGlobalObject*, JSCell* base, const PropertySlot&);
static std::unique_ptr<PolyProtoAccessChain> create(JSGlobalObject*, JSCell* base, JSObject* target);
std::unique_ptr<PolyProtoAccessChain> clone()
{
return makeUnique<PolyProtoAccessChain>(*this);
}
const Vector<StructureID>& chain() const { return m_chain; }
void dump(Structure* baseStructure, PrintStream& out) const;
bool operator==(const PolyProtoAccessChain& other) const;
bool operator!=(const PolyProtoAccessChain& other) const
{
return !(*this == other);
}
bool needImpurePropertyWatchpoint(VM&) const;
template <typename Func>
void forEach(VM& vm, Structure* baseStructure, const Func& func) const
{
bool atEnd = !m_chain.size();
func(baseStructure, atEnd);
for (unsigned i = 0; i < m_chain.size(); ++i) {
atEnd = i + 1 == m_chain.size();
func(vm.getStructure(m_chain[i]), atEnd);
}
}
Structure* slotBaseStructure(VM& vm, Structure* baseStructure) const
{
if (m_chain.size())
return vm.getStructure(m_chain.last());
return baseStructure;
}
private:
PolyProtoAccessChain() = default;
Vector<StructureID> m_chain;
};
}