RegExpMatchesArray.cpp [plain text]
#include "config.h"
#include "RegExpMatchesArray.h"
namespace JSC {
JSArray* createEmptyRegExpMatchesArray(JSGlobalObject* globalObject, JSString* input, RegExp* regExp)
{
VM& vm = globalObject->vm();
JSArray* array;
GCDeferralContext deferralContext(vm.heap);
if (UNLIKELY(globalObject->isHavingABadTime())) {
array = JSArray::tryCreateUninitialized(vm, &deferralContext, globalObject->regExpMatchesArrayStructure(), regExp->numSubpatterns() + 1);
array->initializeIndexWithoutBarrier(0, jsEmptyString(&vm));
if (unsigned numSubpatterns = regExp->numSubpatterns()) {
for (unsigned i = 1; i <= numSubpatterns; ++i)
array->initializeIndexWithoutBarrier(i, jsUndefined());
}
} else {
array = tryCreateUninitializedRegExpMatchesArray(vm, &deferralContext, globalObject->regExpMatchesArrayStructure(), regExp->numSubpatterns() + 1);
RELEASE_ASSERT(array);
array->initializeIndexWithoutBarrier(0, jsEmptyString(&vm), ArrayWithContiguous);
if (unsigned numSubpatterns = regExp->numSubpatterns()) {
for (unsigned i = 1; i <= numSubpatterns; ++i)
array->initializeIndexWithoutBarrier(i, jsUndefined(), ArrayWithContiguous);
}
}
array->putDirectWithoutBarrier(RegExpMatchesArrayIndexPropertyOffset, jsNumber(-1));
array->putDirectWithoutBarrier(RegExpMatchesArrayInputPropertyOffset, input);
return array;
}
static Structure* createStructureImpl(VM& vm, JSGlobalObject* globalObject, IndexingType indexingType)
{
Structure* structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(indexingType);
PropertyOffset offset;
structure = Structure::addPropertyTransition(vm, structure, vm.propertyNames->index, 0, offset);
ASSERT(offset == RegExpMatchesArrayIndexPropertyOffset);
structure = Structure::addPropertyTransition(vm, structure, vm.propertyNames->input, 0, offset);
ASSERT(offset == RegExpMatchesArrayInputPropertyOffset);
return structure;
}
Structure* createRegExpMatchesArrayStructure(VM& vm, JSGlobalObject* globalObject)
{
return createStructureImpl(vm, globalObject, ArrayWithContiguous);
}
Structure* createRegExpMatchesArraySlowPutStructure(VM& vm, JSGlobalObject* globalObject)
{
return createStructureImpl(vm, globalObject, ArrayWithSlowPutArrayStorage);
}
}