X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/50ab30fc3a257e46da6b8bdc0dad054f729e16e1..f6b84c13c5c539dbac4f4b9b530eeec95d683475:/object.test.js diff --git a/object.test.js b/object.test.js index 38d333f..3a0e1a7 100644 --- a/object.test.js +++ b/object.test.js @@ -19,6 +19,8 @@ import { spy, } from "./dev-deps.js"; import { + defineOwnDataProperty, + defineOwnNonenumerableDataProperty, defineOwnProperties, defineOwnProperty, deleteOwnProperty, @@ -309,11 +311,113 @@ describe("LazyLoader", () => { }); }); +describe("defineOwnDataProperty", () => { + it("[[Call]] defines the property", () => { + const obj = {}; + defineOwnDataProperty(obj, "etaoin", "success"); + assert(Object.hasOwn(obj, "etaoin")); + assertStrictEquals(obj.etaoin, "success"); + }); + + it("[[Call]] defines a configurable, enumerable, writable property", () => { + const obj = {}; + defineOwnDataProperty(obj, "etaoin", "success"); + assertEquals( + Object.getOwnPropertyDescriptor(obj, "etaoin"), + { + configurable: true, + enumerable: true, + value: "success", + writable: true, + }, + ); + }); + + it("[[Call]] returns the provided object", () => { + const obj = {}; + assertStrictEquals( + defineOwnDataProperty(obj, "etaoin", null), + obj, + ); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => new defineOwnDataProperty(obj, "etaoin", null)); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(defineOwnDataProperty.length, 3); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + defineOwnDataProperty.name, + "defineOwnDataProperty", + ); + }); + }); +}); + +describe("defineOwnNonenumerableDataProperty", () => { + it("[[Call]] defines the property", () => { + const obj = {}; + defineOwnNonenumerableDataProperty(obj, "etaoin", "success"); + assert(Object.hasOwn(obj, "etaoin")); + assertStrictEquals(obj.etaoin, "success"); + }); + + it("[[Call]] defines a configurable, non·enumerable, writable property", () => { + const obj = {}; + defineOwnNonenumerableDataProperty(obj, "etaoin", "success"); + assertEquals( + Object.getOwnPropertyDescriptor(obj, "etaoin"), + { + configurable: true, + enumerable: false, + value: "success", + writable: true, + }, + ); + }); + + it("[[Call]] returns the provided object", () => { + const obj = {}; + assertStrictEquals( + defineOwnNonenumerableDataProperty(obj, "etaoin", null), + obj, + ); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => + new defineOwnNonenumerableDataProperty(obj, "etaoin", null) + ); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(defineOwnNonenumerableDataProperty.length, 3); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + defineOwnNonenumerableDataProperty.name, + "defineOwnNonenumerableDataProperty", + ); + }); + }); +}); + describe("defineOwnProperty", () => { it("[[Call]] defines the property", () => { const obj = {}; defineOwnProperty(obj, "etaoin", {}); - assert("etaoin" in obj); + assert(Object.hasOwn(obj, "etaoin")); }); it("[[Call]] returns the provided object", () => { @@ -525,17 +629,45 @@ describe("frozenCopy", () => { ); }); + it("[[Call]] preserves data properties", () => { + const properties = { + implied: { + configurable: false, + enumerable: true, + }, + writable: { + configurable: false, + enumerable: true, + value: "etaoin", + writable: true, + }, + nonwritable: { + configurable: false, + enumerable: true, + value: "shrdlu", + writable: false, + }, + }; + assertEquals( + Object.getOwnPropertyDescriptors( + frozenCopy(Object.create(null, properties)), + ), + { + implied: { + ...properties.implied, + value: undefined, + writable: false, + }, + writable: { ...properties.writable, writable: false }, + nonwritable: properties.nonwritable, + }, + ); + }); + it("[[Call]] does not copy properties on the prototype", () => { assert( !("failure" in - frozenCopy(Object.create({ failure: undefined }), { - data: { - configurable: true, - value: undefined, - writable: true, - }, - accessor: { configurable: true, get: undefined }, - })), + frozenCopy(Object.create({ failure: undefined }))), ); });