public void TestWeakSet() { var ws = new WeakSet<object>(); var o = new Object(); ws.Add(o); ws.Add(o); Assert.AreEqual(1, ws.Count); foreach (var item in ws) Assert.AreEqual(item, o); ws.Remove(o); Assert.AreEqual(0, ws.Count); AddObject(ws); AddObject(ws); Assert.AreEqual(2, ws.Count); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); int iC = 0; foreach (var item in ws) iC++; Assert.AreEqual(0, iC); Assert.AreEqual(2, ws.Count); ws.WeakCleanup(); Assert.AreEqual(0, ws.Count); }
public void TestWeakSet() { var ws = new WeakSet <object>(); var o = new Object(); ws.Add(o); ws.Add(o); Assert.AreEqual(1, ws.Count); foreach (var item in ws) { Assert.AreEqual(item, o); } ws.Remove(o); Assert.AreEqual(0, ws.Count); AddObject(ws); AddObject(ws); Assert.AreEqual(2, ws.Count); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); int iC = 0; foreach (var item in ws) { iC++; } Assert.AreEqual(0, iC); Assert.AreEqual(2, ws.Count); ws.WeakCleanup(); Assert.AreEqual(0, ws.Count); }
public static WeakSet <ISymbol> GetUnrootedSymbols(Compilation compilation) { var result = new WeakSet <ISymbol>(); var compAssembly = compilation.Assembly; result.Add(compAssembly); // The dynamic type is also unrooted (i.e. doesn't point back at the compilation or source // assembly). So we have to keep track of it so we can get back from it to a project in case the // underlying compilation is GC'ed. if (compilation.Language == LanguageNames.CSharp) { result.Add(compilation.DynamicType); } foreach (var reference in compilation.References) { var symbol = compilation.GetAssemblyOrModuleSymbol(reference); if (symbol == null) { continue; } result.Add(symbol); } return(result); }
public static UnrootedSymbolSet GetUnrootedSymbols(Compilation compilation) { var primaryAssembly = new WeakReference <IAssemblySymbol>(compilation.Assembly); // The dynamic type is also unrooted (i.e. doesn't point back at the compilation or source // assembly). So we have to keep track of it so we can get back from it to a project in case the // underlying compilation is GC'ed. var primaryDynamic = new WeakReference <ITypeSymbol?>( compilation.Language == LanguageNames.CSharp ? compilation.DynamicType : null); var secondarySymbols = new WeakSet <ISymbol>(); foreach (var reference in compilation.References) { var symbol = compilation.GetAssemblyOrModuleSymbol(reference); if (symbol == null) { continue; } secondarySymbols.Add(symbol); } return(new UnrootedSymbolSet(primaryAssembly, primaryDynamic, secondarySymbols)); }
static FileLog() { var cleanupPeriod = TimeSpan.FromSeconds(5); DefaultMuxer = new MultiFileMuxer(new SingleFileMuxerFactory()); DefaultMuxer.InitiateOrphanedRegistrationsCleanup(cleanupPeriod); Instances = new WeakSet <FileLog>(); Instances.InitiatePurge(cleanupPeriod); }
public void Clear(RuntimeFunction clear) { IsUnconstructableFunctionWLength(clear, "clear", 0); It("should throw a TypeError when this is not an object", () => { Case(Undefined, Throws.TypeError); Case(Null, Throws.TypeError); Case(false, Throws.TypeError); Case(0, Throws.TypeError); Case("", Throws.TypeError); Case(new Symbol(), Throws.TypeError); }); It("should throw a TypeError when this object has no [[MapData]] internal slot", () => { Case(EcmaArray.Of(), Throws.TypeError); Case(Map.Prototype, Throws.TypeError); Case(Object.Construct(), Throws.TypeError); Case(Global.Set.Construct(), Throws.TypeError); Case(WeakSet.Construct(), Throws.TypeError); }); It("should clear a Map object", () => { EcmaValue map = Map.Construct(EcmaArray.Of( EcmaArray.Of("foo", "bar"), EcmaArray.Of(1, 1) )); clear.Call(map); That(map["size"], Is.EqualTo(0)); map = Map.Construct(); map.Invoke("set", "foo", "bar"); map.Invoke("set", 1, 1); clear.Call(map); That(map["size"], Is.EqualTo(0)); }); It("should return undefined", () => { EcmaValue map = Map.Construct(); Case(map, Undefined); Case(map, Undefined); }); It("should not break iterator", () => { EcmaValue map = Map.Construct(EcmaArray.Of( EcmaArray.Of("a", 1), EcmaArray.Of("b", 2), EcmaArray.Of("c", 3) )); EcmaValue iterator = map.Invoke("entries"); iterator.Invoke("next"); clear.Call(map); VerifyIteratorResult(iterator.Invoke("next"), true); }); }
protected State( ValueSource <Optional <Compilation> >?compilation, Compilation?declarationOnlyCompilation, TrackedGeneratorDriver generatorDriver, WeakSet <ISymbol>?unrootedSymbolSet) { // Declaration-only compilations should never have any references Contract.ThrowIfTrue(declarationOnlyCompilation != null && declarationOnlyCompilation.ExternalReferences.Any()); Compilation = compilation; DeclarationOnlyCompilation = declarationOnlyCompilation; GeneratorDriver = generatorDriver; UnrootedSymbolSet = unrootedSymbolSet; }
public void Constructor(RuntimeFunction ctor) { IsConstructorWLength(ctor, "WeakSet", 0, WeakSet.Prototype); That(GlobalThis, Has.OwnProperty("WeakSet", ctor, EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable)); It("must be called as constructor", () => { That(() => WeakSet.Call(This), Throws.TypeError); That(() => WeakSet.Call(This, EcmaArray.Of()), Throws.TypeError); }); It("should return a new WeakSet object if iterable is undefined or null", () => { That(Object.Invoke("getPrototypeOf", WeakSet.Construct()), Is.EqualTo(WeakSet.Prototype)); That(Object.Invoke("getPrototypeOf", WeakSet.Construct(Undefined)), Is.EqualTo(WeakSet.Prototype)); That(Object.Invoke("getPrototypeOf", WeakSet.Construct(Null)), Is.EqualTo(WeakSet.Prototype)); }); It("should throw a TypeError if object is not iterable", () => { That(() => WeakSet.Construct(Object.Construct()), Throws.TypeError); }); It("should throw TypeError if add is not callable only when iterable is not undefined or null", () => { using (TempProperty(WeakSet.Prototype, "add", Null)) { That(() => WeakSet.Construct(EcmaArray.Of()), Throws.TypeError); That(() => WeakSet.Construct(), Throws.Nothing); That(() => WeakSet.Construct(Undefined), Throws.Nothing); That(() => WeakSet.Construct(Null), Throws.Nothing); } }); It("should return abrupt from getting add mehod only when iterable is not undefined or null", () => { using (TempProperty(WeakSet.Prototype, "add", EcmaPropertyDescriptor.FromValue(CreateObject(("get", ThrowTest262Exception), ("configurable", true))))) { That(() => WeakSet.Construct(EcmaArray.Of()), Throws.Test262); That(() => WeakSet.Construct(), Throws.Nothing); That(() => WeakSet.Construct(Undefined), Throws.Nothing); That(() => WeakSet.Construct(Null), Throws.Nothing); } });
void AddObject(WeakSet <object> ws) { ws.Add(new Object()); }
void AddObject(WeakSet<object> ws) { ws.Add(new Object()); }
public UnrootedSymbolSet(WeakReference <IAssemblySymbol> primaryAssemblySymbol, WeakReference <ITypeSymbol?> primaryDynamicSymbol, WeakSet <ISymbol> secondaryReferencedSymbols) { PrimaryAssemblySymbol = primaryAssemblySymbol; PrimaryDynamicSymbol = primaryDynamicSymbol; SecondaryReferencedSymbols = secondaryReferencedSymbols; }
void UpdateScopeMap() { foreach (var t in pendingItems.ToList()) { if (!t.IsLoaded()) continue; var s = FindScope(t); var ws = map[s]; if (ws == null) map[s] = ws = new WeakSet<DependencyObject>(); ws.Add(t); pendingItems.Remove(t); } }