LazyClassStructure.cpp [plain text]
#include "config.h"
#include "LazyClassStructure.h"
#include "JSCInlines.h"
#include "LazyPropertyInlines.h"
namespace JSC {
LazyClassStructure::Initializer::Initializer(VM& vm, JSGlobalObject* global, LazyClassStructure& classStructure, const StructureInitializer& structureInit)
: vm(vm)
, global(global)
, classStructure(classStructure)
, structureInit(structureInit)
{
}
void LazyClassStructure::Initializer::setPrototype(JSObject* prototype)
{
RELEASE_ASSERT(!this->prototype);
RELEASE_ASSERT(!structure);
RELEASE_ASSERT(!constructor);
this->prototype = prototype;
}
void LazyClassStructure::Initializer::setStructure(Structure* structure)
{
RELEASE_ASSERT(!this->structure);
RELEASE_ASSERT(!constructor);
this->structure = structure;
structureInit.set(structure);
if (!prototype)
prototype = structure->storedPrototypeObject();
}
void LazyClassStructure::Initializer::setConstructor(PropertyName propertyName, JSObject* constructor)
{
RELEASE_ASSERT(structure);
RELEASE_ASSERT(prototype);
RELEASE_ASSERT(!this->constructor);
this->constructor = constructor;
prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
if (!propertyName.isNull())
global->putDirect(vm, propertyName, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
classStructure.m_constructor.set(vm, global, constructor);
}
void LazyClassStructure::Initializer::setConstructor(JSObject* constructor)
{
String name;
if (InternalFunction* internalFunction = jsDynamicCast<InternalFunction*>(vm, constructor))
name = internalFunction->name();
else if (JSFunction* function = jsDynamicCast<JSFunction*>(vm, constructor))
name = function->name(vm);
else
RELEASE_ASSERT_NOT_REACHED();
setConstructor(Identifier::fromString(&vm, name), constructor);
}
void LazyClassStructure::visit(SlotVisitor& visitor)
{
m_structure.visit(visitor);
visitor.append(m_constructor);
}
void LazyClassStructure::dump(PrintStream& out) const
{
out.print("<structure = ", m_structure, ", constructor = ", RawPointer(m_constructor.get()), ">");
}
}