]> Lady’s Gitweb - Pisces/commitdiff
Provide fake external constructor for Matcher
authorLady <redacted>
Thu, 8 Sep 2022 05:20:46 +0000 (22:20 -0700)
committerLady <redacted>
Fri, 12 May 2023 03:56:48 +0000 (20:56 -0700)
Classes which depend on identity for behaviours should not be exposed
because this inheritance can be modified at runtime. This commit
provides a fake Matcher constructor which simply calls the real one.

This has a side‐effect of reducing the amount of prototype modification
which this class setup entailed, at the cost of needing to manually
redefine all the properties from the internal Matcher constructor
prototype onto the external one.

string.js

index 28412fc98b8854b9b26f248c5e8b8ae98526d033..3dc39acade9259c7c5120c28cde20ad398225426 100644 (file)
--- a/string.js
+++ b/string.js
@@ -10,6 +10,7 @@
 import { bind, call, identity, makeCallable } from "./function.js";
 import {
   defineOwnProperties,
+  getOwnPropertyDescriptors,
   getPrototype,
   objectCreate,
   setPrototype,
@@ -213,12 +214,25 @@ export const {
       return call(getUnicode, this.#regExp, []);
     }
   };
-  const matcherPrototype = setPrototype(
-    Matcher.prototype,
-    rePrototype,
+
+  const matcherConstructor = defineOwnProperties(
+    class extends RegExp {
+      constructor(...args) {
+        return new Matcher(...args);
+      }
+    },
+    {
+      name: { value: "Matcher" },
+      length: { value: 1 },
+    },
+  );
+  const matcherPrototype = defineOwnProperties(
+    matcherConstructor.prototype,
+    getOwnPropertyDescriptors(Matcher.prototype),
+    { constructor: { value: matcherConstructor } },
   );
 
-  return { Matcher };
+  return { Matcher: matcherConstructor };
 })();
 
 export const {
This page took 0.027868 seconds and 4 git commands to generate.