TemplateRegistry.cpp [plain text]
#include "config.h"
#include "TemplateRegistry.h"
#include "BuiltinNames.h"
#include "JSCInlines.h"
#include "JSGlobalObject.h"
#include "JSTemplateRegistryKey.h"
#include "ObjectConstructor.h"
#include "TemplateRegistryKey.h"
#include "WeakGCMapInlines.h"
namespace JSC {
TemplateRegistry::TemplateRegistry(VM& vm)
: m_templateMap(vm)
{
}
JSArray* TemplateRegistry::getTemplateObject(ExecState* exec, JSTemplateRegistryKey* templateKeyObject)
{
auto& templateKey = templateKeyObject->templateRegistryKey();
JSArray* cached = m_templateMap.get(&templateKey);
if (cached)
return cached;
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
unsigned count = templateKey.cookedStrings().size();
JSArray* templateObject = constructEmptyArray(exec, nullptr, count);
RETURN_IF_EXCEPTION(scope, nullptr);
JSArray* rawObject = constructEmptyArray(exec, nullptr, count);
RETURN_IF_EXCEPTION(scope, nullptr);
for (unsigned index = 0; index < count; ++index) {
auto cooked = templateKey.cookedStrings()[index];
if (cooked)
templateObject->putDirectIndex(exec, index, jsString(exec, cooked.value()), PropertyAttribute::ReadOnly | PropertyAttribute::DontDelete, PutDirectIndexLikePutDirect);
else
templateObject->putDirectIndex(exec, index, jsUndefined(), PropertyAttribute::ReadOnly | PropertyAttribute::DontDelete, PutDirectIndexLikePutDirect);
RETURN_IF_EXCEPTION(scope, nullptr);
rawObject->putDirectIndex(exec, index, jsString(exec, templateKey.rawStrings()[index]), PropertyAttribute::ReadOnly | PropertyAttribute::DontDelete, PutDirectIndexLikePutDirect);
RETURN_IF_EXCEPTION(scope, nullptr);
}
objectConstructorFreeze(exec, rawObject);
scope.assertNoException();
templateObject->putDirect(vm, vm.propertyNames->raw, rawObject, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
templateObject->putDirect(vm, vm.propertyNames->builtinNames().templateRegistryKeyPrivateName(), templateKeyObject, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
objectConstructorFreeze(exec, templateObject);
scope.assertNoException();
m_templateMap.set(&templateKey, templateObject);
return templateObject;
}
}