wasmerio / winterjs

Winter is coming... ❄️
https://winterjs.org/
MIT License
3.02k stars 55 forks source link

JSON.stringify skips keys when JSON conversion is not supported #39

Closed theduke closed 8 months ago

theduke commented 8 months ago

When using JSON.stringify() on objects with keys that apparently don't support JSON serialization, the whole key is skipped.

I would expect to at least still see a null key.

Or get an exception thrown.

Expected:

{
  success: true,
   headers: ???,
   tail: 'tail'
}

Actual:

{
  success: true,
   tail: 'tail'
}

async function handleRequest(request) {
  console.debug(request);

  const out = JSON.stringify({
    success: true,
    headers: request.headers,
    tail: 'tail',
  });
  return new Response(out, {
    headers: { "content-type": "application/json" },
  });
}

addEventListener("fetch", (req) => {
  req.respondWith(handleRequest(req));
});
theduke commented 8 months ago

Update: I believe this is happening because the value is undefined, and therefore skipped, so this may be expected?

theduke commented 8 months ago

The value was undefined, so this is expected...