Ticket #24189: qtwebengine-6.11.3-icu4c_79-1.patch

File qtwebengine-6.11.3-icu4c_79-1.patch, 7.4 KB (added by martyj19, 3 weeks ago)

ICU patch to v8 in node.js ported to v8 in qtwebengine (original from Joe Locash)

  • src/3rdparty/chromium/v8/src/regexp/gen-regexp-special-case.cc

    diff -Naur qtwebengine-6.11.3.orig/src/3rdparty/chromium/v8/src/regexp/gen-regexp-special-case.cc qtwebengine-6.11.3/src/3rdparty/chromium/v8/src/regexp/gen-regexp-special-case.cc
    old new  
    99
    1010#include "src/base/strings.h"
    1111#include "src/regexp/special-case.h"
     12#include "unicode/uchar.h"
    1213
    1314namespace v8 {
    1415namespace internal {
    … …  
    1718static const base::uc32 kSurrogateEnd = 0xdfff;
    1819static const base::uc32 kNonBmpStart = 0x10000;
    1920
     21// Removes supplementary code points from |set| and returns whether any were
     22// present. Since Unicode 18, the case closure of a BMP character can contain
     23// supplementary code points (U+1DF95 LATIN SMALL LIGATURE LONG S WITH
     24// DESCENDER S case-folds to U+00DF LATIN SMALL LETTER SHARP S). Non-unicode
     25// ignoreCase matching compares UTF-16 code units, so a supplementary code
     26// point never matches a BMP character and does not take part in Canonicalize.
     27bool RemoveSupplementary(icu::UnicodeSet& set) {
     28  constexpr UChar32 kFirstSupplementary = static_cast<UChar32>(kNonBmpStart);
     29  if (!set.containsSome(kFirstSupplementary, UCHAR_MAX_VALUE)) return false;
     30  set.remove(kFirstSupplementary, UCHAR_MAX_VALUE);
     31  return true;
     32}
     33
    2034// The following code generates "src/regexp/special-case.cc".
    2135void PrintSet(std::ofstream& out, const char* name,
    2236              const icu::UnicodeSet& set) {
    … …  
    5165  icu::UnicodeSet current;
    5266  icu::UnicodeSet special_add;
    5367  icu::UnicodeSet ignore;
     68  icu::UnicodeSet supplementary_equivalents;
    5469  UErrorCode status = U_ZERO_ERROR;
    5570  icu::UnicodeSet upper("[\\p{Lu}]", status);
    5671  CHECK(U_SUCCESS(status));
    … …  
    6378    }
    6479    current.set(i, i);
    6580    current.closeOver(USET_CASE_INSENSITIVE);
     81    if (RemoveSupplementary(current)) supplementary_equivalents.add(i);
    6682
    6783    // Check to see if all characters in the case-folding equivalence
    6884    // class as defined by UnicodeSet::closeOver all map to the same
    … …  
    112128      UChar32 canonical = RegExpCaseFolding::Canonicalize(c);
    113129      current.set(c, c);
    114130      current.closeOver(USET_CASE_INSENSITIVE);
     131      RemoveSupplementary(current);
    115132      current.removeAll(ignore);
    116133      for (int32_t j = 0; j < current.getRangeCount(); j++) {
    117134        for (UChar32 c2 = current.getRangeStart(j);
    … …  
    124141
    125142  PrintSet(out, "IgnoreSet", ignore);
    126143  PrintSet(out, "SpecialAddSet", special_add);
     144  PrintSet(out, "SupplementaryEquivalentsSet", supplementary_equivalents);
    127145}
    128146
    129147void WriteHeader(const char* header_filename) {
  • src/3rdparty/chromium/v8/src/regexp/regexp-parser.cc

    diff -Naur qtwebengine-6.11.3.orig/src/3rdparty/chromium/v8/src/regexp/regexp-parser.cc qtwebengine-6.11.3/src/3rdparty/chromium/v8/src/regexp/regexp-parser.cc
    old new  
    99#include "src/regexp/regexp-ast.h"
    1010#include "src/regexp/regexp-macro-assembler.h"
    1111#include "src/regexp/regexp.h"
     12#include "src/regexp/special-case.h"
    1213#include "src/strings/char-predicates-inl.h"
    1314#include "src/utils/ostreams.h"
    1415#include "src/utils/utils.h"
    … …  
    155156
    156157void RegExpTextBuilder::AddCharacter(base::uc16 c) {
    157158  FlushPendingSurrogate();
     159  if (NeedsDesugaringForIgnoreCase(c)) {
     160    AddClassRangesForDesugaring(c);
     161    return;
     162  }
    158163  if (characters_ == nullptr) {
    159164    characters_ = zone()->New<ZoneList<base::uc16>>(4, zone());
    160165  }
    … …  
    237242  return false;
    238243}
    239244
    240 // We only use this for characters made of surrogate pairs.  All other
    241 // characters outside of character classes are made case independent in the
    242 // code generation.
     245// Desugar supplementary characters with case equivalents and BMP characters
     246// with supplementary equivalents. Other atoms are folded during code
     247// generation.
    243248bool RegExpTextBuilder::NeedsDesugaringForIgnoreCase(base::uc32 c) {
    244249#ifdef V8_INTL_SUPPORT
    245250  if (IsUnicodeMode() && ignore_case()) {
     251    if (c <= unibrow::Utf16::kMaxNonSurrogateCharCode) {
     252      return RegExpCaseFolding::HasSupplementaryEquivalents(
     253          static_cast<base::uc16>(c));
     254    }
    246255    icu::UnicodeSet set(c, c);
    247     set.closeOver(USET_CASE_INSENSITIVE);
    248     set.removeAllStrings();
     256    RegExpCaseFolding::CloseOver(set, RegExpCaseFolding::Mode::kUnicode);
    249257    return set.size() > 1;
    250258  }
    251259  // In the case where ICU is not included, we act as if the unicode flag is
  • src/3rdparty/chromium/v8/src/regexp/special-case.h

    diff -Naur qtwebengine-6.11.3.orig/src/3rdparty/chromium/v8/src/regexp/special-case.h qtwebengine-6.11.3/src/3rdparty/chromium/v8/src/regexp/special-case.h
    old new  
    77
    88#ifdef V8_INTL_SUPPORT
    99#include "src/base/logging.h"
     10#include "src/base/strings.h"
    1011#include "src/common/globals.h"
    11 
    1212#include "unicode/uchar.h"
    1313#include "unicode/uniset.h"
    1414#include "unicode/unistr.h"
    … …  
    7171// another character. Characters that match no other characters in
    7272// their equivalence class are added to IgnoreSet. Characters that
    7373// match at least one other character are added to SpecialAddSet.
     74// Supplementary code points are ignored throughout: non-unicode matching
     75// compares UTF-16 code units, so they can never match a BMP character.
     76//
     77// The generator additionally emits SupplementaryEquivalentsSet, the BMP
     78// characters whose Unicode case closure contains supplementary code points.
     79// This set is used for unicode-mode matching, see HasSupplementaryEquivalents.
    7480
    7581class RegExpCaseFolding final : public AllStatic {
    7682 public:
     83  enum class Mode { kNonUnicode, kUnicode };
     84
    7785  static const icu::UnicodeSet& IgnoreSet();
    7886  static const icu::UnicodeSet& SpecialAddSet();
    7987
    … …  
    108116    // h. Return cu.
    109117    return cu;
    110118  }
     119
     120  // Close a set of characters under case equivalence, preserving its
     121  // original members. Non-unicode inputs must be UTF-16 code units.
     122  static void CloseOver(icu::UnicodeSet& set, Mode mode) {
     123    if (mode == Mode::kUnicode) {
     124      set.closeOver(USET_SIMPLE_CASE_INSENSITIVE);
     125      return;
     126    }
     127    DCHECK(!set.containsSome(0x10000, 0x10ffff));
     128    if (IgnoreSet().containsNone(set)) {
     129      CloseOverNonUnicode(set);
     130      return;
     131    }
     132    if (IgnoreSet().containsAll(set)) return;
     133    // Ignored characters neither contribute nor acquire equivalents, but
     134    // must remain in the result if they were explicitly present.
     135    icu::UnicodeSet ignored(set);
     136    ignored.retainAll(IgnoreSet());
     137    set.removeAll(IgnoreSet());
     138    CloseOverNonUnicode(set);
     139    set.addAll(ignored);
     140  }
     141
     142  // Whether c has supplementary Unicode case equivalents.
     143  static bool HasSupplementaryEquivalents(base::uc16 c) {
     144    return SupplementaryEquivalentsSet().contains(c);
     145  }
     146
     147 private:
     148  static const icu::UnicodeSet& SupplementaryEquivalentsSet();
     149
     150  // Requires a set containing no IgnoreSet characters.
     151  static void CloseOverNonUnicode(icu::UnicodeSet& set) {
     152    set.closeOver(USET_SIMPLE_CASE_INSENSITIVE);
     153    set.removeAll(IgnoreSet());
     154    set.remove(0x10000, 0x10ffff);
     155  }
    111156};
    112157
    113158}  // namespace internal