예제 #1
0
        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);
                }
            });