diff options
author | Adam Conrad <422184+acconrad@users.noreply.github.com> | 2019-01-05 15:02:44 +0000 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-01-05 10:02:44 -0500 |
commit | f44322128b1ebb3d3d0db5ab9527ee4cdfbc7942 (patch) | |
tree | 4ec076859376986f7b3c9b66406431c068257e43 /js/util.ts | |
parent | ad01085406bbcb0d0d66eb3e05d4781a3aebee21 (diff) |
Add Event web API (#1059)
Diffstat (limited to 'js/util.ts')
-rw-r--r-- | js/util.ts | 12 |
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"); +} |