]> Lady’s Gitweb - Pisces/blobdiff - object.test.js
Refactor object.js not to depend on function.js
[Pisces] / object.test.js
index 38d333f75d273c61abbfc0e51a7fdb6b620ce560..3a0e1a73363a94d855ede03c3ed99ba7e67265f0 100644 (file)
@@ -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 }))),
     );
   });
 
This page took 0.026051 seconds and 4 git commands to generate.