Skip to content

Function has non-object prototype 'null' in instanceof check, when I use node but it is fine in Browser #35730

Description

@jackIsZlg

Looks like a Node.js bug. Logging an object should never crash. The same works in the browser:

function X () {}
X.prototype = null;
x = {};
x.constructor = X;
console.log(x);

Node.js:

Uncaught TypeError: Function has non-object prototype 'null' in instanceof check
    at Function.[Symbol.hasInstance] (<anonymous>)
    at getConstructorName (internal/util/inspect.js:535:13)
    at formatRaw (internal/util/inspect.js:803:23)
    at formatValue (internal/util/inspect.js:793:10)
    at inspect (internal/util/inspect.js:326:10)
    at formatWithOptionsInternal (internal/util/inspect.js:1994:40)
    at formatWithOptions (internal/util/inspect.js:1878:10)
    at Object.value (internal/console/constructor.js:306:14)
    at Object.log (internal/console/constructor.js:341:61)

Browser:

{constructor: ƒ}

node Verison: v14.14.0

Activity

targos commented on Oct 21, 2020

@targos
Member

@nodejs/util

added
utilIssues and PRs related to the built-in util module.
on Oct 21, 2020
self-assigned this
on Oct 21, 2020

samal-rasmussen commented on Nov 5, 2020

@samal-rasmussen

Are there any version of node that are not affected by this bug?

7kms commented on Nov 10, 2020

@7kms

v14.15.0 is also fail

kaizhu256 commented on Nov 10, 2020

@kaizhu256
Contributor

looks like v14-regression. v12 (both linux and win32-platform) works fine

#!/bin/sh
node -e '
console.log(process.platform, process.versions);
function X () {}
X.prototype = null;
x = {};
x.constructor = X;
console.log(x);
'

# stdout
# win32 {
#   node: '12.16.0',
#   v8: '7.8.279.23-node.31',
#   uv: '1.34.0',
#   zlib: '1.2.11',
#   brotli: '1.0.7',
#   ares: '1.15.0',
#   modules: '72',
#   nghttp2: '1.40.0',
#   napi: '5',
#   llhttp: '2.0.4',
#   http_parser: '2.9.3',
#   openssl: '1.1.1d',
#   cldr: '35.1',
#   icu: '64.2',
#   tz: '2019c',
#   unicode: '12.1'
# }
# X { constructor: [Function: X] }

Trystan-SA commented on Nov 19, 2020

@Trystan-SA

(On Windows 10 - MSI x64 installer)
Node 14.0.0 Work
Node 14.2.0 Work
Node 14.3.0 Work
Node 14.4.0 Work
Node 14.5.0 Fail
Node 14.15.1 Fail
Node 15.2.1 Fail

So something between 14.4.0 and 14.5.0 probably created this bug.

ExE-Boss commented on Nov 19, 2020

@ExE-Boss
Contributor

@Trystan-SA
The PR that caused the regression is #33449.

jasonwilliams commented on Dec 10, 2020

@jasonwilliams

This fails for me on v15.0.1

I get

TypeError: Function has non-object prototype 'null' in instanceof check
    at Function.[Symbol.hasInstance] (<anonymous>)
    at getConstructorName (node:internal/util/inspect:545:13)
    at formatRaw (node:internal/util/inspect:813:23)
    at formatValue (node:internal/util/inspect:803:10)
    at formatProperty (node:internal/util/inspect:1689:11)
    at formatRaw (node:internal/util/inspect:1017:9)
    at formatValue (node:internal/util/inspect:803:10)
    at formatProperty (node:internal/util/inspect:1689:11)
    at formatRaw (node:internal/util/inspect:1017:9)
    at formatValue (node:internal/util/inspect:803:10)
    at formatProperty (node:internal/util/inspect:1689:11)
    at formatArray (node:internal/util/inspect:1519:17)
    at formatRaw (node:internal/util/inspect:1014:14)
    at formatValue (node:internal/util/inspect:803:10)
    at formatProperty (node:internal/util/inspect:1689:11)
    at formatRaw (node:internal/util/inspect:1017:9)
    at formatValue (node:internal/util/inspect:803:10)
    at formatProperty (node:internal/util/inspect:1689:11)
    at formatRaw (node:internal/util/inspect:1017:9)
    at formatValue (node:internal/util/inspect:803:10)
    at Object.inspect (node:internal/util/inspect:336:10)

from hitting https://github.com/karma-runner/karma/blob/master/lib/server.js#L66

11 remaining items

marxangels commented on Jun 3, 2021

@marxangels

v14.17.0 OK

npenin commented on Jun 25, 2022

@npenin

I found another way to reproduce this one (on node v16.15.1):

var x={}
console.log(x instanceof Proxy)

Can we reopen the bug ?

deleted a comment from jackIsZlg on Jun 25, 2022

bnoordhuis commented on Jun 25, 2022

@bnoordhuis
Member

@npenin can you open a new issue? It's probably not the same bug.

(for the audit log: removed an OoO auto-reply while I was here)

scorpion-orion commented on Mar 14, 2025

@scorpion-orion

This bug is still in NodeJS v23... just using instanceof Proxy will throw the TypeError.

jackIsZlg commented on Mar 14, 2025

@jackIsZlg
Author

BridgeAR commented on Mar 14, 2025

@BridgeAR
Member

Can you please open a new issue with a description how to reproduce this?

ljharb commented on Mar 14, 2025

@ljharb
SponsorMember
function X () {}
X.prototype = null;
x = {};
x.constructor = X;
console.log(x);
x instanceof Proxy

throws for me, per spec, in Safari 18.1 and node v23 and node v14.21.3. I think this is either a misunderstanding or a bug that's been fixed already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues and PRs for confirmed bugs.utilIssues and PRs related to the built-in util module.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions