awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.74k stars 342 forks source link

Invalid serialization of undefined values in the middle of an object #314

Closed andyneville closed 3 months ago

andyneville commented 3 months ago

Using version 0.1.12-beta, as well as building the latest code locally from the master branch, serializing an object containing an undefined property sandwiched between other properties results in invalid JSON:

const value = {
  a: '123',
  b: undefined,
  c: '123'
};

console.log(JSON.stringify(value));

Expected output: {"a":"123","c":"123"} Actual output (LLRT): {"a":"123""c":"123"} which is invalid JSON because of the double double-quotes without a separating comma.

Moving the undefined property to the first or last position serializes properly:

./llrt -e "console.log(JSON.stringify({a: '123', b: undefined, c: '123'}));"
{"a":"123""c":"123"}    <- INVALID

./llrt -e "console.log(JSON.stringify({a: '123', c: '123', b: undefined}));"
{"a":"123","c":"123"}    <- valid

./llrt -e "console.log(JSON.stringify({b: undefined, a: '123', c: '123'}));"
{"a":"123","c":"123"}    <- valid