Skip to content

Why does the global process object have its prototype replaced? #14699

@MSLaguana

Description

@MSLaguana
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    processIssues and PRs related to the process subsystem.questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions