diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp | 127 |
1 files changed, 48 insertions, 79 deletions
diff --git a/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp b/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp index 3eb462240..0dc05c6c4 100644 --- a/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp +++ b/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2012-2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,99 +26,68 @@ #include "config.h" #include "RegExpMatchesArray.h" -#include "ButterflyInlines.h" -#include "Operations.h" - namespace JSC { -const ClassInfo RegExpMatchesArray::s_info = {"Array", &JSArray::s_info, 0, 0, CREATE_METHOD_TABLE(RegExpMatchesArray)}; - -RegExpMatchesArray::RegExpMatchesArray(VM& vm, Butterfly* butterfly, JSGlobalObject* globalObject, JSString* input, RegExp* regExp, MatchResult result) - : JSArray(vm, globalObject->regExpMatchesArrayStructure(), butterfly) - , m_result(result) - , m_state(ReifiedNone) -{ - m_input.set(vm, this, input); - m_regExp.set(vm, this, regExp); -} - -RegExpMatchesArray* RegExpMatchesArray::create(ExecState* exec, JSString* input, RegExp* regExp, MatchResult result) +JSArray* createEmptyRegExpMatchesArray(JSGlobalObject* globalObject, JSString* input, RegExp* regExp) { - ASSERT(result); - VM& vm = exec->vm(); - Butterfly* butterfly = createArrayButterfly(vm, 0, regExp->numSubpatterns() + 1); - RegExpMatchesArray* array = new (NotNull, allocateCell<RegExpMatchesArray>(vm.heap)) RegExpMatchesArray(vm, butterfly, exec->lexicalGlobalObject(), input, regExp, result); - array->finishCreation(vm); - return array; -} - -void RegExpMatchesArray::finishCreation(VM& vm) -{ - Base::finishCreation(vm); -} - -void RegExpMatchesArray::visitChildren(JSCell* cell, SlotVisitor& visitor) -{ - RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell); - ASSERT_GC_OBJECT_INHERITS(thisObject, info()); - COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); - ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); - - Base::visitChildren(thisObject, visitor); - visitor.append(&thisObject->m_input); - visitor.append(&thisObject->m_regExp); -} - -void RegExpMatchesArray::reifyAllProperties(ExecState* exec) -{ - ASSERT(m_state != ReifiedAll); - ASSERT(m_result); - - reifyMatchPropertyIfNecessary(exec); - - if (unsigned numSubpatterns = m_regExp->numSubpatterns()) { - Vector<int, 32> subpatternResults; - int position = m_regExp->match(exec->vm(), m_input->value(exec), m_result.start, subpatternResults); - ASSERT_UNUSED(position, position >= 0 && static_cast<size_t>(position) == m_result.start); - ASSERT(m_result.start == static_cast<size_t>(subpatternResults[0])); - ASSERT(m_result.end == static_cast<size_t>(subpatternResults[1])); - - for (unsigned i = 1; i <= numSubpatterns; ++i) { - int start = subpatternResults[2 * i]; - if (start >= 0) - putDirectIndex(exec, i, jsSubstring(exec, m_input.get(), start, subpatternResults[2 * i + 1] - start)); - else - putDirectIndex(exec, i, jsUndefined()); + VM& vm = globalObject->vm(); + JSArray* array; + + // FIXME: This should handle array allocation errors gracefully. + // https://bugs.webkit.org/show_bug.cgi?id=155144 + + GCDeferralContext deferralContext(vm.heap); + + if (UNLIKELY(globalObject->isHavingABadTime())) { + array = JSArray::tryCreateForInitializationPrivate(vm, &deferralContext, globalObject->regExpMatchesArrayStructure(), regExp->numSubpatterns() + 1); + // FIXME: we should probably throw an out of memory error here, but + // when making this change we should check that all clients of this + // function will correctly handle an exception being thrown from here. + // https://bugs.webkit.org/show_bug.cgi?id=169786 + RELEASE_ASSERT(array); + + 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); } } - putDirect(exec->vm(), exec->propertyNames().index, jsNumber(m_result.start)); - putDirect(exec->vm(), exec->propertyNames().input, m_input.get()); - - m_state = ReifiedAll; + array->putDirectWithoutBarrier(RegExpMatchesArrayIndexPropertyOffset, jsNumber(-1)); + array->putDirectWithoutBarrier(RegExpMatchesArrayInputPropertyOffset, input); + return array; } -void RegExpMatchesArray::reifyMatchProperty(ExecState* exec) +static Structure* createStructureImpl(VM& vm, JSGlobalObject* globalObject, IndexingType indexingType) { - ASSERT(m_state == ReifiedNone); - ASSERT(m_result); - putDirectIndex(exec, 0, jsSubstring(exec, m_input.get(), m_result.start, m_result.end - m_result.start)); - m_state = ReifiedMatch; + 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; } -JSString* RegExpMatchesArray::leftContext(ExecState* exec) +Structure* createRegExpMatchesArrayStructure(VM& vm, JSGlobalObject* globalObject) { - if (!m_result.start) - return jsEmptyString(exec); - return jsSubstring(exec, m_input.get(), 0, m_result.start); + return createStructureImpl(vm, globalObject, ArrayWithContiguous); } -JSString* RegExpMatchesArray::rightContext(ExecState* exec) +Structure* createRegExpMatchesArraySlowPutStructure(VM& vm, JSGlobalObject* globalObject) { - unsigned length = m_input->length(); - if (m_result.end == length) - return jsEmptyString(exec); - return jsSubstring(exec, m_input.get(), m_result.end, length - m_result.end); + return createStructureImpl(vm, globalObject, ArrayWithSlowPutArrayStorage); } } // namespace JSC |