File: sanitizer_names.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (52 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SANITIZER_SANITIZER_NAMES_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SANITIZER_SANITIZER_NAMES_H_

#include "third_party/blink/renderer/core/dom/qualified_name.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/hash_traits.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h"

namespace blink {

// SanitizerNameHashTraits defines traits suitable for Sanitizer use.
//
// Sanitizer stores all names as blink::QualifiedName, which is used all
// over Blink. QualifiedName has three components, local name, prefix, and
// namespace URI. For Sanitizer, the spec demands that we always match on
// name + namespace, but never on the prefix. These traits define equality
// and hash function to match this. This allows us to re-use QualifiedName
// and the "standard" WTF structures.
struct SanitizerNameHashTraits : GenericHashTraits<blink::QualifiedName> {
  static unsigned GetHash(const QualifiedName& name) {
    CHECK(name.LocalName());
    unsigned hash = HashTraits<AtomicString>::GetHash(name.LocalName());
    if (name.NamespaceURI()) {
      hash ^= HashTraits<AtomicString>::GetHash(name.NamespaceURI());
    }
    return hash;
  }
  static bool Equal(const QualifiedName& a, const QualifiedName& b) {
    return a.Matches(b);
  }
  static constexpr bool kSafeToCompareToEmptyOrDeleted = false;
  static constexpr bool kEmptyValueIsZero = false;
  static const QualifiedName& EmptyValue() { return g_null_name; }
  static const QualifiedName& DeletedValue() {
    // This is a bit of a cheat: We re-use the "*" name -- which is not a valid
    // element or attribute name -- as the "deleted" name.
    return g_any_name;
  }
};

typedef HashSet<QualifiedName, SanitizerNameHashTraits> SanitizerNameSet;
typedef HashMap<QualifiedName, SanitizerNameSet, SanitizerNameHashTraits>
    SanitizerNameMap;

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_SANITIZER_SANITIZER_NAMES_H_