Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Commits on Oct 25, 2018

  1. 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: whatwg/console#3
    joyeecheung committed Oct 25, 2018
    Configuration menu
    Copy the full SHA
    5556e47 View commit details
    Browse the repository at this point in the history