Node: JavaScript debug statements

Created on 18 Feb 2018  路  7Comments  路  Source: nodejs/node

I personally would some times like to have some debug calls for internal APIs e.g. the internal errors. It would make the API easier to use by just verifying the input but only when run by our test suite. We are all human and make mistakes. So it should behave similar to a DCHECK in C++ but just in JS. Because I would not want to have those checks run in production.

Do we want to introduce something like that? (Or do we actually already have that and I just missed that?)

I guess there are two ways of implementing something like that:

a) A macro
b) A simple if (env.NODE_DEBUG_INTERNAL === 'true') {}

What do others @nodejs/collaborators think?

meta

Most helpful comment

I had discussed making debug macro comments with @trevnorris for async-hooks but the idea never got anywhere. I think this would be a good idea for core development/debugging.

All 7 comments

we can pretty easily adapt the DTRACE_* macro system, i'd be willing to make a pr

There was some work that went into a //CHECK(statement); comment that could be enabled.

Nice, do you know where I can find some further info about it?

I think our JS files are preprocessed by a python script before ending up in the binary. It might be somewhere inside it?

I think our JS files are preprocessed by a python script before ending up in the binary. It might be somewhere inside it?

The version of js2c.py in V8 indeed supports macro expansion (as defined either inline or in macros.py). It should be easy to select a macro file depending on build mode.

I had discussed making debug macro comments with @trevnorris for async-hooks but the idea never got anywhere. I think this would be a good idea for core development/debugging.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Icemic picture Icemic  路  3Comments

ksushilmaurya picture ksushilmaurya  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

addaleax picture addaleax  路  3Comments