]> Lady’s Gitweb - Pisces/blobdiff - object.test.js
Add methods for own entries and values to object.js
[Pisces] / object.test.js
index 348d06da83332901c8047288658ab08c607cfa56..cba44b948824ba411ecb966ae3e80a1265a3f5c4 100644 (file)
@@ -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(
This page took 0.026289 seconds and 4 git commands to generate.