-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Altering Object.prototype.name
breaks in the REPL
#11614
Comments
Object.prototype
breaks in the REPLObject.prototype.name
breaks in the REPL
I personally wouldn’t have a problem with that, a prototypeless object is certainly not wrong for |
@addaleax cool. And you're definitely right, but I guess the REPL would be the best place to experiment with such ice skating 😄 |
Although not directly related to this bug, it might also make sense to use a prototypeless object for |
…ects Use a prototype-less object for inspect.styles and inspect.colors to allow modification of Object.prototype in the REPL. Fixes: nodejs#11614
Darwin 15.6.0 Darwin Kernel Version 15.6.0: Thu Sep 1 15:01:16 PDT 2016; root:xnu-3248.60.11~2/RELEASE_X86_64 x86_64
Problematic code:
Sample run:
Code breaks in stylizeWithColor the following line.
Why?
Because we are printing a property, the call to
stylizeWithColor
passes'name'
as thestyleType
where'name'
style type is actually ignored.These style types are stored in the plain object
inspect.styles
so the execution expectsinspect.styles['name']
on the first line ofstylizeWithColor
to returnundefined
(since it is ignored) and not enter theif
statement.However, since we added a
"name"
property onObject.prototype
,inspect.styles['name']
doesn't find'name'
directly but does find it up the [[Prototype]] chain and actually returns the string"bug"
.This means that the code tries to execute
inspect.colors["bug"][0]
, which givesundefined[0]
, and throws the error in the issue.A funny consequence is that, if we make
name
equal to a color value used ininspect.colors
, then the error wouldn't happen and the propertyname
will be printed in that color.Proposed solution
Use an object not linked to
Object.prototype
forinspect.style
.If confirmed, I'd be happy to implement it.
Inspired by this StackOverflow question
The text was updated successfully, but these errors were encountered: