]> Lady’s Gitweb - Pisces/commitdiff
Add ::flags override to Matcher 0.3.0
authorLady <redacted>
Sat, 20 May 2023 01:05:32 +0000 (18:05 -0700)
committerLady <redacted>
Sat, 20 May 2023 01:05:32 +0000 (18:05 -0700)
Otherwise this code will break if new flags are added but not supported
by ♓🌟 Piscēs.

string.js
string.test.js

index 3dc39acade9259c7c5120c28cde20ad398225426..eb6f6fb4db0fa5444496190ce61ba766a81cbbd8 100644 (file)
--- a/string.js
+++ b/string.js
@@ -1,7 +1,7 @@
 // ♓🌟 Piscēs ∷ string.js
 // ====================================================================
 //
-// Copyright © 2022 Lady [@ Lady’s Computer].
+// Copyright © 2022–2023 Lady [@ Lady’s Computer].
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -15,6 +15,7 @@ import {
   objectCreate,
   setPrototype,
 } from "./object.js";
+import { type } from "./value.js";
 
 export const {
   /**
@@ -34,6 +35,8 @@ export const {
   const { exec: reExec, toString: reToString } = rePrototype;
   const getDotAll =
     Object.getOwnPropertyDescriptor(rePrototype, "dotAll").get;
+  const getFlags =
+    Object.getOwnPropertyDescriptor(rePrototype, "flags").get;
   const getGlobal =
     Object.getOwnPropertyDescriptor(rePrototype, "global").get;
   const getHasIndices =
@@ -175,6 +178,16 @@ export const {
       }
     }
 
+    /**
+     * Gets the flags present on this Matcher.
+     *
+     * ※ This needs to be defined because the internal RegExp object
+     * may have flags which are not yet recognized by ♓🌟 Piscēs.
+     */
+    get flags() {
+      return call(getFlags, this.#regExp, []);
+    }
+
     /** Gets whether the global flag is present on this Matcher. */
     get global() {
       return call(getGlobal, this.#regExp, []);
index 94aec3701c30abfb4bb2298c739cfd6bc11496de..95c715e3636b5bee2b1fef6e775a2ccfcf5a3549 100644 (file)
@@ -184,6 +184,12 @@ describe("Matcher", () => {
     });
   });
 
+  describe("::toString", () => {
+    it("[[Get]] does not throw an error", () => {
+      new Matcher(/(?:)/u).toString();
+    });
+  });
+
   describe("::unicode", () => {
     it("[[Get]] returns true when the unicode flag is present", () => {
       assertStrictEquals(new Matcher(/(?:)/u).unicode, true);
This page took 0.026989 seconds and 4 git commands to generate.