diff options
author | Florian Dold <florian@dold.me> | 2021-02-08 19:59:19 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-02-08 19:59:19 +0100 |
commit | 8c92499d85917693d2f87252419f0eeccd239a2b (patch) | |
tree | 569d0ee1c25d62caf0ac87131ecfa8166d12c62b /packages/idb-bridge/src/util/structuredClone.ts | |
parent | 5ff5a686e4f15dea839b18fda9275687557d23a7 (diff) | |
download | wallet-core-8c92499d85917693d2f87252419f0eeccd239a2b.tar.xz |
idb: add first web platform tests, fix issues detected by them
Diffstat (limited to 'packages/idb-bridge/src/util/structuredClone.ts')
-rw-r--r-- | packages/idb-bridge/src/util/structuredClone.ts | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/packages/idb-bridge/src/util/structuredClone.ts b/packages/idb-bridge/src/util/structuredClone.ts index c49d0377f..9bbeb7151 100644 --- a/packages/idb-bridge/src/util/structuredClone.ts +++ b/packages/idb-bridge/src/util/structuredClone.ts @@ -14,17 +14,24 @@ permissions and limitations under the License. */ -function structuredCloneImpl(val: any, visited: WeakMap<any, boolean>): any { - // FIXME: replace with real implementation! - return JSON.parse(JSON.stringify(val)); +// @ts-ignore +import Typeson from "typeson"; +// @ts-ignore +import structuredCloningThrowing from "typeson-registry/dist/presets/structured-cloning-throwing"; + +const TSON = new Typeson().register(structuredCloningThrowing); + +export function structuredEncapsulate(val: any): any { + return TSON.encapsulate(val); +} + +export function structuredRevive(val: any): any { + return TSON.revive(val); } /** * Structured clone for IndexedDB. */ export function structuredClone(val: any): any { - const visited: WeakMap<any, boolean> = new WeakMap<any, boolean>(); - return structuredCloneImpl(val, visited); + return structuredRevive(structuredEncapsulate(val)); } - -export default structuredClone; |