]> Lady’s Gitweb - Pisces/commitdiff
Rename scalarValueString → toScalarValueString
authorLady <redacted>
Sat, 11 Nov 2023 03:12:06 +0000 (22:12 -0500)
committerLady <redacted>
Fri, 17 Nov 2023 02:24:03 +0000 (21:24 -0500)
Also update the implementation to use the new `String::toWellFormed`
method.

string.js
string.test.js

index 774261dbdf90f8a8e49e38e51f4e61069d318a6a..0c603acbfa47b70c051c1c452ab3bbce582a88c7 100644 (file)
--- a/string.js
+++ b/string.js
@@ -21,11 +21,8 @@ import {
 import {
   defineOwnProperties,
   getOwnPropertyDescriptors,
-  getPrototype,
-  objectCreate,
   setPrototype,
 } from "./object.js";
-import { ITERATOR } from "./value.js";
 
 const RE = RegExp;
 const { prototype: rePrototype } = RE;
@@ -330,13 +327,6 @@ export const {
    * with U+FFFD.
    */
   scalarValues,
-
-  /**
-   * Returns the result of converting the provided value to a string of
-   * scalar values by replacing (unpaired) surrogate values with
-   * U+FFFD.
-   */
-  scalarValueString,
 } = (() => {
   const generateCharacters = function* (character) {
     yield character;
@@ -368,31 +358,12 @@ export const {
     bind(generateCodepoints, { allowSurrogates: false }, []),
     "String Scalar Value Iterator",
   );
-  const {
-    next: scalarValuesNext,
-  } = getPrototype(scalarValuesIterator(""));
-  const scalarValueIterablePrototype = {
-    [ITERATOR]() {
-      return {
-        next: bind(
-          scalarValuesNext,
-          scalarValuesIterator(this.source),
-          [],
-        ),
-      };
-    },
-  };
 
   return {
     characters: ($) => charactersIterator(`${$}`),
     codeUnits: ($) => codeUnitsIterator(`${$}`),
     codepoints: ($) => codepointsIterator(`${$}`),
     scalarValues: ($) => scalarValuesIterator(`${$}`),
-    scalarValueString: ($) =>
-      stringFromCodepoints(...objectCreate(
-        scalarValueIterablePrototype,
-        { source: { value: `${$}` } },
-      )),
   };
 })();
 
@@ -760,6 +731,16 @@ export const substring = createCallableFunction(
   stringPrototype.substring,
 );
 
+/**
+ * Returns the result of converting the provided value to a string of
+ * scalar values by replacing (unpaired) surrogate values with
+ * U+FFFD.
+ */
+export const toScalarValueString = createCallableFunction(
+  String.prototype.toWellFormed,
+  { name: "toScalarValueString" },
+);
+
 /**
  * Returns the result of converting the provided value to a string.
  *
index 4f257f9f96f28a8d799cb0fd447c28895e429c00..e98a040bdd1f080697f8c094c41498b4678a3075 100644 (file)
@@ -32,7 +32,6 @@ import {
   Matcher,
   rawString,
   scalarValues,
-  scalarValueString,
   splitOnASCIIWhitespace,
   splitOnCommas,
   stringCatenate,
@@ -56,6 +55,7 @@ import {
   stripAndCollapseASCIIWhitespace,
   stripLeadingAndTrailingASCIIWhitespace,
   substring,
+  toScalarValueString,
   toString,
 } from "./string.js";
 
@@ -934,31 +934,6 @@ describe("rawString", () => {
   });
 });
 
-describe("scalarValueString", () => {
-  it("[[Call]] replaces invalid values", () => {
-    assertStrictEquals(
-      scalarValueString("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
-      "Ii🎙\uFFFD\uFFFD\uFFFD\uFFFD🆗☺",
-    );
-  });
-
-  it("[[Construct]] throws an error", () => {
-    assertThrows(() => new scalarValueString(""));
-  });
-
-  describe(".length", () => {
-    it("[[Get]] returns the correct length", () => {
-      assertStrictEquals(scalarValueString.length, 1);
-    });
-  });
-
-  describe(".name", () => {
-    it("[[Get]] returns the correct name", () => {
-      assertStrictEquals(scalarValueString.name, "scalarValueString");
-    });
-  });
-});
-
 describe("scalarValues", () => {
   it("[[Call]] returns an iterable", () => {
     assertStrictEquals(
@@ -1914,6 +1889,34 @@ describe("substring", () => {
   });
 });
 
+describe("toScalarValueString", () => {
+  it("[[Call]] replaces invalid values", () => {
+    assertStrictEquals(
+      toScalarValueString("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
+      "Ii🎙\uFFFD\uFFFD\uFFFD\uFFFD🆗☺",
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new toScalarValueString(""));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(toScalarValueString.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        toScalarValueString.name,
+        "toScalarValueString",
+      );
+    });
+  });
+});
+
 describe("toString", () => {
   it("[[Call]] converts to a string", () => {
     assertStrictEquals(
This page took 0.025108 seconds and 4 git commands to generate.