summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/yarr
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-09-13 12:51:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 20:50:05 +0200
commitd441d6f39bb846989d95bcf5caf387b42414718d (patch)
treee367e64a75991c554930278175d403c072de6bb8 /Source/JavaScriptCore/yarr
parent0060b2994c07842f4c59de64b5e3e430525c4b90 (diff)
downloadqtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit. Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/JavaScriptCore/yarr')
-rw-r--r--Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.h6
-rw-r--r--Source/JavaScriptCore/yarr/YarrInterpreter.cpp59
-rw-r--r--Source/JavaScriptCore/yarr/YarrInterpreter.h25
-rw-r--r--Source/JavaScriptCore/yarr/YarrJIT.cpp39
-rw-r--r--Source/JavaScriptCore/yarr/YarrJIT.h6
-rw-r--r--Source/JavaScriptCore/yarr/YarrParser.h4
-rw-r--r--Source/JavaScriptCore/yarr/YarrPattern.cpp76
-rw-r--r--Source/JavaScriptCore/yarr/YarrPattern.h68
8 files changed, 131 insertions, 152 deletions
diff --git a/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.h b/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.h
index be0ead43d..9dce78200 100644
--- a/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.h
+++ b/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.h
@@ -93,9 +93,9 @@ inline UChar getCanonicalPair(UCS2CanonicalizationRange* info, UChar ch)
case CanonicalizeAlternatingUnaligned:
return ((ch - 1) ^ 1) + 1;
default:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return 0;
}
@@ -129,7 +129,7 @@ inline bool areCanonicallyEquivalent(UChar a, UChar b)
return ((a - 1) | 1) == ((b - 1) | 1);
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return false;
}
diff --git a/Source/JavaScriptCore/yarr/YarrInterpreter.cpp b/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
index 31603f6d3..f0312ea25 100644
--- a/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
+++ b/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
@@ -83,8 +83,8 @@ public:
static inline void popParenthesesDisjunctionContext(BackTrackInfoParentheses* backTrack)
{
- ASSERT(backTrack->matchAmount);
- ASSERT(backTrack->lastContext);
+ RELEASE_ASSERT(backTrack->matchAmount);
+ RELEASE_ASSERT(backTrack->lastContext);
backTrack->lastContext = backTrack->lastContext->next;
--backTrack->matchAmount;
}
@@ -111,8 +111,7 @@ public:
{
size_t size = sizeof(DisjunctionContext) - sizeof(uintptr_t) + disjunction->m_frameSize * sizeof(uintptr_t);
allocatorPool = allocatorPool->ensureCapacity(size);
- if (!allocatorPool)
- CRASH();
+ RELEASE_ASSERT(allocatorPool);
return new (allocatorPool->alloc(size)) DisjunctionContext();
}
@@ -161,8 +160,7 @@ public:
{
size_t size = sizeof(ParenthesesDisjunctionContext) - sizeof(unsigned) + (term.atom.parenthesesDisjunction->m_numSubpatterns << 1) * sizeof(unsigned) + sizeof(DisjunctionContext) - sizeof(uintptr_t) + disjunction->m_frameSize * sizeof(uintptr_t);
allocatorPool = allocatorPool->ensureCapacity(size);
- if (!allocatorPool)
- CRASH();
+ RELEASE_ASSERT(allocatorPool);
return new (allocatorPool->alloc(size)) ParenthesesDisjunctionContext(output, term);
}
@@ -207,8 +205,7 @@ public:
int readChecked(unsigned negativePositionOffest)
{
- if (pos < negativePositionOffest)
- CRASH();
+ RELEASE_ASSERT(pos >= negativePositionOffest);
unsigned p = pos - negativePositionOffest;
ASSERT(p < length);
return input[p];
@@ -264,8 +261,7 @@ public:
void uncheckInput(unsigned count)
{
- if (pos < count)
- CRASH();
+ RELEASE_ASSERT(pos >= count);
pos -= count;
}
@@ -276,8 +272,7 @@ public:
bool atEnd(unsigned negativePositionOffest)
{
- if (pos < negativePositionOffest)
- CRASH();
+ RELEASE_ASSERT(pos >= negativePositionOffest);
return (pos - negativePositionOffest) == length;
}
@@ -485,7 +480,7 @@ public:
return true;
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return false;
}
@@ -567,7 +562,7 @@ public:
return true;
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return false;
}
@@ -801,7 +796,7 @@ public:
{
// 'Terminal' parentheses are at the end of the regex, and as such a match past end
// should always be returned as a successful match - we should never backtrack to here.
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return false;
}
@@ -927,7 +922,7 @@ public:
return JSRegExpMatch;
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return JSRegExpErrorNoMatch;
}
@@ -1067,7 +1062,7 @@ public:
}
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return JSRegExpErrorNoMatch;
}
@@ -1273,7 +1268,7 @@ public:
}
// We should never fall-through to here.
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
backtrack:
ASSERT(context->term < static_cast<int>(disjunction->terms.size()));
@@ -1282,7 +1277,7 @@ public:
case ByteTerm::TypeSubpatternBegin:
return JSRegExpNoMatch;
case ByteTerm::TypeSubpatternEnd:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
case ByteTerm::TypeBodyAlternativeBegin:
case ByteTerm::TypeBodyAlternativeDisjunction: {
@@ -1304,7 +1299,7 @@ public:
MATCH_NEXT();
}
case ByteTerm::TypeBodyAlternativeEnd:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
case ByteTerm::TypeAlternativeBegin:
case ByteTerm::TypeAlternativeDisjunction: {
@@ -1393,10 +1388,10 @@ public:
BACKTRACK();
case ByteTerm::TypeDotStarEnclosure:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
}
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
return JSRegExpErrorNoMatch;
}
@@ -1425,8 +1420,7 @@ public:
output[i << 1] = offsetNoMatch;
allocatorPool = pattern->m_allocator->startAllocator();
- if (!allocatorPool)
- CRASH();
+ RELEASE_ASSERT(allocatorPool);
DisjunctionContext* context = allocDisjunctionContext(pattern->m_body.get());
@@ -1461,8 +1455,6 @@ private:
unsigned remainingMatchCount;
};
-
-
class ByteCompiler {
struct ParenthesesStackEntry {
unsigned beginTerm;
@@ -1718,17 +1710,20 @@ public:
unsigned subpatternId = parenthesesBegin.atom.subpatternId;
unsigned numSubpatterns = lastSubpatternId - subpatternId + 1;
- ByteDisjunction* parenthesesDisjunction = new ByteDisjunction(numSubpatterns, callFrameSize);
+ OwnPtr<ByteDisjunction> parenthesesDisjunction = adoptPtr(new ByteDisjunction(numSubpatterns, callFrameSize));
+
+ unsigned firstTermInParentheses = beginTerm + 1;
+ parenthesesDisjunction->terms.reserveInitialCapacity(endTerm - firstTermInParentheses + 2);
parenthesesDisjunction->terms.append(ByteTerm::SubpatternBegin());
- for (unsigned termInParentheses = beginTerm + 1; termInParentheses < endTerm; ++termInParentheses)
+ for (unsigned termInParentheses = firstTermInParentheses; termInParentheses < endTerm; ++termInParentheses)
parenthesesDisjunction->terms.append(m_bodyDisjunction->terms[termInParentheses]);
parenthesesDisjunction->terms.append(ByteTerm::SubpatternEnd());
m_bodyDisjunction->terms.shrink(beginTerm);
- m_allParenthesesInfo.append(parenthesesDisjunction);
- m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParenthesesSubpattern, subpatternId, parenthesesDisjunction, capture, inputPosition));
+ m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParenthesesSubpattern, subpatternId, parenthesesDisjunction.get(), capture, inputPosition));
+ m_allParenthesesInfo.append(parenthesesDisjunction.release());
m_bodyDisjunction->terms[beginTerm].atom.quantityCount = quantityCount.unsafeGet();
m_bodyDisjunction->terms[beginTerm].atom.quantityType = quantityType;
@@ -1815,7 +1810,7 @@ public:
for (unsigned alt = 0; alt < disjunction->m_alternatives.size(); ++alt) {
unsigned currentCountAlreadyChecked = inputCountAlreadyChecked;
- PatternAlternative* alternative = disjunction->m_alternatives[alt];
+ PatternAlternative* alternative = disjunction->m_alternatives[alt].get();
if (alt) {
if (disjunction == m_pattern.m_body)
@@ -1926,7 +1921,7 @@ private:
OwnPtr<ByteDisjunction> m_bodyDisjunction;
unsigned m_currentAlternativeIndex;
Vector<ParenthesesStackEntry> m_parenthesesStack;
- Vector<ByteDisjunction*> m_allParenthesesInfo;
+ Vector<OwnPtr<ByteDisjunction> > m_allParenthesesInfo;
};
PassOwnPtr<BytecodePattern> byteCompile(YarrPattern& pattern, BumpPointerAllocator* allocator)
diff --git a/Source/JavaScriptCore/yarr/YarrInterpreter.h b/Source/JavaScriptCore/yarr/YarrInterpreter.h
index fb60bd979..bb64e6d91 100644
--- a/Source/JavaScriptCore/yarr/YarrInterpreter.h
+++ b/Source/JavaScriptCore/yarr/YarrInterpreter.h
@@ -337,42 +337,37 @@ public:
struct BytecodePattern {
WTF_MAKE_FAST_ALLOCATED;
public:
- BytecodePattern(PassOwnPtr<ByteDisjunction> body, Vector<ByteDisjunction*> allParenthesesInfo, YarrPattern& pattern, BumpPointerAllocator* allocator)
+ BytecodePattern(PassOwnPtr<ByteDisjunction> body, Vector<OwnPtr<ByteDisjunction> >& parenthesesInfoToAdopt, YarrPattern& pattern, BumpPointerAllocator* allocator)
: m_body(body)
, m_ignoreCase(pattern.m_ignoreCase)
, m_multiline(pattern.m_multiline)
, m_allocator(allocator)
{
+ m_body->terms.shrinkToFit();
+
newlineCharacterClass = pattern.newlineCharacterClass();
wordcharCharacterClass = pattern.wordcharCharacterClass();
- m_allParenthesesInfo.append(allParenthesesInfo);
- m_userCharacterClasses.append(pattern.m_userCharacterClasses);
- // 'Steal' the YarrPattern's CharacterClasses! We clear its
- // array, so that it won't delete them on destruction. We'll
- // take responsibility for that.
- pattern.m_userCharacterClasses.clear();
- }
+ m_allParenthesesInfo.swap(parenthesesInfoToAdopt);
+ m_allParenthesesInfo.shrinkToFit();
- ~BytecodePattern()
- {
- deleteAllValues(m_allParenthesesInfo);
- deleteAllValues(m_userCharacterClasses);
+ m_userCharacterClasses.swap(pattern.m_userCharacterClasses);
+ m_userCharacterClasses.shrinkToFit();
}
OwnPtr<ByteDisjunction> m_body;
bool m_ignoreCase;
bool m_multiline;
// Each BytecodePattern is associated with a RegExp, each RegExp is associated
- // with a JSGlobalData. Cache a pointer to out JSGlobalData's m_regExpAllocator.
+ // with a VM. Cache a pointer to out VM's m_regExpAllocator.
BumpPointerAllocator* m_allocator;
CharacterClass* newlineCharacterClass;
CharacterClass* wordcharCharacterClass;
private:
- Vector<ByteDisjunction*> m_allParenthesesInfo;
- Vector<CharacterClass*> m_userCharacterClasses;
+ Vector<OwnPtr<ByteDisjunction> > m_allParenthesesInfo;
+ Vector<OwnPtr<CharacterClass> > m_userCharacterClasses;
};
JS_EXPORT_PRIVATE PassOwnPtr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
diff --git a/Source/JavaScriptCore/yarr/YarrJIT.cpp b/Source/JavaScriptCore/yarr/YarrJIT.cpp
index 1aef49bdf..1b2b03131 100644
--- a/Source/JavaScriptCore/yarr/YarrJIT.cpp
+++ b/Source/JavaScriptCore/yarr/YarrJIT.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,7 +40,7 @@ namespace JSC { namespace Yarr {
template<YarrJITCompileMode compileMode>
class YarrGenerator : private MacroAssembler {
- friend void jitCompile(JSGlobalData*, YarrCodeBlock& jitObject, const String& pattern, unsigned& numSubpatterns, const char*& error, bool ignoreCase, bool multiline);
+ friend void jitCompile(VM*, YarrCodeBlock& jitObject, const String& pattern, unsigned& numSubpatterns, const char*& error, bool ignoreCase, bool multiline);
#if CPU(ARM)
static const RegisterID input = ARMRegisters::r0;
@@ -179,8 +179,8 @@ class YarrGenerator : private MacroAssembler {
void matchCharacterClass(RegisterID character, JumpList& matchDest, const CharacterClass* charClass)
{
if (charClass->m_table) {
- ExtendedAddress tableEntry(character, reinterpret_cast<intptr_t>(charClass->m_table->m_table));
- matchDest.append(branchTest8(charClass->m_table->m_inverted ? Zero : NonZero, tableEntry));
+ ExtendedAddress tableEntry(character, reinterpret_cast<intptr_t>(charClass->m_table));
+ matchDest.append(branchTest8(charClass->m_tableInverted ? Zero : NonZero, tableEntry));
return;
}
Jump unicodeFail;
@@ -1265,7 +1265,7 @@ class YarrGenerator : private MacroAssembler {
case PatternTerm::TypeParenthesesSubpattern:
case PatternTerm::TypeParentheticalAssertion:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
case PatternTerm::TypeBackReference:
m_shouldFallBack = true;
break;
@@ -1331,7 +1331,7 @@ class YarrGenerator : private MacroAssembler {
case PatternTerm::TypeParenthesesSubpattern:
case PatternTerm::TypeParentheticalAssertion:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
case PatternTerm::TypeDotStarEnclosure:
backtrackDotStarEnclosure(opIndex);
@@ -2325,11 +2325,11 @@ class YarrGenerator : private MacroAssembler {
m_ops.append(alternativeBeginOpCode);
m_ops.last().m_previousOp = notFound;
m_ops.last().m_term = term;
- Vector<PatternAlternative*>& alternatives = term->parentheses.disjunction->m_alternatives;
+ Vector<OwnPtr<PatternAlternative> >& alternatives = term->parentheses.disjunction->m_alternatives;
for (unsigned i = 0; i < alternatives.size(); ++i) {
size_t lastOpIndex = m_ops.size() - 1;
- PatternAlternative* nestedAlternative = alternatives[i];
+ PatternAlternative* nestedAlternative = alternatives[i].get();
opCompileAlternative(nestedAlternative);
size_t thisOpIndex = m_ops.size();
@@ -2376,11 +2376,11 @@ class YarrGenerator : private MacroAssembler {
m_ops.append(OpSimpleNestedAlternativeBegin);
m_ops.last().m_previousOp = notFound;
m_ops.last().m_term = term;
- Vector<PatternAlternative*>& alternatives = term->parentheses.disjunction->m_alternatives;
+ Vector<OwnPtr<PatternAlternative> >& alternatives = term->parentheses.disjunction->m_alternatives;
for (unsigned i = 0; i < alternatives.size(); ++i) {
size_t lastOpIndex = m_ops.size() - 1;
- PatternAlternative* nestedAlternative = alternatives[i];
+ PatternAlternative* nestedAlternative = alternatives[i].get();
opCompileAlternative(nestedAlternative);
size_t thisOpIndex = m_ops.size();
@@ -2450,7 +2450,7 @@ class YarrGenerator : private MacroAssembler {
// to return the failing result.
void opCompileBody(PatternDisjunction* disjunction)
{
- Vector<PatternAlternative*>& alternatives = disjunction->m_alternatives;
+ Vector<OwnPtr<PatternAlternative> >& alternatives = disjunction->m_alternatives;
size_t currentAlternativeIndex = 0;
// Emit the 'once through' alternatives.
@@ -2460,7 +2460,7 @@ class YarrGenerator : private MacroAssembler {
do {
size_t lastOpIndex = m_ops.size() - 1;
- PatternAlternative* alternative = alternatives[currentAlternativeIndex];
+ PatternAlternative* alternative = alternatives[currentAlternativeIndex].get();
opCompileAlternative(alternative);
size_t thisOpIndex = m_ops.size();
@@ -2495,7 +2495,7 @@ class YarrGenerator : private MacroAssembler {
m_ops.last().m_previousOp = notFound;
do {
size_t lastOpIndex = m_ops.size() - 1;
- PatternAlternative* alternative = alternatives[currentAlternativeIndex];
+ PatternAlternative* alternative = alternatives[currentAlternativeIndex].get();
ASSERT(!alternative->onceThrough());
opCompileAlternative(alternative);
@@ -2524,6 +2524,9 @@ class YarrGenerator : private MacroAssembler {
push(X86Registers::ebp);
move(stackPointerRegister, X86Registers::ebp);
push(X86Registers::ebx);
+ // The ABI doesn't guarantee the upper bits are zero on unsigned arguments, so clear them ourselves.
+ zeroExtend32ToPtr(index, index);
+ zeroExtend32ToPtr(length, length);
#if OS(WINDOWS)
if (compileMode == IncludeSubpatterns)
loadPtr(Address(X86Registers::ebp, 6 * sizeof(void*)), output);
@@ -2605,7 +2608,7 @@ public:
{
}
- void compile(JSGlobalData* globalData, YarrCodeBlock& jitObject)
+ void compile(VM* vm, YarrCodeBlock& jitObject)
{
generateEnter();
@@ -2639,7 +2642,7 @@ public:
backtrack();
// Link & finalize the code.
- LinkBuffer linkBuffer(*globalData, this, REGEXP_CODE_ID);
+ LinkBuffer linkBuffer(*vm, this, REGEXP_CODE_ID);
m_backtrackingState.linkDataLabels(linkBuffer);
if (compileMode == MatchOnly) {
@@ -2686,12 +2689,12 @@ private:
BacktrackingState m_backtrackingState;
};
-void jitCompile(YarrPattern& pattern, YarrCharSize charSize, JSGlobalData* globalData, YarrCodeBlock& jitObject, YarrJITCompileMode mode)
+void jitCompile(YarrPattern& pattern, YarrCharSize charSize, VM* vm, YarrCodeBlock& jitObject, YarrJITCompileMode mode)
{
if (mode == MatchOnly)
- YarrGenerator<MatchOnly>(pattern, charSize).compile(globalData, jitObject);
+ YarrGenerator<MatchOnly>(pattern, charSize).compile(vm, jitObject);
else
- YarrGenerator<IncludeSubpatterns>(pattern, charSize).compile(globalData, jitObject);
+ YarrGenerator<IncludeSubpatterns>(pattern, charSize).compile(vm, jitObject);
}
}}
diff --git a/Source/JavaScriptCore/yarr/YarrJIT.h b/Source/JavaScriptCore/yarr/YarrJIT.h
index bb7033fde..b7ce7d38f 100644
--- a/Source/JavaScriptCore/yarr/YarrJIT.h
+++ b/Source/JavaScriptCore/yarr/YarrJIT.h
@@ -28,7 +28,7 @@
#if ENABLE(YARR_JIT)
-#include "JSGlobalData.h"
+#include "VM.h"
#include "MacroAssemblerCodeRef.h"
#include "MatchResult.h"
#include "Yarr.h"
@@ -42,7 +42,7 @@
namespace JSC {
-class JSGlobalData;
+class VM;
class ExecutablePool;
namespace Yarr {
@@ -132,7 +132,7 @@ enum YarrJITCompileMode {
MatchOnly,
IncludeSubpatterns
};
-void jitCompile(YarrPattern&, YarrCharSize, JSGlobalData*, YarrCodeBlock& jitObject, YarrJITCompileMode = IncludeSubpatterns);
+void jitCompile(YarrPattern&, YarrCharSize, VM*, YarrCodeBlock& jitObject, YarrJITCompileMode = IncludeSubpatterns);
} } // namespace JSC::Yarr
diff --git a/Source/JavaScriptCore/yarr/YarrParser.h b/Source/JavaScriptCore/yarr/YarrParser.h
index 4bab1a090..8c5d71b5f 100644
--- a/Source/JavaScriptCore/yarr/YarrParser.h
+++ b/Source/JavaScriptCore/yarr/YarrParser.h
@@ -212,8 +212,8 @@ private:
// parseEscape() should never call these delegate methods when
// invoked with inCharacterClass set.
- NO_RETURN_DUE_TO_ASSERT void assertionWordBoundary(bool) { ASSERT_NOT_REACHED(); }
- NO_RETURN_DUE_TO_ASSERT void atomBackReference(unsigned) { ASSERT_NOT_REACHED(); }
+ NO_RETURN_DUE_TO_ASSERT void assertionWordBoundary(bool) { RELEASE_ASSERT_NOT_REACHED(); }
+ NO_RETURN_DUE_TO_ASSERT void atomBackReference(unsigned) { RELEASE_ASSERT_NOT_REACHED(); }
private:
Delegate& m_delegate;
diff --git a/Source/JavaScriptCore/yarr/YarrPattern.cpp b/Source/JavaScriptCore/yarr/YarrPattern.cpp
index c953a38d2..3ce0216e5 100644
--- a/Source/JavaScriptCore/yarr/YarrPattern.cpp
+++ b/Source/JavaScriptCore/yarr/YarrPattern.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2010 Peter Varga (pvarga@inf.u-szeged.hu), University of Szeged
*
* Redistribution and use in source and binary forms, with or without
@@ -175,16 +175,16 @@ public:
}
- CharacterClass* charClass()
+ PassOwnPtr<CharacterClass> charClass()
{
- CharacterClass* characterClass = new CharacterClass(0);
+ OwnPtr<CharacterClass> characterClass = adoptPtr(new CharacterClass);
characterClass->m_matches.swap(m_matches);
characterClass->m_ranges.swap(m_ranges);
characterClass->m_matchesUnicode.swap(m_matchesUnicode);
characterClass->m_rangesUnicode.swap(m_rangesUnicode);
- return characterClass;
+ return characterClass.release();
}
private:
@@ -274,9 +274,10 @@ public:
, m_characterClassConstructor(pattern.m_ignoreCase)
, m_invertParentheticalAssertion(false)
{
- m_pattern.m_body = new PatternDisjunction();
- m_alternative = m_pattern.m_body->addNewAlternative();
- m_pattern.m_disjunctions.append(m_pattern.m_body);
+ OwnPtr<PatternDisjunction> body = adoptPtr(new PatternDisjunction);
+ m_pattern.m_body = body.get();
+ m_alternative = body->addNewAlternative();
+ m_pattern.m_disjunctions.append(body.release());
}
~YarrPatternConstructor()
@@ -288,9 +289,10 @@ public:
m_pattern.reset();
m_characterClassConstructor.reset();
- m_pattern.m_body = new PatternDisjunction();
- m_alternative = m_pattern.m_body->addNewAlternative();
- m_pattern.m_disjunctions.append(m_pattern.m_body);
+ OwnPtr<PatternDisjunction> body = adoptPtr(new PatternDisjunction);
+ m_pattern.m_body = body.get();
+ m_alternative = body->addNewAlternative();
+ m_pattern.m_disjunctions.append(body.release());
}
void assertionBOL()
@@ -327,9 +329,9 @@ public:
}
m_characterClassConstructor.putUnicodeIgnoreCase(ch, info);
- CharacterClass* newCharacterClass = m_characterClassConstructor.charClass();
- m_pattern.m_userCharacterClasses.append(newCharacterClass);
- m_alternative->m_terms.append(PatternTerm(newCharacterClass, false));
+ OwnPtr<CharacterClass> newCharacterClass = m_characterClassConstructor.charClass();
+ m_alternative->m_terms.append(PatternTerm(newCharacterClass.get(), false));
+ m_pattern.m_userCharacterClasses.append(newCharacterClass.release());
}
void atomBuiltInCharacterClass(BuiltInCharacterClassID classID, bool invert)
@@ -383,15 +385,15 @@ public:
break;
default:
- ASSERT_NOT_REACHED();
+ RELEASE_ASSERT_NOT_REACHED();
}
}
void atomCharacterClassEnd()
{
- CharacterClass* newCharacterClass = m_characterClassConstructor.charClass();
- m_pattern.m_userCharacterClasses.append(newCharacterClass);
- m_alternative->m_terms.append(PatternTerm(newCharacterClass, m_invertCharacterClass));
+ OwnPtr<CharacterClass> newCharacterClass = m_characterClassConstructor.charClass();
+ m_alternative->m_terms.append(PatternTerm(newCharacterClass.get(), m_invertCharacterClass));
+ m_pattern.m_userCharacterClasses.append(newCharacterClass.release());
}
void atomParenthesesSubpatternBegin(bool capture = true)
@@ -400,19 +402,19 @@ public:
if (capture)
m_pattern.m_numSubpatterns++;
- PatternDisjunction* parenthesesDisjunction = new PatternDisjunction(m_alternative);
- m_pattern.m_disjunctions.append(parenthesesDisjunction);
- m_alternative->m_terms.append(PatternTerm(PatternTerm::TypeParenthesesSubpattern, subpatternId, parenthesesDisjunction, capture, false));
+ OwnPtr<PatternDisjunction> parenthesesDisjunction = adoptPtr(new PatternDisjunction(m_alternative));
+ m_alternative->m_terms.append(PatternTerm(PatternTerm::TypeParenthesesSubpattern, subpatternId, parenthesesDisjunction.get(), capture, false));
m_alternative = parenthesesDisjunction->addNewAlternative();
+ m_pattern.m_disjunctions.append(parenthesesDisjunction.release());
}
void atomParentheticalAssertionBegin(bool invert = false)
{
- PatternDisjunction* parenthesesDisjunction = new PatternDisjunction(m_alternative);
- m_pattern.m_disjunctions.append(parenthesesDisjunction);
- m_alternative->m_terms.append(PatternTerm(PatternTerm::TypeParentheticalAssertion, m_pattern.m_numSubpatterns + 1, parenthesesDisjunction, false, invert));
+ OwnPtr<PatternDisjunction> parenthesesDisjunction = adoptPtr(new PatternDisjunction(m_alternative));
+ m_alternative->m_terms.append(PatternTerm(PatternTerm::TypeParentheticalAssertion, m_pattern.m_numSubpatterns + 1, parenthesesDisjunction.get(), false, invert));
m_alternative = parenthesesDisjunction->addNewAlternative();
m_invertParentheticalAssertion = invert;
+ m_pattern.m_disjunctions.append(parenthesesDisjunction.release());
}
void atomParenthesesEnd()
@@ -477,23 +479,27 @@ public:
// skip alternatives with m_startsWithBOL set true.
PatternDisjunction* copyDisjunction(PatternDisjunction* disjunction, bool filterStartsWithBOL = false)
{
- PatternDisjunction* newDisjunction = 0;
+ OwnPtr<PatternDisjunction> newDisjunction;
for (unsigned alt = 0; alt < disjunction->m_alternatives.size(); ++alt) {
- PatternAlternative* alternative = disjunction->m_alternatives[alt];
+ PatternAlternative* alternative = disjunction->m_alternatives[alt].get();
if (!filterStartsWithBOL || !alternative->m_startsWithBOL) {
if (!newDisjunction) {
- newDisjunction = new PatternDisjunction();
+ newDisjunction = adoptPtr(new PatternDisjunction());
newDisjunction->m_parent = disjunction->m_parent;
}
PatternAlternative* newAlternative = newDisjunction->addNewAlternative();
+ newAlternative->m_terms.reserveInitialCapacity(alternative->m_terms.size());
for (unsigned i = 0; i < alternative->m_terms.size(); ++i)
newAlternative->m_terms.append(copyTerm(alternative->m_terms[i], filterStartsWithBOL));
}
}
- if (newDisjunction)
- m_pattern.m_disjunctions.append(newDisjunction);
- return newDisjunction;
+ if (!newDisjunction)
+ return 0;
+
+ PatternDisjunction* copiedDisjunction = newDisjunction.get();
+ m_pattern.m_disjunctions.append(newDisjunction.release());
+ return copiedDisjunction;
}
PatternTerm copyTerm(PatternTerm& term, bool filterStartsWithBOL = false)
@@ -655,7 +661,7 @@ public:
bool hasFixedSize = true;
for (unsigned alt = 0; alt < disjunction->m_alternatives.size(); ++alt) {
- PatternAlternative* alternative = disjunction->m_alternatives[alt];
+ PatternAlternative* alternative = disjunction->m_alternatives[alt].get();
unsigned currentAlternativeCallFrameSize = setupAlternativeOffsets(alternative, initialCallFrameSize, initialInputPosition);
minimumInputSize = std::min(minimumInputSize, alternative->m_minimumSize);
maximumCallFrameSize = std::max(maximumCallFrameSize, currentAlternativeCallFrameSize);
@@ -690,7 +696,7 @@ public:
if (m_pattern.m_numSubpatterns)
return;
- Vector<PatternAlternative*>& alternatives = m_pattern.m_body->m_alternatives;
+ Vector<OwnPtr<PatternAlternative> >& alternatives = m_pattern.m_body->m_alternatives;
for (size_t i = 0; i < alternatives.size(); ++i) {
Vector<PatternTerm>& terms = alternatives[i]->m_terms;
if (terms.size()) {
@@ -725,7 +731,7 @@ public:
if (loopDisjunction) {
// Move alternatives from loopDisjunction to disjunction
for (unsigned alt = 0; alt < loopDisjunction->m_alternatives.size(); ++alt)
- disjunction->m_alternatives.append(loopDisjunction->m_alternatives[alt]);
+ disjunction->m_alternatives.append(loopDisjunction->m_alternatives[alt].release());
loopDisjunction->m_alternatives.clear();
}
@@ -744,7 +750,7 @@ public:
if (term.type == PatternTerm::TypeParenthesesSubpattern) {
PatternDisjunction* nestedDisjunction = term.parentheses.disjunction;
for (unsigned alt = 0; alt < nestedDisjunction->m_alternatives.size(); ++alt) {
- if (containsCapturingTerms(nestedDisjunction->m_alternatives[alt], 0, nestedDisjunction->m_alternatives[alt]->m_terms.size() - 1))
+ if (containsCapturingTerms(nestedDisjunction->m_alternatives[alt].get(), 0, nestedDisjunction->m_alternatives[alt]->m_terms.size() - 1))
return true;
}
}
@@ -760,11 +766,11 @@ public:
// beginning and the end of the match.
void optimizeDotStarWrappedExpressions()
{
- Vector<PatternAlternative*>& alternatives = m_pattern.m_body->m_alternatives;
+ Vector<OwnPtr<PatternAlternative> >& alternatives = m_pattern.m_body->m_alternatives;
if (alternatives.size() != 1)
return;
- PatternAlternative* alternative = alternatives[0];
+ PatternAlternative* alternative = alternatives[0].get();
Vector<PatternTerm>& terms = alternative->m_terms;
if (terms.size() >= 3) {
bool startsWithBOL = false;
diff --git a/Source/JavaScriptCore/yarr/YarrPattern.h b/Source/JavaScriptCore/yarr/YarrPattern.h
index 14e89b8e0..e7d187c2b 100644
--- a/Source/JavaScriptCore/yarr/YarrPattern.h
+++ b/Source/JavaScriptCore/yarr/YarrPattern.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2010 Peter Varga (pvarga@inf.u-szeged.hu), University of Szeged
*
* Redistribution and use in source and binary forms, with or without
@@ -28,6 +28,8 @@
#define YarrPattern_h
#include <wtf/CheckedArithmetic.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
@@ -48,37 +50,28 @@ struct CharacterRange {
}
};
-struct CharacterClassTable : RefCounted<CharacterClassTable> {
- const char* m_table;
- bool m_inverted;
- static PassRefPtr<CharacterClassTable> create(const char* table, bool inverted)
- {
- return adoptRef(new CharacterClassTable(table, inverted));
- }
-
-private:
- CharacterClassTable(const char* table, bool inverted)
- : m_table(table)
- , m_inverted(inverted)
- {
- }
-};
-
struct CharacterClass {
WTF_MAKE_FAST_ALLOCATED;
public:
// All CharacterClass instances have to have the full set of matches and ranges,
- // they may have an optional table for faster lookups (which must match the
+ // they may have an optional m_table for faster lookups (which must match the
// specified matches and ranges)
- CharacterClass(PassRefPtr<CharacterClassTable> table)
+ CharacterClass()
+ : m_table(0)
+ {
+ }
+ CharacterClass(const char* table, bool inverted)
: m_table(table)
+ , m_tableInverted(inverted)
{
}
Vector<UChar> m_matches;
Vector<CharacterRange> m_ranges;
Vector<UChar> m_matchesUnicode;
Vector<CharacterRange> m_rangesUnicode;
- RefPtr<CharacterClassTable> m_table;
+
+ const char* m_table;
+ bool m_tableInverted;
};
enum QuantifierType {
@@ -275,19 +268,14 @@ public:
{
}
- ~PatternDisjunction()
- {
- deleteAllValues(m_alternatives);
- }
-
PatternAlternative* addNewAlternative()
{
PatternAlternative* alternative = new PatternAlternative(this);
- m_alternatives.append(alternative);
+ m_alternatives.append(adoptPtr(alternative));
return alternative;
}
- Vector<PatternAlternative*> m_alternatives;
+ Vector<OwnPtr<PatternAlternative> > m_alternatives;
PatternAlternative* m_parent;
unsigned m_minimumSize;
unsigned m_callFrameSize;
@@ -318,12 +306,6 @@ struct TermChain {
struct YarrPattern {
JS_EXPORT_PRIVATE YarrPattern(const String& pattern, bool ignoreCase, bool multiline, const char** error);
- ~YarrPattern()
- {
- deleteAllValues(m_disjunctions);
- deleteAllValues(m_userCharacterClasses);
- }
-
void reset()
{
m_numSubpatterns = 0;
@@ -340,9 +322,7 @@ struct YarrPattern {
nonspacesCached = 0;
nonwordcharCached = 0;
- deleteAllValues(m_disjunctions);
m_disjunctions.clear();
- deleteAllValues(m_userCharacterClasses);
m_userCharacterClasses.clear();
}
@@ -354,43 +334,43 @@ struct YarrPattern {
CharacterClass* newlineCharacterClass()
{
if (!newlineCached)
- m_userCharacterClasses.append(newlineCached = newlineCreate());
+ m_userCharacterClasses.append(adoptPtr(newlineCached = newlineCreate()));
return newlineCached;
}
CharacterClass* digitsCharacterClass()
{
if (!digitsCached)
- m_userCharacterClasses.append(digitsCached = digitsCreate());
+ m_userCharacterClasses.append(adoptPtr(digitsCached = digitsCreate()));
return digitsCached;
}
CharacterClass* spacesCharacterClass()
{
if (!spacesCached)
- m_userCharacterClasses.append(spacesCached = spacesCreate());
+ m_userCharacterClasses.append(adoptPtr(spacesCached = spacesCreate()));
return spacesCached;
}
CharacterClass* wordcharCharacterClass()
{
if (!wordcharCached)
- m_userCharacterClasses.append(wordcharCached = wordcharCreate());
+ m_userCharacterClasses.append(adoptPtr(wordcharCached = wordcharCreate()));
return wordcharCached;
}
CharacterClass* nondigitsCharacterClass()
{
if (!nondigitsCached)
- m_userCharacterClasses.append(nondigitsCached = nondigitsCreate());
+ m_userCharacterClasses.append(adoptPtr(nondigitsCached = nondigitsCreate()));
return nondigitsCached;
}
CharacterClass* nonspacesCharacterClass()
{
if (!nonspacesCached)
- m_userCharacterClasses.append(nonspacesCached = nonspacesCreate());
+ m_userCharacterClasses.append(adoptPtr(nonspacesCached = nonspacesCreate()));
return nonspacesCached;
}
CharacterClass* nonwordcharCharacterClass()
{
if (!nonwordcharCached)
- m_userCharacterClasses.append(nonwordcharCached = nonwordcharCreate());
+ m_userCharacterClasses.append(adoptPtr(nonwordcharCached = nonwordcharCreate()));
return nonwordcharCached;
}
@@ -401,8 +381,8 @@ struct YarrPattern {
unsigned m_numSubpatterns;
unsigned m_maxBackReference;
PatternDisjunction* m_body;
- Vector<PatternDisjunction*, 4> m_disjunctions;
- Vector<CharacterClass*> m_userCharacterClasses;
+ Vector<OwnPtr<PatternDisjunction>, 4> m_disjunctions;
+ Vector<OwnPtr<CharacterClass> > m_userCharacterClasses;
private:
const char* compile(const String& patternString);