-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
cmd/geth, jsre: restore command line editing on windows #1642
Conversation
One problem I saw while working on this is that attached consoles get disconnected after 60s |
} | ||
} | ||
|
||
func (ctx ppctx) printObject(obj *otto.Object, indent string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you're using this type of "type casting" over obj.Value()
and use value.Export
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export converts both undefined
and null
to Go nil
. It also has other issues, e.g.
new String('foo')
exports as map[string]interface{}{"0": "f", "1": "o", "2": "o"}
.
Export is recursive and crashes for circular structures. The new printer does, too, but
we can fix it whereas Export
is part of otto.
👍 |
I'll add circular structure handling so the following doesn't crash the printer: > a = {'b': 1}
> a.a = a
> a |
e5f20cd
to
c5c0365
Compare
@bas-vk PTAL. I've added a depth limit so the above case prints as > a = {b:1}
{
b: 1
}
> a.a = a
{
a: {
a: {
a: {
a: {...},
b: 1
},
b: 1
},
b: 1
},
b: 1
} |
ca856e7
to
1b24061
Compare
PR #856 broke command line editing by wrapping stdout with a filter that interprets ANSI escape sequences to fix colored printing on windows. Implement the printer in Go instead so it can do its own platform-dependent coloring. As a nice side effect, the JS console is now noticeably more responsive when printing results. Fixes #1608 Fixes #1612
1b24061
to
0ef80bb
Compare
func (ctx ppctx) doOwnProperties(v otto.Value, f func(string)) { | ||
Object, _ := ctx.vm.Object("Object") | ||
rv, _ := Object.Call("getOwnPropertyNames", v) | ||
gv, _ := rv.Export() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does rv and gv mean? Is the second returned value here errors? If so why are they not checked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rv
is short for return value, gv
for go value. None of the errors are checked because
Object.getOwnPropertyNames
exists as a method and should not error for JS objects.
Try breaking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The easiest way to break this is to evaluate Object.getOwnPropertyNames = null
at the console.
Printing any object after that crashes the console. I don't think it is worth fixing though. The best
thing we could do in such a situation would be to print "can't print because you broke Object".
Maybe we should print such a message and inform the user that its probably best to restart geth or the console in case of an attach. Now it crashes which might cause issues. The depth limit change is ok. |
👍 |
cmd/geth, jsre: restore command line editing on windows
PR #856 broke command line editing by wrapping stdout with a filter that
interprets ANSI escape sequences to fix colored printing on windows.
Implement the printer in Go instead so it can do its own
platform-dependent coloring.
As a nice side effect, the JS console is now noticeably more responsive
when printing results.
Fixes #1608
Fixes #1612