diff options
author | Florian Dold <florian@dold.me> | 2021-02-25 16:34:55 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-02-25 16:35:04 +0100 |
commit | 48acd573b1a470e54831e4388ea0e4fde410de30 (patch) | |
tree | 6cb7ff42c64ca45645ac9f812860f5c078ac70f2 /packages/idb-bridge/src/util | |
parent | 0e288650180380d0d1974eb2e0dfdcf57300f725 (diff) | |
download | wallet-core-48acd573b1a470e54831e4388ea0e4fde410de30.tar.xz |
idb: make test cases pass
Diffstat (limited to 'packages/idb-bridge/src/util')
-rw-r--r-- | packages/idb-bridge/src/util/makeStoreKeyValue.ts | 10 | ||||
-rw-r--r-- | packages/idb-bridge/src/util/structuredClone.test.ts | 12 |
2 files changed, 19 insertions, 3 deletions
diff --git a/packages/idb-bridge/src/util/makeStoreKeyValue.ts b/packages/idb-bridge/src/util/makeStoreKeyValue.ts index 243e46e04..c0fdb19a7 100644 --- a/packages/idb-bridge/src/util/makeStoreKeyValue.ts +++ b/packages/idb-bridge/src/util/makeStoreKeyValue.ts @@ -15,7 +15,7 @@ */ import { extractKey } from "./extractKey"; -import { DataError } from "./errors"; +import { DataCloneError, DataError } from "./errors"; import { valueToKey } from "./valueToKey"; import { structuredClone } from "./structuredClone"; import { IDBKeyPath, IDBValidKey } from "../idbtypes"; @@ -26,7 +26,7 @@ export interface StoreKeyResult { value: any; } -export function injectKey( +function injectKey( keyPath: IDBKeyPath | IDBKeyPath[], value: any, key: IDBValidKey, @@ -87,7 +87,11 @@ export function makeStoreKeyValue( // This models a decision table on (haveKey, haveKeyPath, autoIncrement) - value = structuredClone(value); + try { + value = structuredClone(value); + } catch (e) { + throw new DataCloneError(); + } if (haveKey) { if (haveKeyPath) { diff --git a/packages/idb-bridge/src/util/structuredClone.test.ts b/packages/idb-bridge/src/util/structuredClone.test.ts index 58a7f32c1..ed404c6be 100644 --- a/packages/idb-bridge/src/util/structuredClone.test.ts +++ b/packages/idb-bridge/src/util/structuredClone.test.ts @@ -29,6 +29,18 @@ test("structured clone", (t) => { checkClone(t, [new Date()]); checkClone(t, undefined); checkClone(t, [undefined]); + + t.throws(() => { + structuredClone({ foo: () => {} }); + }); + + t.throws(() => { + structuredClone(Promise); + }); + + t.throws(() => { + structuredClone(Promise.resolve()); + }); }); test("structured clone (cycles)", (t) => { |