This verbose output was to avoid outputting {__proto__: {x: 1}}, which would set the prototype of the object, not a property called '__proto__'. But wrapping __proto__ as ['__proto__'] achieves the same effect and is shorter.
It would also allow removing some code which handles this special case in the serializer.
NB: When setting a circular property, Object.defineProperties() is still needed - obj.__proto__ = obj or Object.assign(obj, {['__proto__']: obj}) both trigger the setter on Object.prototype.__proto__, which results in setting the prototype.
Input:
Current output:
This verbose output was to avoid outputting
{__proto__: {x: 1}}
, which would set the prototype of the object, not a property called'__proto__'
. But wrapping__proto__
as['__proto__']
achieves the same effect and is shorter.It would also allow removing some code which handles this special case in the serializer.
NB: When setting a circular property,
Object.defineProperties()
is still needed -obj.__proto__ = obj
orObject.assign(obj, {['__proto__']: obj})
both trigger the setter onObject.prototype.__proto__
, which results in setting the prototype.