Skip to content

lib: make the global console [[Prototype]] an empty object

lib: make the global console Prototype an empty object

From the WHATWG console spec:

For historical web-compatibility reasons, the namespace object for console must have as its Prototype an empty object, created as if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.

Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use new Console to construct the global console.

This patch changes the prototype chain of the global console object, so the console.Console.prototype is not in the global console prototype chain anymore.

const proto = Object.getPrototypeOf(global.console);
// Before this patch
proto.constructor === global.console.Console
// After this patch
proto.constructor === Object

But, we still maintain that

global.console instanceof global.console.Console

through a custom Symbol.hasInstance function of Console that tests for a special symbol kIsConsole for backwards compatibility.

This fixes a case in the console Web Platform Test that we commented out.

Refs: https://console.spec.whatwg.org/#console-namespace Refs: https://github.com/whatwg/console/issues/3

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading