TemplateRegistry.cpp [plain text]
#include "config.h"
#include "TemplateRegistry.h"
#include "JSCJSValueInlines.h"
#include "JSGlobalObject.h"
#include "ObjectConstructor.h"
#include "StructureInlines.h"
#include "WeakGCMapInlines.h"
namespace JSC {
TemplateRegistry::TemplateRegistry(VM& vm)
: m_templateMap(vm)
{
}
JSArray* TemplateRegistry::getTemplateObject(ExecState* exec, const TemplateRegistryKey& templateKey)
{
JSArray* cached = m_templateMap.get(templateKey);
if (cached)
return cached;
VM& vm = exec->vm();
unsigned count = templateKey.cookedStrings().size();
JSArray* templateObject = constructEmptyArray(exec, nullptr, count);
if (UNLIKELY(vm.exception()))
return nullptr;
JSArray* rawObject = constructEmptyArray(exec, nullptr, count);
if (UNLIKELY(vm.exception()))
return nullptr;
for (unsigned index = 0; index < count; ++index) {
templateObject->putDirectIndex(exec, index, jsString(exec, templateKey.cookedStrings()[index]), ReadOnly | DontDelete, PutDirectIndexLikePutDirect);
rawObject->putDirectIndex(exec, index, jsString(exec, templateKey.rawStrings()[index]), ReadOnly | DontDelete, PutDirectIndexLikePutDirect);
}
objectConstructorFreeze(exec, rawObject);
ASSERT(!exec->hadException());
templateObject->putDirect(vm, exec->propertyNames().raw, rawObject, ReadOnly | DontEnum | DontDelete);
objectConstructorFreeze(exec, templateObject);
ASSERT(!exec->hadException());
m_templateMap.set(templateKey, templateObject);
return templateObject;
}
}