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); }); }
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); } });