/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: set ts=8 sts=2 et sw=2 tw=80:
*/ /* 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/. */
JS::RootedString test(cx, JS_NewStringCopyZ(cx, "test")); // sym is a Symbol in global Symbol registry and hence can't be used as a key.
JS::RootedSymbol sym(cx, JS::GetSymbolFor(cx, test));
JS::RootedValue key(cx, JS::SymbolValue(sym));
CHECK(!key.isUndefined());
/* * Perform an incremental GC, introducing an unmarked CCW to force the map * zone to finish marking before the delegate zone.
*/
CHECK(newCCW(map, delegateRoot));
performIncrementalGC(); #ifdef DEBUG
CHECK(map->zone()->lastSweepGroupIndex() <
delegateRoot->zone()->lastSweepGroupIndex()); #endif
/* * Check the delegate keeps the entry alive even if the key is not reachable.
*/
key = nullptr;
keyVal.setUndefined();
CHECK(newCCW(map, delegateRoot));
performIncrementalGC();
CHECK(checkSize(cx, map, 1));
/* * Check that the zones finished marking at the same time, which is * necessary because of the presence of the delegate and the CCW.
*/ #ifdef DEBUG
CHECK(map->zone()->lastSweepGroupIndex() ==
delegateRoot->zone()->lastSweepGroupIndex()); #endif
/* Check that when the delegate becomes unreachable the entry is removed. */
delegateRoot = nullptr;
keyDelegate = nullptr;
JS_GC(cx);
CHECK(checkSize(cx, map, 0));
returntrue;
}
static size_t DelegateObjectMoved(JSObject* obj, JSObject* old) { if (!keyDelegate) { return 0; // Object got moved before we set keyDelegate to point to it.
}
JS::RootedObject key(cx, JS_NewObject(cx, &keyClass)); if (!key) { return nullptr;
}
return key;
}
JSObject* newCCW(JS::HandleObject sourceZone, JS::HandleObject destZone) { /* * Now ensure that this zone will be swept first by adding a cross * compartment wrapper to a new object in the same zone as the * delegate object.
*/
JS::RootedObject object(cx);
{
JSAutoRealm ar(cx, destZone);
object = JS_NewPlainObject(cx); if (!object) { return nullptr;
}
}
{
JSAutoRealm ar(cx, sourceZone); if (!JS_WrapObject(cx, &object)) { return nullptr;
}
}
// In order to test the SCC algorithm, we need the wrapper/wrappee to be // tenured.
cx->runtime()->gc.evictNursery();
// Wait until we've started marking before finishing the GC // non-incrementally. while (rt->gc.state() == gc::State::Prepare) {
rt->gc.debugGCSlice(budget);
} if (JS::IsIncrementalGCInProgress(cx)) {
rt->gc.finishGC(JS::GCReason::DEBUG_GC);
}
}
END_TEST(testWeakMap_keyDelegates)
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.