mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
fix(ext/kv): stricter structured clone serializer (#18914)
This commit is contained in:
parent
10ae5ee265
commit
1066490847
3 changed files with 52 additions and 3 deletions
|
@ -123,6 +123,36 @@ dbTest("set and get recursive object", async (db) => {
|
|||
assert(resultValue.a === resultValue);
|
||||
});
|
||||
|
||||
// invalid values (as per structured clone algorithm with _for storage_, NOT JSON)
|
||||
const INVALID_VALUE_CASES = [
|
||||
{ name: "function", value: () => {} },
|
||||
{ name: "symbol", value: Symbol() },
|
||||
{ name: "WeakMap", value: new WeakMap() },
|
||||
{ name: "WeakSet", value: new WeakSet() },
|
||||
{
|
||||
name: "WebAssembly.Module",
|
||||
value: new WebAssembly.Module(
|
||||
new Uint8Array([0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00]),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "SharedArrayBuffer",
|
||||
value: new SharedArrayBuffer(3),
|
||||
},
|
||||
];
|
||||
|
||||
for (const { name, value } of INVALID_VALUE_CASES) {
|
||||
dbTest(`set and get ${name} value (invalid)`, async (db) => {
|
||||
await assertRejects(
|
||||
async () => await db.set(["a"], value),
|
||||
Error,
|
||||
);
|
||||
const res = await db.get(["a"]);
|
||||
assertEquals(res.key, ["a"]);
|
||||
assertEquals(res.value, null);
|
||||
});
|
||||
}
|
||||
|
||||
const keys = [
|
||||
["a"],
|
||||
["a", "b"],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue