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,
},
};
const binaryCodeUnitIterablePrototype = {
- [iteratorSymbol]() {
+ [ITERATOR]() {
return {
next: bind(
arrayIteratorNext,
// ♓🌟 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
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,
// ♓🌟 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
stringStartsWith,
substring,
} from "./string.js";
+import { ITERATOR } from "./value.js";
const sub·delims = rawString`[!\$&'()*+,;=]`;
const gen·delims = rawString`[:/?#\[\]@]`;
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,
},
};
const iriGeneratorIterablePrototype = {
- [iteratorSymbol]() {
+ [ITERATOR]() {
return {
next: bind(generatorIteratorNext, this.generator(), []),
};
},
};
const iriSegmentIterablePrototype = {
- [iteratorSymbol]() {
+ [ITERATOR]() {
return {
next: bind(
arrayIteratorNext,
// ♓🌟 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
*/
frozenCopy,
} = (() => {
- const {
- iterator: iteratorSymbol,
- species: speciesSymbol,
- } = Symbol;
const {
next: generatorIteratorNext,
} = getPrototype(function* () {}.prototype);
const propertyDescriptorEntryIterablePrototype = {
- [iteratorSymbol]() {
+ [ITERATOR]() {
return {
next: bind(generatorIteratorNext, this.generator(), []),
};
//
// (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)
objectCreate,
setPrototype,
} from "./object.js";
-import { type } from "./value.js";
+import { ITERATOR, TO_STRING_TAG, type } from "./value.js";
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;
value: stringCodeValueIteratorNext,
writable: true,
},
- [toStringTagSymbol]: {
+ [TO_STRING_TAG]: {
configurable: true,
enumerable: false,
value: "String Code Value Iterator",
},
);
const scalarValueIterablePrototype = {
- [iteratorSymbol]() {
+ [ITERATOR]() {
return {
next: bind(
stringCodeValueIteratorNext,
* String::[Symbol.iterator].
*/
export const characters = makeCallable(
- String.prototype[Symbol.iterator],
+ String.prototype[ITERATOR],
);
/**
// ♓🌟 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;
*/
toPrimitive,
} = (() => {
- const { toPrimitive: toPrimitiveSymbol } = Symbol;
+ const { apply: call } = Reflect;
return {
ordinaryToPrimitive: (O, hint) => {
);
} 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.
// ♓🌟 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
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 = {