| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The output format is inspired by Chrome DevTools.
Probably only possible via the V8 API... would be worth looking at the dev tools code to see how it's done |
Sorry, something went wrong.
There was a problem hiding this comment.
Seems like this case needs tests
Sorry, something went wrong.
There was a problem hiding this comment.
style: semicolons here and below
Sorry, something went wrong.
There was a problem hiding this comment.
I have that in a new commit yet to be pushed. Is it normal that make jshint doesn't touch tests?
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, for some reason that choice was made a long time ago. Wouldn't call it "normal" though :)
Sorry, something went wrong.
|
@domenic I have added a test covering the case you commented on, thanks. There were no tests of alignment at all, so I took the luxury of adding tests for the rest of the containers as well. |
Sorry, something went wrong.
|
I just pushed a proof-of-concept implementation of util.inspect for Promises. It uses the mirror debugger to synchronously inspect Promises. (Alternatively, this could be done if I could have a module with compiler intrinsics enabled). There are bits I don't like about my implementation but I wanted to get this out there before I went to bed in case people think my course of action totally sucks and I should abandon ship 😛 Output looks like > Promise.resolve(3)
Promise { 3 }
> Promise.reject(3)
Promise { <rejected> 3 }
> new Promise(function(){})
Promise { <pending> }which is a change from Chrome DevTools, as they are ridiculously verbose: > Promise.resolve(3)
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: 3}
> Promise.reject(3)
Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: 3}
> new Promise(function(){})
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} |
Sorry, something went wrong.
|
Left some comments on the promise inspection code. I don't disagree with the Debug.MakeMirror approach (in fact I think it's the only way to crack open a promise) but I think the current implementation is creating mirrors too eagerly. |
Sorry, something went wrong.
|
@bnoordhuis Thank you for your comments.
I've hoisted it to the top of the file for simplicity; however if this is too expensive or otherwise unsatisfactory I can create it on demand and cache.
If we could have compiler intrinsics enabled for the lib/internals folder, the Promise internals are at the properties %CreateGlobalPrivateOwnSymbol("Promise#status") and ...("Promise#value"). I don't know if this is more or less desirable than using runInDebugContext. My guess is less, but perhaps this functionality would be useful for other things in the future..
you are correct, I should have noticed this. They are now created as "transient" so they will not be cached.
I've guarded the mirror creation with an instanceof, so the common case should not be penalized. The code still calls inspectPromise twice if it is indeed a native promise, but I can't eliminate this without a more involved refactor (or creating a closure, which seems just as bad as creating an extra mirror). I have tried to keep my changes as minimal as possible as this is my first io.js PR. |
Sorry, something went wrong.
we may mutate keys in the typecase, so don't check keys.length until no more mutations.
There was a problem hiding this comment.
@domenic: Should we add support for Weak{Set,Map} inspection through Debug as a follow-on to this PR?
Sorry, something went wrong.
There was a problem hiding this comment.
Noooo that seems very bad, basically exposes iteration to JS.
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah – I thought it might be a bit fraught with peril; was surprised to see the chrome dev tools expose that info.
Sorry, something went wrong.
|
The nits can probably be disregarded – just looked and saw that we were using map before, anyway :) This LGTM. Unless @bnoordhuis or @domenic objects, I'll merge this tomorrow afternoon. |
Sorry, something went wrong.
It's possible to do that but it's kind of a hack: const v8 = require('v8');
v8.setFlagsFromString('--allow_natives_syntax');
const promiseStatus = eval('%CreateGlobalPrivateOwnSymbol("Promise#status")');
const promiseValue = eval('%CreateGlobalPrivateOwnSymbol("Promise#value")');
v8.setFlagsFromString('--noallow_natives_syntax'); |
Sorry, something went wrong.
There was a problem hiding this comment.
Preferably assign empty = false and use strict checks below (i.e. empty = empty === true && keys.length === 0 and if (empty === true) {.)
It's a minor thing but V8 emits marginally tighter code for strict boolean comparisons.
Sorry, something went wrong.
|
@bnoordhuis @chrisdickinson OK, I addressed these style nits.
It saves an instanceof check. I'm hoping to do a larger scale cleanup of util.inspect when I next have free time, which should fix the double inspectPromise calls and make this issue moot.
Yes, another thing I would like to clean up. (Or at least move the subtraction logic to a central place) |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Among other things, this makes working with ES6 containers bearable on the REPL.
Before:
After:
The output format is inspired by Chrome DevTools.
I would like to support inspecting promises but I do not know of a way to synchronously obtain the status and fulfillment value. If someone would like to point me in the right direction I can provide a followup PR. (see below)