Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / vm / PropertyKey.h
blob56e2cfea0cb862f796ba6b10df0dfefbb3b8d1d3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef vm_PropertyKey_h
8 #define vm_PropertyKey_h
10 #include "mozilla/HashFunctions.h" // mozilla::HashGeneric
12 #include "NamespaceImports.h" // js::PropertyKey
14 #include "js/HashTable.h" // js::DefaultHasher
15 #include "js/Id.h" // JS::PropertyKey
16 #include "vm/StringType.h" // JSAtom::hash
17 #include "vm/SymbolType.h" // JS::Symbol::hash
19 namespace js {
21 static MOZ_ALWAYS_INLINE HashNumber HashPropertyKey(PropertyKey key) {
22 // HashGeneric alone would work, but bits of atom and symbol addresses
23 // could then be recovered from the hash code. See bug 1330769.
24 if (MOZ_LIKELY(key.isAtom())) {
25 return key.toAtom()->hash();
27 if (key.isSymbol()) {
28 return key.toSymbol()->hash();
30 return mozilla::HashGeneric(key.asRawBits());
33 // Like HashPropertyKey but optimized for callers that only use atom or symbol
34 // keys.
35 static MOZ_ALWAYS_INLINE HashNumber
36 HashAtomOrSymbolPropertyKey(PropertyKey key) {
37 if (MOZ_LIKELY(key.isAtom())) {
38 return key.toAtom()->hash();
40 return key.toSymbol()->hash();
43 } // namespace js
45 namespace mozilla {
47 template <>
48 struct DefaultHasher<JS::PropertyKey> {
49 using Lookup = JS::PropertyKey;
50 static HashNumber hash(JS::PropertyKey key) {
51 return js::HashPropertyKey(key);
53 static bool match(JS::PropertyKey key1, JS::PropertyKey key2) {
54 return key1 == key2;
58 } // namespace mozilla
60 #endif /* vm_PropertyKey_h */