summaryrefslogtreecommitdiff
path: root/js/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/util.ts')
-rw-r--r--js/util.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/js/util.ts b/js/util.ts
index 58e865337..ec24ec5bd 100644
--- a/js/util.ts
+++ b/js/util.ts
@@ -151,3 +151,15 @@ export function requiredArguments(
throw new TypeError(errMsg);
}
}
+
+// Returns values from a WeakMap to emulate private properties in JavaScript
+export function getPrivateValue<
+ K extends object,
+ V extends object,
+ W extends keyof V
+>(instance: K, weakMap: WeakMap<K, V>, key: W): V[W] {
+ if (weakMap.has(instance)) {
+ return weakMap.get(instance)![key];
+ }
+ throw new TypeError("Illegal invocation");
+}