diff options
Diffstat (limited to 'deps/v8/src/regexp/regexp-parser.cc')
-rw-r--r-- | deps/v8/src/regexp/regexp-parser.cc | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/deps/v8/src/regexp/regexp-parser.cc b/deps/v8/src/regexp/regexp-parser.cc index fd3123f674..3035f6a9a9 100644 --- a/deps/v8/src/regexp/regexp-parser.cc +++ b/deps/v8/src/regexp/regexp-parser.cc @@ -13,7 +13,7 @@ #include "src/utils.h" #ifdef V8_I18N_SUPPORT -#include "unicode/uset.h" +#include "unicode/uniset.h" #endif // V8_I18N_SUPPORT namespace v8 { @@ -75,6 +75,7 @@ void RegExpParser::Advance() { if (has_next()) { StackLimitCheck check(isolate()); if (check.HasOverflowed()) { + if (FLAG_abort_on_stack_overflow) FATAL("Aborting on stack overflow"); ReportError(CStrVector( MessageTemplate::TemplateString(MessageTemplate::kStackOverflow))); } else if (zone()->excess_allocation()) { @@ -1082,37 +1083,37 @@ bool IsExactPropertyValueAlias(const char* property_value_name, bool LookupPropertyValueName(UProperty property, const char* property_value_name, bool negate, ZoneList<CharacterRange>* result, Zone* zone) { + UProperty property_for_lookup = property; + if (property_for_lookup == UCHAR_SCRIPT_EXTENSIONS) { + // For the property Script_Extensions, we have to do the property value + // name lookup as if the property is Script. + property_for_lookup = UCHAR_SCRIPT; + } int32_t property_value = - u_getPropertyValueEnum(property, property_value_name); + u_getPropertyValueEnum(property_for_lookup, property_value_name); if (property_value == UCHAR_INVALID_CODE) return false; // We require the property name to match exactly to one of the property value // aliases. However, u_getPropertyValueEnum uses loose matching. - if (!IsExactPropertyValueAlias(property_value_name, property, + if (!IsExactPropertyValueAlias(property_value_name, property_for_lookup, property_value)) { return false; } - USet* set = uset_openEmpty(); UErrorCode ec = U_ZERO_ERROR; - uset_applyIntPropertyValue(set, property, property_value, &ec); - bool success = ec == U_ZERO_ERROR && !uset_isEmpty(set); + icu::UnicodeSet set; + set.applyIntPropertyValue(property, property_value, ec); + bool success = ec == U_ZERO_ERROR && !set.isEmpty(); if (success) { - uset_removeAllStrings(set); - if (negate) uset_complement(set); - int item_count = uset_getItemCount(set); - int item_result = 0; - for (int i = 0; i < item_count; i++) { - uc32 start = 0; - uc32 end = 0; - item_result += uset_getItem(set, i, &start, &end, nullptr, 0, &ec); - result->Add(CharacterRange::Range(start, end), zone); + set.removeAllStrings(); + if (negate) set.complement(); + for (int i = 0; i < set.getRangeCount(); i++) { + result->Add( + CharacterRange::Range(set.getRangeStart(i), set.getRangeEnd(i)), + zone); } - DCHECK_EQ(U_ZERO_ERROR, ec); - DCHECK_EQ(0, item_result); } - uset_close(set); return success; } @@ -1196,9 +1197,14 @@ bool RegExpParser::ParsePropertyClass(ZoneList<CharacterRange>* result, const char* property_name = first_part.ToConstVector().start(); const char* value_name = second_part.ToConstVector().start(); UProperty property = u_getPropertyEnum(property_name); - if (property < UCHAR_INT_START) return false; - if (property >= UCHAR_INT_LIMIT) return false; if (!IsExactPropertyAlias(property_name, property)) return false; + if (property == UCHAR_GENERAL_CATEGORY) { + // We want to allow aggregate value names such as "Letter". + property = UCHAR_GENERAL_CATEGORY_MASK; + } else if (property != UCHAR_SCRIPT && + property != UCHAR_SCRIPT_EXTENSIONS) { + return false; + } return LookupPropertyValueName(property, value_name, negate, result, zone()); } @@ -1720,12 +1726,10 @@ bool RegExpBuilder::NeedsDesugaringForUnicode(RegExpCharacterClass* cc) { bool RegExpBuilder::NeedsDesugaringForIgnoreCase(uc32 c) { #ifdef V8_I18N_SUPPORT if (unicode() && ignore_case()) { - USet* set = uset_open(c, c); - uset_closeOver(set, USET_CASE_INSENSITIVE); - uset_removeAllStrings(set); - bool result = uset_size(set) > 1; - uset_close(set); - return result; + icu::UnicodeSet set(c, c); + set.closeOver(USET_CASE_INSENSITIVE); + set.removeAllStrings(); + return set.size() > 1; } // In the case where ICU is not included, we act as if the unicode flag is // not set, and do not desugar. |