From f44322128b1ebb3d3d0db5ab9527ee4cdfbc7942 Mon Sep 17 00:00:00 2001 From: Adam Conrad <422184+acconrad@users.noreply.github.com> Date: Sat, 5 Jan 2019 15:02:44 +0000 Subject: Add Event web API (#1059) --- js/util.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'js/util.ts') 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, key: W): V[W] { + if (weakMap.has(instance)) { + return weakMap.get(instance)![key]; + } + throw new TypeError("Illegal invocation"); +} -- cgit v1.2.3