[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 01/02: idb: suggest encoding improvements
From: |
gnunet |
Subject: |
[taler-wallet-core] 01/02: idb: suggest encoding improvements |
Date: |
Wed, 28 Jun 2023 17:22:36 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
commit 3f4526847b76ddafa9a3e23d94e973c30d8c72ef
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Jun 28 17:13:08 2023 +0200
idb: suggest encoding improvements
---
packages/idb-bridge/src/util/structuredClone.ts | 38 ++++++++++++++++++++-----
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/packages/idb-bridge/src/util/structuredClone.ts
b/packages/idb-bridge/src/util/structuredClone.ts
index 5ed269db3..a3842b8c4 100644
--- a/packages/idb-bridge/src/util/structuredClone.ts
+++ b/packages/idb-bridge/src/util/structuredClone.ts
@@ -14,6 +14,29 @@
permissions and limitations under the License.
*/
+/**
+ * Encoding (new, compositional version):
+ *
+ * Encapsulate object that itself might contain a "$" field:
+ * { $: { E... } }
+ * Circular reference:
+ * { $: ["ref", uplevel, field...] }
+ * Date:
+ * { $: ["data"], val: datestr }
+ * Bigint:
+ * { $: ["bigint"], val: bigintstr }
+ * Array with special (non-number) attributes:
+ * { $: ["array"], val: arrayobj }
+ * Undefined field
+ * { $: "undef" }
+ *
+ * Legacy (top-level only), for backwards compatibility:
+ * { $types: [...] }
+ */
+
+/**
+ * Imports.
+ */
import { DataCloneError } from "./errors.js";
const { toString: toStr } = {};
@@ -73,10 +96,6 @@ function isUserObject(val: any): boolean {
return hasConstructorOf(val, Object) || isUserObject(proto);
}
-function isRegExp(val: any): boolean {
- return toStringTag(val) === "RegExp";
-}
-
function copyBuffer(cur: any) {
if (cur instanceof Buffer) {
return Buffer.from(cur);
@@ -334,8 +353,7 @@ export function structuredEncapsulate(val: any): any {
return res;
}
-export function internalStructuredRevive(val: any): any {
- val = JSON.parse(JSON.stringify(val));
+export function applyLegacyTypeAnnotations(val: any): any {
if (val === null) {
return null;
}
@@ -417,8 +435,14 @@ export function internalStructuredRevive(val: any): any {
return outRoot;
}
+export function internalStructuredRevive(val: any): any {
+ // FIXME: Do the newly specified, compositional encoding here.
+ val = JSON.parse(JSON.stringify(val));
+}
+
export function structuredRevive(val: any): any {
- return internalStructuredRevive(val);
+ const r = internalStructuredRevive(val);
+ return applyLegacyTypeAnnotations(r);
}
/**
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.