DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (27a812186ff4)

VCS Links

Line Code
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Private maps (hashtables). */

#ifndef xpcmaps_h___
#define xpcmaps_h___

#include "mozilla/MemoryReporting.h"


// Maps...

// Note that most of the declarations for hash table entries begin with
// a pointer to something or another. This makes them look enough like
// the PLDHashEntryStub struct that the default OPs (PL_DHashGetStubOps())
// just do the right thing for most of our needs.

// no virtuals in the maps - all the common stuff inlined
// templates could be used to good effect here.

/*************************/

class JSObject2WrappedJSMap
{
    typedef js::HashMap<JSObject*, nsXPCWrappedJS*, js::PointerHasher<JSObject*, 3>,
                        js::SystemAllocPolicy> Map;

public:
    static JSObject2WrappedJSMap* newMap(int size) {
        JSObject2WrappedJSMap* map = new JSObject2WrappedJSMap();
        if (map && map->mTable.init(size))
            return map;
        delete map;
        return nullptr;
    }

    inline nsXPCWrappedJS* Find(JSObject* Obj) {
        NS_PRECONDITION(Obj,"bad param");
        Map::Ptr p = mTable.lookup(Obj);
        return p ? p->value() : nullptr;
    }

    inline nsXPCWrappedJS* Add(JSContext* cx, nsXPCWrappedJS* wrapper) {
        NS_PRECONDITION(wrapper,"bad param");
        JSObject* obj = wrapper->GetJSObjectPreserveColor();
        Map::AddPtr p = mTable.lookupForAdd(obj);
        if (p)
            return p->value();
        if (!mTable.add(p, obj, wrapper))
            return nullptr;
        JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, obj, this);
        return wrapper;
    }

    inline void Remove(nsXPCWrappedJS* wrapper) {
        NS_PRECONDITION(wrapper,"bad param");
        mTable.remove(wrapper->GetJSObjectPreserveColor());
    }

    inline uint32_t Count() {return mTable.count();}

    inline void Dump(int16_t depth) {
        for (Map::Range r = mTable.all(); !r.empty(); r.popFront())
            r.front().value()->DebugDump(depth);
    }

    void FindDyingJSObjects(nsTArray<nsXPCWrappedJS*>* dying);

    void ShutdownMarker();

    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) {
        size_t n = mallocSizeOf(this);
        n += mTable.sizeOfExcludingThis(mallocSizeOf);
        return n;
    }

private:
    JSObject2WrappedJSMap() {}

    /*
     * This function is called during minor GCs for each key in the HashMap that
     * has been moved.
     */
    static void KeyMarkCallback(JSTracer* trc, JSObject* key, void* data) {
        JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(data);
        JSObject* prior = key;
        JS_CallObjectTracer(trc, &key, "XPCJSRuntime::mWrappedJSMap key");
        self->mTable.rekeyIfMoved(prior, key);
    }

    Map mTable;
};

/*************************/

class Native2WrappedNativeMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        nsISupports*      key;
        XPCWrappedNative* value;
    };

    static Native2WrappedNativeMap* newMap(int size);

    inline XPCWrappedNative* Find(nsISupports* Obj)
    {
        NS_PRECONDITION(Obj,"bad param");
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, Obj, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->value;
    }

    inline XPCWrappedNative* Add(XPCWrappedNative* wrapper)
    {
        NS_PRECONDITION(wrapper,"bad param");
        nsISupports* obj = wrapper->GetIdentityObject();
        MOZ_ASSERT(!Find(obj), "wrapper already in new scope!");
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, obj, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key)
            return entry->value;
        entry->key = obj;
        entry->value = wrapper;
        return wrapper;
    }

    inline void Remove(XPCWrappedNative* wrapper)
    {
        NS_PRECONDITION(wrapper,"bad param");
#ifdef DEBUG
        XPCWrappedNative* wrapperInMap = Find(wrapper->GetIdentityObject());
        MOZ_ASSERT(!wrapperInMap || wrapperInMap == wrapper,
                   "About to remove a different wrapper with the same "
                   "nsISupports identity! This will most likely cause serious "
                   "problems!");
#endif
        PL_DHashTableOperate(mTable, wrapper->GetIdentityObject(), PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);

    ~Native2WrappedNativeMap();
private:
    Native2WrappedNativeMap();    // no implementation
    Native2WrappedNativeMap(int size);

    static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);

private:
    PLDHashTable* mTable;
};

/*************************/

class IID2WrappedJSClassMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        const nsIID*         key;
        nsXPCWrappedJSClass* value;

        static const struct PLDHashTableOps sOps;
    };

    static IID2WrappedJSClassMap* newMap(int size);

    inline nsXPCWrappedJSClass* Find(REFNSIID iid)
    {
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, &iid, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->value;
    }

    inline nsXPCWrappedJSClass* Add(nsXPCWrappedJSClass* clazz)
    {
        NS_PRECONDITION(clazz,"bad param");
        const nsIID* iid = &clazz->GetIID();
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, iid, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key)
            return entry->value;
        entry->key = iid;
        entry->value = clazz;
        return clazz;
    }

    inline void Remove(nsXPCWrappedJSClass* clazz)
    {
        NS_PRECONDITION(clazz,"bad param");
        PL_DHashTableOperate(mTable, &clazz->GetIID(), PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    ~IID2WrappedJSClassMap();
private:
    IID2WrappedJSClassMap();    // no implementation
    IID2WrappedJSClassMap(int size);
private:
    PLDHashTable* mTable;
};

/*************************/

class IID2NativeInterfaceMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        const nsIID*        key;
        XPCNativeInterface* value;

        static const struct PLDHashTableOps sOps;
    };

    static IID2NativeInterfaceMap* newMap(int size);

    inline XPCNativeInterface* Find(REFNSIID iid)
    {
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, &iid, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->value;
    }

    inline XPCNativeInterface* Add(XPCNativeInterface* iface)
    {
        NS_PRECONDITION(iface,"bad param");
        const nsIID* iid = iface->GetIID();
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, iid, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key)
            return entry->value;
        entry->key = iid;
        entry->value = iface;
        return iface;
    }

    inline void Remove(XPCNativeInterface* iface)
    {
        NS_PRECONDITION(iface,"bad param");
        PL_DHashTableOperate(mTable, iface->GetIID(), PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);

    ~IID2NativeInterfaceMap();
private:
    IID2NativeInterfaceMap();    // no implementation
    IID2NativeInterfaceMap(int size);

    static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);

private:
    PLDHashTable* mTable;
};

/*************************/

class ClassInfo2NativeSetMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        nsIClassInfo* key;
        XPCNativeSet* value;
    };

    static ClassInfo2NativeSetMap* newMap(int size);

    inline XPCNativeSet* Find(nsIClassInfo* info)
    {
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, info, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->value;
    }

    inline XPCNativeSet* Add(nsIClassInfo* info, XPCNativeSet* set)
    {
        NS_PRECONDITION(info,"bad param");
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, info, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key)
            return entry->value;
        entry->key = info;
        entry->value = set;
        return set;
    }

    inline void Remove(nsIClassInfo* info)
    {
        NS_PRECONDITION(info,"bad param");
        PL_DHashTableOperate(mTable, info, PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    // ClassInfo2NativeSetMap holds pointers to *some* XPCNativeSets.
    // So we don't want to count those XPCNativeSets, because they are better
    // counted elsewhere (i.e. in XPCJSRuntime::mNativeSetMap, which holds
    // pointers to *all* XPCNativeSets).  Hence the "Shallow".
    size_t ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);

    ~ClassInfo2NativeSetMap();
private:
    ClassInfo2NativeSetMap();    // no implementation
    ClassInfo2NativeSetMap(int size);
private:
    PLDHashTable* mTable;
};

/*************************/

class ClassInfo2WrappedNativeProtoMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        nsIClassInfo*          key;
        XPCWrappedNativeProto* value;
    };

    static ClassInfo2WrappedNativeProtoMap* newMap(int size);

    inline XPCWrappedNativeProto* Find(nsIClassInfo* info)
    {
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, info, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->value;
    }

    inline XPCWrappedNativeProto* Add(nsIClassInfo* info, XPCWrappedNativeProto* proto)
    {
        NS_PRECONDITION(info,"bad param");
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, info, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key)
            return entry->value;
        entry->key = info;
        entry->value = proto;
        return proto;
    }

    inline void Remove(nsIClassInfo* info)
    {
        NS_PRECONDITION(info,"bad param");
        PL_DHashTableOperate(mTable, info, PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);

    ~ClassInfo2WrappedNativeProtoMap();
private:
    ClassInfo2WrappedNativeProtoMap();    // no implementation
    ClassInfo2WrappedNativeProtoMap(int size);

    static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);

private:
    PLDHashTable* mTable;
};

/*************************/

class NativeSetMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        XPCNativeSet* key_value;

        static bool
        Match(PLDHashTable* table,
              const PLDHashEntryHdr* entry,
              const void* key);

        static const struct PLDHashTableOps sOps;
    };

    static NativeSetMap* newMap(int size);

    inline XPCNativeSet* Find(XPCNativeSetKey* key)
    {
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, key, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->key_value;
    }

    inline XPCNativeSet* Add(const XPCNativeSetKey* key, XPCNativeSet* set)
    {
        NS_PRECONDITION(key,"bad param");
        NS_PRECONDITION(set,"bad param");
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, key, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key_value)
            return entry->key_value;
        entry->key_value = set;
        return set;
    }

    inline XPCNativeSet* Add(XPCNativeSet* set)
    {
        XPCNativeSetKey key(set, nullptr, 0);
        return Add(&key, set);
    }

    inline void Remove(XPCNativeSet* set)
    {
        NS_PRECONDITION(set,"bad param");

        XPCNativeSetKey key(set, nullptr, 0);
        PL_DHashTableOperate(mTable, &key, PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);

    ~NativeSetMap();
private:
    NativeSetMap();    // no implementation
    NativeSetMap(int size);

    static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);

private:
    PLDHashTable* mTable;
};

/***************************************************************************/

class IID2ThisTranslatorMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        nsIID                                  key;
        nsCOMPtr<nsIXPCFunctionThisTranslator> value;

        static bool
        Match(PLDHashTable* table,
              const PLDHashEntryHdr* entry,
              const void* key);

        static void
        Clear(PLDHashTable* table, PLDHashEntryHdr* entry);

        static const struct PLDHashTableOps sOps;
    };

    static IID2ThisTranslatorMap* newMap(int size);

    inline nsIXPCFunctionThisTranslator* Find(REFNSIID iid)
    {
        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, &iid, PL_DHASH_LOOKUP);
        if (PL_DHASH_ENTRY_IS_FREE(entry))
            return nullptr;
        return entry->value;
    }

    inline nsIXPCFunctionThisTranslator* Add(REFNSIID iid,
                                             nsIXPCFunctionThisTranslator* obj)
    {

        Entry* entry = (Entry*)
            PL_DHashTableOperate(mTable, &iid, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        entry->value = obj;
        entry->key = iid;
        return obj;
    }

    inline void Remove(REFNSIID iid)
    {
        PL_DHashTableOperate(mTable, &iid, PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    ~IID2ThisTranslatorMap();
private:
    IID2ThisTranslatorMap();    // no implementation
    IID2ThisTranslatorMap(int size);
private:
    PLDHashTable* mTable;
};

/***************************************************************************/

class XPCNativeScriptableSharedMap
{
public:
    struct Entry : public PLDHashEntryHdr
    {
        XPCNativeScriptableShared* key;

        static PLDHashNumber
        Hash(PLDHashTable* table, const void* key);

        static bool
        Match(PLDHashTable* table,
              const PLDHashEntryHdr* entry,
              const void* key);

        static const struct PLDHashTableOps sOps;
    };

    static XPCNativeScriptableSharedMap* newMap(int size);

    bool GetNewOrUsed(uint32_t flags, char* name, uint32_t interfacesBitmap,
                      XPCNativeScriptableInfo* si);

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    ~XPCNativeScriptableSharedMap();
private:
    XPCNativeScriptableSharedMap();    // no implementation
    XPCNativeScriptableSharedMap(int size);
private:
    PLDHashTable* mTable;
};

/***************************************************************************/

class XPCWrappedNativeProtoMap
{
public:
    static XPCWrappedNativeProtoMap* newMap(int size);

    inline XPCWrappedNativeProto* Add(XPCWrappedNativeProto* proto)
    {
        NS_PRECONDITION(proto,"bad param");
        PLDHashEntryStub* entry = (PLDHashEntryStub*)
            PL_DHashTableOperate(mTable, proto, PL_DHASH_ADD);
        if (!entry)
            return nullptr;
        if (entry->key)
            return (XPCWrappedNativeProto*) entry->key;
        entry->key = proto;
        return proto;
    }

    inline void Remove(XPCWrappedNativeProto* proto)
    {
        NS_PRECONDITION(proto,"bad param");
        PL_DHashTableOperate(mTable, proto, PL_DHASH_REMOVE);
    }

    inline uint32_t Count() {return mTable->entryCount;}
    inline uint32_t Enumerate(PLDHashEnumerator f, void* arg)
        {return PL_DHashTableEnumerate(mTable, f, arg);}

    ~XPCWrappedNativeProtoMap();
private:
    XPCWrappedNativeProtoMap();    // no implementation
    XPCWrappedNativeProtoMap(int size);
private:
    PLDHashTable* mTable;
};

/***************************************************************************/

class JSObject2JSObjectMap
{
    typedef js::HashMap<JSObject*, JS::Heap<JSObject*>, js::PointerHasher<JSObject*, 3>,
                        js::SystemAllocPolicy> Map;

public:
    static JSObject2JSObjectMap* newMap(int size) {
        JSObject2JSObjectMap* map = new JSObject2JSObjectMap();
        if (map && map->mTable.init(size))
            return map;
        delete map;
        return nullptr;
    }

    inline JSObject* Find(JSObject* key) {
        NS_PRECONDITION(key, "bad param");
        if (Map::Ptr p = mTable.lookup(key))
            return p->value();
        return nullptr;
    }

    /* Note: If the entry already exists, return the old value. */
    inline JSObject* Add(JSContext* cx, JSObject* key, JSObject* value) {
        NS_PRECONDITION(key,"bad param");
        Map::AddPtr p = mTable.lookupForAdd(key);
        if (p)
            return p->value();
        if (!mTable.add(p, key, value))
            return nullptr;
        MOZ_ASSERT(xpc::GetCompartmentPrivate(key)->scope->mWaiverWrapperMap == this);
        JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, key, this);
        return value;
    }

    inline void Remove(JSObject* key) {
        NS_PRECONDITION(key,"bad param");
        mTable.remove(key);
    }

    inline uint32_t Count() { return mTable.count(); }

    void Sweep() {
        for (Map::Enum e(mTable); !e.empty(); e.popFront()) {
            JSObject* updated = e.front().key();
            if (JS_IsAboutToBeFinalizedUnbarriered(&updated) || JS_IsAboutToBeFinalized(&e.front().value()))
                e.removeFront();
            else if (updated != e.front().key())
                e.rekeyFront(updated);
        }
    }

    void Reparent(JSContext* aCx, JSObject* aNewInnerArg) {
        JS::RootedObject aNewInner(aCx, aNewInnerArg);
        for (Map::Enum e(mTable); !e.empty(); e.popFront()) {
            /*
             * We reparent wrappers that have as their parent an inner window
             * whose outer has the new inner window as its current inner.
             */
            JS::RootedObject parent(aCx, JS_GetParent(e.front().value()));
            JS::RootedObject outer(aCx, JS_ObjectToOuterObject(aCx, parent));
            if (outer) {
                JSObject* inner = JS_ObjectToInnerObject(aCx, outer);
                if (inner == aNewInner && inner != parent)
                    JS_SetParent(aCx, e.front().value(), aNewInner);
            } else {
                JS_ClearPendingException(aCx);
            }
        }
    }

private:
    JSObject2JSObjectMap() {}

    /*
     * This function is called during minor GCs for each key in the HashMap that
     * has been moved.
     */
    static void KeyMarkCallback(JSTracer* trc, JSObject* key, void* data) {
        /*
         * To stop the barriers on the values of mTable firing while we are
         * marking the store buffer, we cast the table to one that is
         * binary-equivatlent but without the barriers, and update that.
         */
        typedef js::HashMap<JSObject*, JSObject*, js::PointerHasher<JSObject*, 3>,
                            js::SystemAllocPolicy> UnbarrieredMap;
        JSObject2JSObjectMap* self = static_cast<JSObject2JSObjectMap*>(data);
        UnbarrieredMap& table = reinterpret_cast<UnbarrieredMap&>(self->mTable);

        JSObject* prior = key;
        JS_CallObjectTracer(trc, &key, "XPCWrappedNativeScope::mWaiverWrapperMap key");
        table.rekeyIfMoved(prior, key);
    }

    Map mTable;
};

#endif /* xpcmaps_h___ */