X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/ee0f6916f2f56f17bd232f964fec9a4c7ed6ec89..refs/heads/current:/symbol.js?ds=inline diff --git a/symbol.js b/symbol.js index 514b526..2bd3717 100644 --- a/symbol.js +++ b/symbol.js @@ -7,16 +7,45 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at . -import { makeCallable } from "./function.js"; -import { getOwnPropertyDescriptor } from "./object.js"; +import { createCallableFunction } from "./function.js"; /** * Returns the description for the provided symbol. * * ※ This is effectively an alias for the `Symbol::description` * getter. + * + * ☡ This function throws if the provided argument is not a symbol. + */ +export const getSymbolDescription = createCallableFunction( + Object.getOwnPropertyDescriptor(Symbol.prototype, "description").get, + { name: "getSymbolDescription" }, +); + +/** + * Returns a string representation of the provided symbol. + * + * ※ Use `getSymbolDescription` instead if you just want the text + * description of a symbol. + * + * ※ This is effectively an alias for the `Symbol::toString`. + * + * ☡ This function throws if the provided argument is not a symbol. + */ +export const symbolToString = createCallableFunction( + Symbol.prototype.toString, + { name: "symbolToString" }, +); + +/** + * Returns the value of the provided symbol. + * + * ※ This is effectively an alias for the `Symbol::valueOf`. + * + * ☡ This function throws if the provided argument is not a symbol and + * does not have a `[[SymbolData]]` slot. */ -export const getSymbolDescription = makeCallable( - getOwnPropertyDescriptor(Symbol.prototype, "description").get, - "getSymbolDescription", +export const symbolValue = createCallableFunction( + Symbol.prototype.valueOf, + { name: "symbolValue" }, );