- Version: All
- Platform: All
- Subsystem: process
I have been investigating some behaviors of node-chakracore, and I found some confusing code around the process object. In https://github.com/nodejs/node/blob/master/lib/internal/bootstrap_node.js#L17 the global process object instance has its __proto__ replaced with a fresh object that in turn has __proto__ of EventEmitter.prototype. That is, process.__proto__ !== process.__proto__.constructor.prototype and process.__proto__.__proto__ === EventEmitter.prototype.
What is the reason behind this, and why not simply set process.__proto__.constructor.prototype.__proto__ to be EventEmitter.prototype, preferably in the native code where process's constructor function is defined (although I haven't checked the order of instantiation of EventEmitter and process yet)?
The reason that I care about this is it is currently blocking an improvement in node-chakracore regarding how some objects toString() to something like [object process] rather than [object Object]. That improvement works for all cases except for the global process instance because it works by adding a Symbol.toStringTag to the object prototype, which is explicitly overridden for process.
I have been investigating some behaviors of node-chakracore, and I found some confusing code around the
processobject. In https://github.com/nodejs/node/blob/master/lib/internal/bootstrap_node.js#L17 the globalprocessobject instance has its__proto__replaced with a fresh object that in turn has__proto__ofEventEmitter.prototype. That is,process.__proto__ !== process.__proto__.constructor.prototypeandprocess.__proto__.__proto__ === EventEmitter.prototype.What is the reason behind this, and why not simply set
process.__proto__.constructor.prototype.__proto__to beEventEmitter.prototype, preferably in the native code whereprocess's constructor function is defined (although I haven't checked the order of instantiation ofEventEmitterandprocessyet)?The reason that I care about this is it is currently blocking an improvement in node-chakracore regarding how some objects
toString()to something like[object process]rather than[object Object]. That improvement works for all cases except for the globalprocessinstance because it works by adding aSymbol.toStringTagto the object prototype, which is explicitly overridden forprocess.