summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
inline | side by side (from parent 1:
8fcb8f6)
Also properly casts some arguments of string functions to strings.
* An iterator object for iterating over code values (either code
* units or codepoints) in a string.
*
* An iterator object for iterating over code values (either code
* units or codepoints) in a string.
*
- * ※ This constructor is not exposed.
+ * ※ This class is not exposed, although its methods are (through
+ * the prototypes of string code value iterator objects).
*/
const StringCodeValueIterator = class extends identity {
#allowSurrogates;
*/
const StringCodeValueIterator = class extends identity {
#allowSurrogates;
return {
codeUnits: ($) =>
return {
codeUnits: ($) =>
- new StringCodeValueIterator(call(arrayIterator, $, [])),
+ new StringCodeValueIterator(call(arrayIterator, `${$}`, [])),
codepoints: ($) =>
new StringCodeValueIterator(
codepoints: ($) =>
new StringCodeValueIterator(
- call(stringIterator, $, []),
+ call(stringIterator, `${$}`, []),
true,
),
scalarValues: ($) =>
new StringCodeValueIterator(
true,
),
scalarValues: ($) =>
new StringCodeValueIterator(
- call(stringIterator, $, []),
+ call(stringIterator, `${$}`, []),
false,
),
scalarValueString: ($) =>
stringFromCodepoints(...objectCreate(
scalarValueIterablePrototype,
false,
),
scalarValueString: ($) =>
stringFromCodepoints(...objectCreate(
scalarValueIterablePrototype,
- { source: { value: $ } },
+ { source: { value: `${$}` } },
* value according to the algorithm of String::substring.
*/
export const substring = makeCallable(String.prototype.substring);
* value according to the algorithm of String::substring.
*/
export const substring = makeCallable(String.prototype.substring);
+
+/**
+ * Returns the result of converting the provided value to a string.
+ *
+ * ☡ This method throws for symbols and other objects without a string
+ * representation.
+ */
+export const toString = ($) => `${$}`;
splitOnCommas,
stripAndCollapseASCIIWhitespace,
stripLeadingAndTrailingASCIIWhitespace,
splitOnCommas,
stripAndCollapseASCIIWhitespace,
stripLeadingAndTrailingASCIIWhitespace,
} from "./string.js";
describe("Matcher", () => {
} from "./string.js";
describe("Matcher", () => {
+
+describe("toString", () => {
+ it("[[Call]] converts to a string", () => {
+ assertStrictEquals(
+ toString({
+ toString() {
+ return "success";
+ },
+ }),
+ "success",
+ );
+ });
+
+ it("[[Call]] throws when provided a symbol", () => {
+ assertThrows(() => toString(Symbol()));
+ });
+});