]> Lady’s Gitweb - Pisces/commitdiff
Export welknown symbols from value.js and use them
authorLady <redacted>
Sun, 25 Jun 2023 00:06:14 +0000 (17:06 -0700)
committerLady <redacted>
Sun, 25 Jun 2023 05:23:24 +0000 (22:23 -0700)
This commit changes function.js to depend on value.js and not the other
way around.

binary.js
function.js
iri.js
object.js
string.js
value.js
value.test.js

index deb13dba190cab9afd28d1dcfabf16a4b93723d9..686d3a254df1ac25889ec6e5da2090f55eb897b5 100644 (file)
--- a/binary.js
+++ b/binary.js
@@ -17,23 +17,23 @@ import {
   stringFromCodeUnits,
   stringReplace,
 } from "./string.js";
+import { ITERATOR } from "./value.js";
 
 const Buffer = ArrayBuffer;
 const View = DataView;
 const TypedArray = Object.getPrototypeOf(Uint8Array);
 const { prototype: arrayPrototype } = Array;
 const { prototype: bufferPrototype } = Buffer;
-const { iterator: iteratorSymbol } = Symbol;
 const { prototype: rePrototype } = RegExp;
 const { prototype: typedArrayPrototype } = TypedArray;
 const { prototype: viewPrototype } = View;
 
-const { [iteratorSymbol]: arrayIterator } = arrayPrototype;
+const { [ITERATOR]: arrayIterator } = arrayPrototype;
 const {
   next: arrayIteratorNext,
-} = Object.getPrototypeOf([][iteratorSymbol]());
+} = Object.getPrototypeOf([][ITERATOR]());
 const argumentIterablePrototype = {
-  [iteratorSymbol]() {
+  [ITERATOR]() {
     return {
       next: bind(
         arrayIteratorNext,
@@ -44,7 +44,7 @@ const argumentIterablePrototype = {
   },
 };
 const binaryCodeUnitIterablePrototype = {
-  [iteratorSymbol]() {
+  [ITERATOR]() {
     return {
       next: bind(
         arrayIteratorNext,
index 46cab860fb27e655a44fba66d211b253758637da..72b3b0d69aa940190b7c85f79cae72cb0893c38c 100644 (file)
@@ -1,12 +1,14 @@
 // ♓🌟 Piscēs ∷ function.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
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
+import { ITERATOR } from "./value.js";
+
 export const {
   /**
    * Creates a bound function from the provided function using the
@@ -40,13 +42,12 @@ export const {
     defineProperty: defineOwnProperty,
     getPrototypeOf: getPrototype,
   } = Object;
-  const { iterator: iteratorSymbol } = Symbol;
-  const { [iteratorSymbol]: arrayIterator } = Array.prototype;
+  const { [ITERATOR]: arrayIterator } = Array.prototype;
   const {
     next: arrayIteratorNext,
-  } = getPrototype([][iteratorSymbol]());
+  } = getPrototype([][ITERATOR]());
   const argumentIterablePrototype = {
-    [iteratorSymbol]() {
+    [ITERATOR]() {
       return {
         next: callBind(
           arrayIteratorNext,
diff --git a/iri.js b/iri.js
index 47b1fb83edf81dfa56e4594a8f3e4ae17c5f1c34..5dd9dd098ed778e7e8984e8e20484f0c0f9b6d1d 100644 (file)
--- a/iri.js
+++ b/iri.js
@@ -1,7 +1,7 @@
 // ♓🌟 Piscēs ∷ iri.js
 // ====================================================================
 //
-// Copyright © 2020, 2022 Lady [@ Lady’s Computer].
+// Copyright © 2020, 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
@@ -20,6 +20,7 @@ import {
   stringStartsWith,
   substring,
 } from "./string.js";
+import { ITERATOR } from "./value.js";
 
 const sub·delims = rawString`[!\$&'()*+,;=]`;
 const gen·delims = rawString`[:/?#\[\]@]`;
@@ -198,24 +199,23 @@ export const {
   removeDotSegments,
 } = (() => {
   const TE = TextEncoder;
-  const { iterator: iteratorSymbol } = Symbol;
   const { toString: numberToString } = Number.prototype;
   const { encode: teEncode } = TE.prototype;
 
-  const { [iteratorSymbol]: arrayIterator } = Array.prototype;
+  const { [ITERATOR]: arrayIterator } = Array.prototype;
   const {
     next: arrayIteratorNext,
-  } = Object.getPrototypeOf([][iteratorSymbol]());
+  } = Object.getPrototypeOf([][ITERATOR]());
   const {
     next: generatorIteratorNext,
   } = Object.getPrototypeOf(function* () {}.prototype);
-  const { [iteratorSymbol]: stringIterator } = String.prototype;
+  const { [ITERATOR]: stringIterator } = String.prototype;
   const {
     next: stringIteratorNext,
-  } = Object.getPrototypeOf(""[iteratorSymbol]());
+  } = Object.getPrototypeOf(""[ITERATOR]());
 
   const iriCharacterIterablePrototype = {
-    [iteratorSymbol]() {
+    [ITERATOR]() {
       return {
         next: bind(
           stringIteratorNext,
@@ -226,14 +226,14 @@ export const {
     },
   };
   const iriGeneratorIterablePrototype = {
-    [iteratorSymbol]() {
+    [ITERATOR]() {
       return {
         next: bind(generatorIteratorNext, this.generator(), []),
       };
     },
   };
   const iriSegmentIterablePrototype = {
-    [iteratorSymbol]() {
+    [ITERATOR]() {
       return {
         next: bind(
           arrayIteratorNext,
index 9986291eb77d1c4cc57143ee9d93760aded80393..71b81dbf360277c990c9aeaab874d62626682f56 100644 (file)
--- a/object.js
+++ b/object.js
@@ -1,14 +1,14 @@
 // ♓🌟 Piscēs ∷ object.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
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
 import { bind, call } from "./function.js";
-import { toPrimitive, type } from "./value.js";
+import { ITERATOR, SPECIES, toPrimitive, type } from "./value.js";
 
 /**
  * An object whose properties are lazy‐loaded from the methods on the
@@ -688,15 +688,11 @@ export const {
    */
   frozenCopy,
 } = (() => {
-  const {
-    iterator: iteratorSymbol,
-    species: speciesSymbol,
-  } = Symbol;
   const {
     next: generatorIteratorNext,
   } = getPrototype(function* () {}.prototype);
   const propertyDescriptorEntryIterablePrototype = {
-    [iteratorSymbol]() {
+    [ITERATOR]() {
       return {
         next: bind(generatorIteratorNext, this.generator(), []),
       };
@@ -714,7 +710,7 @@ export const {
         //
         // (If not provided, the constructor will be the value of
         // getting the `constructor` property of O.)
-        const species = constructor?.[speciesSymbol] ?? constructor;
+        const species = constructor?.[SPECIES] ?? constructor;
         return preventExtensions(
           objectCreate(
             species == null || !("prototype" in species)
index eb6f6fb4db0fa5444496190ce61ba766a81cbbd8..c8805d9d3d63d48a508f29fbeee8e83dc61ef8ba 100644 (file)
--- a/string.js
+++ b/string.js
@@ -15,7 +15,7 @@ import {
   objectCreate,
   setPrototype,
 } from "./object.js";
-import { type } from "./value.js";
+import { ITERATOR, TO_STRING_TAG, type } from "./value.js";
 
 export const {
   /**
@@ -310,21 +310,17 @@ export const {
    */
   scalarValueString,
 } = (() => {
-  const {
-    iterator: iteratorSymbol,
-    toStringTag: toStringTagSymbol,
-  } = Symbol;
-  const { [iteratorSymbol]: arrayIterator } = Array.prototype;
+  const { [ITERATOR]: arrayIterator } = Array.prototype;
   const arrayIteratorPrototype = Object.getPrototypeOf(
-    [][iteratorSymbol](),
+    [][ITERATOR](),
   );
   const { next: arrayIteratorNext } = arrayIteratorPrototype;
   const iteratorPrototype = Object.getPrototypeOf(
     arrayIteratorPrototype,
   );
-  const { [iteratorSymbol]: stringIterator } = String.prototype;
+  const { [ITERATOR]: stringIterator } = String.prototype;
   const stringIteratorPrototype = Object.getPrototypeOf(
-    ""[iteratorSymbol](),
+    ""[ITERATOR](),
   );
   const { next: stringIteratorNext } = stringIteratorPrototype;
 
@@ -413,7 +409,7 @@ export const {
         value: stringCodeValueIteratorNext,
         writable: true,
       },
-      [toStringTagSymbol]: {
+      [TO_STRING_TAG]: {
         configurable: true,
         enumerable: false,
         value: "String Code Value Iterator",
@@ -422,7 +418,7 @@ export const {
     },
   );
   const scalarValueIterablePrototype = {
-    [iteratorSymbol]() {
+    [ITERATOR]() {
       return {
         next: bind(
           stringCodeValueIteratorNext,
@@ -463,7 +459,7 @@ export const {
  * String::[Symbol.iterator].
  */
 export const characters = makeCallable(
-  String.prototype[Symbol.iterator],
+  String.prototype[ITERATOR],
 );
 
 /**
index 77cb6b40448f5ca4ae7d08cf001625242c1e09a3..782c857f934f6eaee9a107c940cfb22df2ea69ac 100644 (file)
--- a/value.js
+++ b/value.js
@@ -1,13 +1,49 @@
 // ♓🌟 Piscēs ∷ value.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
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
-import { call } from "./function.js";
+export const {
+  /** The welknown `@@asyncIterator` symbol. */
+  asyncIterator: ASYNC_ITERATOR,
+
+  /** The welknown `@@hasInstance` symbol. */
+  hasInstance: HAS_INSTANCE,
+
+  /** The welknown `@@isConcatSpreadable` symbol. */
+  isConcatSpreadable: IS_CONCAT_SPREADABLE,
+
+  /** The welknown `@@iterator` symbol. */
+  iterator: ITERATOR,
+
+  /** The welknown `@@match` symbol. */
+  match: MATCH,
+
+  /** The welknown `@@matchAll` symbol. */
+  matchAll: MATCH_ALL,
+
+  /** The welknown `@@replace` symbol. */
+  replace: REPLACE,
+
+  /** The welknown `@@species` symbol. */
+  species: SPECIES,
+
+  /** The welknown `@@split` symbol. */
+  split: SPLIT,
+
+  /** The welknown `@@toPrimitive` symbol. */
+  toPrimitive: TO_PRIMITIVE,
+
+  /** The welknown `@@toStringTag` symbol. */
+  toStringTag: TO_STRING_TAG,
+
+  /** The welknown `@@unscopables` symbol. */
+  unscopables: UNSCOPABLES,
+} = Symbol;
 
 /** The null primitive. */
 export const NULL = null;
@@ -40,7 +76,7 @@ export const {
    */
   toPrimitive,
 } = (() => {
-  const { toPrimitive: toPrimitiveSymbol } = Symbol;
+  const { apply: call } = Reflect;
 
   return {
     ordinaryToPrimitive: (O, hint) => {
@@ -80,7 +116,7 @@ export const {
         );
       } else if (type($) === "object") {
         // The provided value is an object.
-        const exoticToPrim = $[toPrimitiveSymbol] ?? undefined;
+        const exoticToPrim = $[TO_PRIMITIVE] ?? undefined;
         if (exoticToPrim !== undefined) {
           // The provided value has an exotic primitive conversion
           // method.
index 6729b85cbc43eacf93f18b43ffe98f44d2d9690e..df8677801934ecb7a09b878e36fe3fe6c2a155be 100644 (file)
@@ -1,7 +1,7 @@
 // ♓🌟 Piscēs ∷ value.test.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,27 +15,114 @@ import {
   it,
 } from "./dev-deps.js";
 import {
+  ASYNC_ITERATOR,
+  HAS_INSTANCE,
+  IS_CONCAT_SPREADABLE,
+  ITERATOR,
+  MATCH,
+  MATCH_ALL,
   NULL,
   ordinaryToPrimitive,
+  REPLACE,
   sameValue,
   sameValueZero,
+  SPECIES,
+  SPLIT,
+  TO_PRIMITIVE,
+  TO_STRING_TAG,
   toPrimitive,
   type,
   UNDEFINED,
+  UNSCOPABLES,
 } from "./value.js";
 
+describe("ASYNC_ITERATOR", () => {
+  it("[[Get]] is @@asyncIterator", () => {
+    assertStrictEquals(ASYNC_ITERATOR, Symbol.asyncIterator);
+  });
+});
+
+describe("HAS_INSTANCE", () => {
+  it("[[Get]] is @@hasInstance", () => {
+    assertStrictEquals(HAS_INSTANCE, Symbol.hasInstance);
+  });
+});
+
+describe("IS_CONCAT_SPREADABLE", () => {
+  it("[[Get]] is @@isConcatSpreadable", () => {
+    assertStrictEquals(
+      IS_CONCAT_SPREADABLE,
+      Symbol.isConcatSpreadable,
+    );
+  });
+});
+
+describe("ITERATOR", () => {
+  it("[[Get]] is @@iterator", () => {
+    assertStrictEquals(ITERATOR, Symbol.iterator);
+  });
+});
+
+describe("MATCH", () => {
+  it("[[Get]] is @@match", () => {
+    assertStrictEquals(MATCH, Symbol.match);
+  });
+});
+
+describe("MATCH_ALL", () => {
+  it("[[Get]] is @@matchAll", () => {
+    assertStrictEquals(MATCH_ALL, Symbol.matchAll);
+  });
+});
+
 describe("NULL", () => {
   it("[[Get]] is null", () => {
     assertStrictEquals(NULL, null);
   });
 });
 
+describe("REPLACE", () => {
+  it("[[Get]] is @@replace", () => {
+    assertStrictEquals(REPLACE, Symbol.replace);
+  });
+});
+
+describe("SPECIES", () => {
+  it("[[Get]] is @@species", () => {
+    assertStrictEquals(SPECIES, Symbol.species);
+  });
+});
+
+describe("SPLIT", () => {
+  it("[[Get]] is @@split", () => {
+    assertStrictEquals(SPLIT, Symbol.split);
+  });
+});
+
+describe("TO_PRIMITIVE", () => {
+  it("[[Get]] is @@toPrimitive", () => {
+    assertStrictEquals(TO_PRIMITIVE, Symbol.toPrimitive);
+  });
+});
+
+describe("TO_STRING_TAG", () => {
+  it("[[Get]] is @@toStringTag", () => {
+    assertStrictEquals(TO_STRING_TAG, Symbol.toStringTag);
+  });
+});
+
 describe("UNDEFINED", () => {
   it("[[Get]] is undefined", () => {
     assertStrictEquals(UNDEFINED, void {});
   });
 });
 
+describe("UNSCOPABLES", () => {
+  it("[[Get]] is @@unscopables", () => {
+    assertStrictEquals(UNSCOPABLES, Symbol.unscopables);
+  });
+});
+
 describe("ordinaryToPrimitive", () => {
   it("[[Call]] prefers `valueOf` by default", () => {
     const obj = {
This page took 0.111117 seconds and 4 git commands to generate.