X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/54b756dbfe3e86b528253082215a9354e14313f0..HEAD:/object.test.js diff --git a/object.test.js b/object.test.js index 348d06d..cba44b9 100644 --- a/object.test.js +++ b/object.test.js @@ -30,9 +30,12 @@ import { getMethod, getOwnPropertyDescriptor, getOwnPropertyDescriptors, + getOwnPropertyEntries, getOwnPropertyKeys, getOwnPropertyStrings, getOwnPropertySymbols, + getOwnPropertyValue, + getOwnPropertyValues, getPropertyValue, getPrototype, hasOwnProperty, @@ -840,6 +843,58 @@ describe("getOwnPropertyDescriptors", () => { }); }); +describe("getOwnPropertyEntries", () => { + it("[[Call]] gets own (but not inherited) property entries", () => { + assertEquals( + getOwnPropertyEntries({ success: true }), + [["success", true]], + ); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertEquals( + getOwnPropertyEntries("foo"), + [["0", "f"], ["1", "o"], ["2", "o"], ["length", 3]], + ); + }); + + it("[[Call]] uses the provided receiver", () => { + const target = {}; + assertEquals( + getOwnPropertyEntries({ + get success() { + return this; + }, + }, target), + [["success", target]], + ); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => getOwnPropertyEntries(null)); + assertThrows(() => getOwnPropertyEntries(undefined)); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => new getOwnPropertyEntries({})); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(getOwnPropertyEntries.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + getOwnPropertyEntries.name, + "getOwnPropertyEntries", + ); + }); + }); +}); + describe("getOwnPropertyKeys", () => { it("[[Call]] gets own (but not inherited) property keys", () => { assertEquals(getOwnPropertyKeys({ success: true }), ["success"]); @@ -950,6 +1005,115 @@ describe("getOwnPropertySymbols", () => { }); }); +describe("getOwnPropertyValue", () => { + it("[[Call]] gets the own property value", () => { + assertStrictEquals( + getOwnPropertyValue({ success: true }, "success"), + true, + ); + }); + + it("[[Call]] returns undefined for non‐own properties", () => { + assertStrictEquals( + getOwnPropertyValue(Object.create({ success: true }), "success"), + undefined, + ); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertStrictEquals(getOwnPropertyValue("foo", "length"), 3); + }); + + it("[[Call]] uses the provided receiver", () => { + const target = {}; + assertStrictEquals( + getOwnPropertyValue( + { + get success() { + return this; + }, + }, + "success", + target, + ), + target, + ); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => getOwnPropertyValue(null)); + assertThrows(() => getOwnPropertyValue(undefined)); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => new getOwnPropertyValue({})); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(getOwnPropertyValue.length, 2); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + getOwnPropertyValue.name, + "getOwnPropertyValue", + ); + }); + }); +}); + +describe("getOwnPropertyValues", () => { + it("[[Call]] gets own (but not inherited) property values", () => { + assertEquals(getOwnPropertyValues({ success: true }), [true]); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertEquals( + getOwnPropertyValues("foo"), + ["f", "o", "o", 3], + ); + }); + + it("[[Call]] uses the provided receiver", () => { + const target = {}; + assertEquals( + getOwnPropertyValues({ + get success() { + return this; + }, + }, target), + [target], + ); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => getOwnPropertyValues(null)); + assertThrows(() => getOwnPropertyValues(undefined)); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => new getOwnPropertyValues({})); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(getOwnPropertyValues.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + getOwnPropertyValues.name, + "getOwnPropertyValues", + ); + }); + }); +}); + describe("getPropertyValue", () => { it("[[Call]] gets property values on the provided object", () => { assertStrictEquals(