Repository navigation
Function has non-object prototype 'null' in instanceof check, when I use node but it is fine in Browser #35730
Description
Activity
@nodejs/util
Are there any version of node that are not affected by this bug?
v14.15.0 is also fail
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] }(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.
@Trystan-SA
The PR that caused the regression is #33449.
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
v14.17.0 OK
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 ?
@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)
This bug is still in NodeJS v23... just using instanceof Proxy will throw the TypeError.
Can you please open a new issue with a description how to reproduce this?
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.
Looks like a Node.js bug. Logging an object should never crash. The same works in the browser:
Node.js:
Browser:
node Verison: v14.14.0