]> Lady’s Gitweb - Pisces/blobdiff - object.js
Define names for LazyLoader getters & setters
[Pisces] / object.js
index a4037951fcd77fa746e8aabe23a974948e29ed9a..55593a390be0fa6ad1c963d83d8717f16c5929c4 100644 (file)
--- a/object.js
+++ b/object.js
@@ -7,7 +7,7 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
-import { bind, call } from "./function.js";
+import { bind, call, toFunctionName } from "./function.js";
 import { ITERATOR, SPECIES, toPrimitive, type } from "./value.js";
 
 /**
@@ -39,37 +39,50 @@ export class LazyLoader extends null {
    */
   constructor(loadMethods) {
     if (type(loadMethods) !== "object") {
+      // The provided value is not an object; throw an error.
       throw new TypeError(
         `Piscēs: Cannot construct LazyLoader: Provided argument is not an object: ${loadMethods}.`,
       );
     } else {
+      // The provided value is an object; process it and build the
+      // result.
       const result = objectCreate(getPrototype(loadMethods));
       const methodKeys = getOwnPropertyKeys(loadMethods);
       for (let index = 0; index < methodKeys.length; ++index) {
+        // Iterate over the property keys of the provided object and
+        // define getters and setters appropriately on the result.
         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
-            ? ($) =>
+          get: defineOwnProperty(
+            () => {
+              const value = call(loadMethods[methodKey], result, []);
               defineOwnProperty(result, methodKey, {
                 configurable,
                 enumerable,
-                value: $,
+                value,
                 writable,
-              })
+              });
+              return value;
+            },
+            "name",
+            { value: toFunctionName(methodKey, "get") },
+          ),
+          set: writable
+            ? defineOwnProperty(
+              ($) =>
+                defineOwnProperty(result, methodKey, {
+                  configurable,
+                  enumerable,
+                  value: $,
+                  writable,
+                }),
+              "name",
+              { value: toFunctionName(methodKey, "set") },
+            )
             : void {},
         });
       }
This page took 0.029117 seconds and 4 git commands to generate.