]> Lady’s Gitweb - Pisces/commitdiff
Polish object.js a little
authorLady <redacted>
Sun, 25 Sep 2022 07:48:49 +0000 (00:48 -0700)
committerLady <redacted>
Fri, 12 May 2023 03:56:48 +0000 (20:56 -0700)
deno.json
object.js

index e5f93e53683c5a3a375305fd8bfe9f495def097a..5d63df686fcf33bf92cbeacb71ade20c330fb12b 100644 (file)
--- a/deno.json
+++ b/deno.json
@@ -1,4 +1,8 @@
 {
   "fmt": { "options": { "lineWidth": 71 } },
-  "lint": { "rules": { "exclude": ["no-irregular-whitespace"] } }
+  "lint": {
+    "rules": {
+      "exclude": ["constructor-super", "no-irregular-whitespace"]
+    }
+  }
 }
index f68909e659c54aad765e93abc816ac2a480154f0..9986291eb77d1c4cc57143ee9d93760aded80393 100644 (file)
--- a/object.js
+++ b/object.js
@@ -32,39 +32,49 @@ import { toPrimitive, type } from "./value.js";
  * object.
  */
 export class LazyLoader extends null {
-  /** Constructs a new LazyLoader object. */
+  /**
+   * Constructs a new LazyLoader object.
+   *
+   * ☡ This function throws if the provided value is not an object.
+   */
   constructor(loadMethods) {
-    const result = objectCreate(getPrototype(loadMethods));
-    const methodKeys = getOwnPropertyKeys(loadMethods);
-    for (let index = 0; index < methodKeys.length; ++index) {
-      const methodKey = methodKeys[index];
-      const { configurable, enumerable, writable } =
-        getOwnPropertyDescriptor(loadMethods, methodKey);
-      defineOwnProperty(result, methodKey, {
-        configurable: true,
-        enumerable,
-        get: () => {
-          const value = call(loadMethods[methodKey], result, []);
-          defineOwnProperty(result, methodKey, {
-            configurable,
-            enumerable,
-            value,
-            writable,
-          });
-          return value;
-        },
-        set: writable
-          ? ($) =>
+    if (type(loadMethods) !== "object") {
+      throw new TypeError(
+        `Piscēs: Cannot construct LazyLoader: Provided argument is not an object: ${loadMethods}.`,
+      );
+    } else {
+      const result = objectCreate(getPrototype(loadMethods));
+      const methodKeys = getOwnPropertyKeys(loadMethods);
+      for (let index = 0; index < methodKeys.length; ++index) {
+        const methodKey = methodKeys[index];
+        const { configurable, enumerable, writable } =
+          getOwnPropertyDescriptor(loadMethods, methodKey);
+        defineOwnProperty(result, methodKey, {
+          configurable: true,
+          enumerable,
+          get: () => {
+            const value = call(loadMethods[methodKey], result, []);
             defineOwnProperty(result, methodKey, {
               configurable,
               enumerable,
-              value: $,
+              value,
               writable,
-            })
-          : void {},
-      });
+            });
+            return value;
+          },
+          set: writable
+            ? ($) =>
+              defineOwnProperty(result, methodKey, {
+                configurable,
+                enumerable,
+                value: $,
+                writable,
+              })
+            : void {},
+        });
+      }
+      return result;
     }
-    return result;
   }
 }
 
@@ -89,12 +99,11 @@ export const { PropertyDescriptor } = (() => {
      * its `enumerable` property, if defined, will always be a
      * boolean).
      */
-    //deno-lint-ignore constructor-super
     constructor(O) {
       if (type(O) !== "object") {
         // The provided value is not an object.
         throw new TypeError(
-          "Piscēs: Cannot convert primitive to property descriptor.",
+          `Piscēs: Cannot convert primitive to property descriptor: ${O}.`,
         );
       } else {
         // The provided value is an object.
@@ -577,7 +586,7 @@ export const {
    * `delete` operator in that it throws if the deletion is
    * unsuccessful.
    *
-   *  This function throws if the first argument is not an object.
+   *  This function throws if the first argument is not an object.
    */
   deleteOwnProperty,
 
@@ -616,7 +625,7 @@ export const {
    * ※ This function differs from Reflect.set in that it throws if the
    * setting is unsuccessful.
    *
-   *  This function throws if the first argument is not an object.
+   *  This function throws if the first argument is not an object.
    */
   setPropertyValue,
 } = (() => {
@@ -659,7 +668,7 @@ export const {
 export const {
   /**
    * Returns a new frozen shallow copy of the enumerable own properties
-   * of the provided object, according to the following rules:—
+   * of the provided object, according to the following rules :—
    *
    * - For data properties, create a nonconfigurable, nonwritable
    *   property with the same value.
@@ -674,6 +683,8 @@ export const {
    * nonnullish `Symbol.species`, that will be used instead. If the
    * used constructor or species is nullish or does not have a
    * `prototype` property, the prototype is set to null.
+   *
+   * ※ The prototype of the provided object itself is ignored.
    */
   frozenCopy,
 } = (() => {
@@ -758,6 +769,13 @@ export const {
   };
 })();
 
+/**
+ * Returns the function on the provided value at the provided property
+ * key.
+ *
+ * ☡ This function throws if the provided property key does not have an
+ * associated value which is callable.
+ */
 export const getMethod = (V, P) => {
   const func = getPropertyValue(V, P);
   if (func == null) {
@@ -774,8 +792,7 @@ export const getMethod = (V, P) => {
  *
  * Existing objects are returned with no modification.
  *
- * ☡ This function throws a TypeError if its argument is null or
- * undefined.
+ * ☡ This function throws if its argument is null or undefined.
  */
 export const { toObject } = (() => {
   const makeObject = Object;
This page took 0.06818 seconds and 4 git commands to generate.