1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
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/. */
15 * Used to add entries to a js::HashMap or HashSet where the key depends on a GC
16 * thing that may be moved by generational or compacting GC between the call to
17 * lookupForAdd() and relookupOrAdd().
20 struct DependentAddPtr
22 typedef typename
T::AddPtr AddPtr
;
23 typedef typename
T::Entry Entry
;
25 template <class Lookup
>
26 DependentAddPtr(const ExclusiveContext
*cx
, const T
&table
, const Lookup
&lookup
)
27 : addPtr(table
.lookupForAdd(lookup
))
28 #ifdef JSGC_GENERATIONAL
29 , originalGcNumber(cx
->zone()->gcNumber())
33 template <class KeyInput
, class ValueInput
>
34 bool add(const ExclusiveContext
*cx
, T
&table
, const KeyInput
&key
, const ValueInput
&value
) {
35 #ifdef JSGC_GENERATIONAL
36 bool gcHappened
= originalGcNumber
!= cx
->zone()->gcNumber();
38 addPtr
= table
.lookupForAdd(key
);
40 return table
.relookupOrAdd(addPtr
, key
, value
);
43 typedef void (DependentAddPtr::* ConvertibleToBool
)();
46 bool found() const { return addPtr
.found(); }
47 operator ConvertibleToBool() const { return found() ? &DependentAddPtr::nonNull
: 0; }
48 const Entry
&operator*() const { return *addPtr
; }
49 const Entry
*operator->() const { return &*addPtr
; }
53 #ifdef JSGC_GENERATIONAL
54 const uint64_t originalGcNumber
;
57 DependentAddPtr() MOZ_DELETE
;
58 DependentAddPtr(const DependentAddPtr
&) MOZ_DELETE
;
59 DependentAddPtr
& operator=(const DependentAddPtr
&) MOZ_DELETE
;