The defaults that reach the prototype
A nested defaults object changes properties on unrelated objects.
What’s going wrong
Input is {value, defaults}: two JSON objects with scalar leaves (null, strings, booleans or finite numbers), nested objects up to depth 6, and at most 100 keys total. value contains no __proto__, constructor or prototype keys. Apply defaults recursively: preserve every existing own scalar, recursively fill two existing object values, and deep-copy a missing object into value. Never follow inherited properties. Ignore keys named __proto__, constructor or prototype at every depth of defaults; retain all other own keys, including toString and hasOwnProperty. Output {value, prototypeKeys, constructorKeys}; the last two fields are sorted enumerable own keys of Object.prototype and Object and must remain empty. Arrays and undefined values are outside this contract. Each case runs in a fresh process.
Expected behavior
Preserve object ownership across recursive defaults.
Reproduction
{"value":{},"defaults":{"constructor":{"prototype":{"polluted":true}}}}{"value":{},"prototypeKeys":[],"constructorKeys":[]}{"value":{"options":{"retries":0}},"defaults":{"options":{"retries":3,"timeout":20}}}{"value":{"options":{"retries":0,"timeout":20}},"prototypeKeys":[],"constructorKeys":[]}{"value":{"a":false,"b":null,"c":""},"defaults":{"a":true,"b":7,"c":"new"}}{"value":{"a":false,"b":null,"c":""},"prototypeKeys":[],"constructorKeys":[]}Before you begin
- JavaScript own versus inherited properties
- Recursive object traversal
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.