]> Lady’s Gitweb - Pisces/blobdiff - symbol.js
Add methods for own entries and values to object.js
[Pisces] / symbol.js
index 343e4096e1c681fd52768795c9a25277467fbfc5..2bd37173fea849be70108d4e8991eb6d08ad918c 100644 (file)
--- a/symbol.js
+++ b/symbol.js
@@ -8,15 +8,44 @@
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
 import { createCallableFunction } from "./function.js";
-import { getOwnPropertyDescriptor } from "./object.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(
-  getOwnPropertyDescriptor(Symbol.prototype, "description").get,
-  "getSymbolDescription",
+  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 symbolValue = createCallableFunction(
+  Symbol.prototype.valueOf,
+  { name: "symbolValue" },
 );
This page took 0.038082 seconds and 4 git commands to generate.