__line_number__ and __filename__

Aaron Gray aaronngray.lists at gmail.com
Fri Aug 24 13:46:47 UTC 2018


On Fri, 24 Aug 2018 at 04:56, J Decker <d3ck0r at gmail.com> wrote:

> On Thu, Aug 23, 2018 at 5:26 PM Aaron Gray <aaronngray.lists at gmail.com>
> wrote:
>
>> I am debugging existing code that I have modularized, and am class'izing
>> that has unittests and it just would have been very useful to have this
>> facility.
>>
> In a  browser, console.log is usually associated with the file and line
> number anyway; which includes using devtools with node.... but it would be
> handy for logging.  with V8 there is console.trace; which spits out the
> stack trace too... before I discovered that I did a logging function
> like...
>
> (from
> https://stackoverflow.com/questions/591857/how-can-i-get-a-javascript-stack-trace-when-i-throw-an-exception
> )
> function stackTrace() { var err = new Error(); return err.stack; }  //
> parse stack to get frame-1 online
>
> // or maybe just frame-1...
> function stackTrace() { var err = new Error(); return err.stack.split(
> "\n" )[1]; }
>
> ---
> function stacktrace() {
>   function st2(f) {
>     return !f ? [] :
>         st2(f.caller).concat([f.toString().split('(')[0].substring(9) +
> '(' + f.arguments.join(',') + ')']);
>   }
>   return st2(arguments.callee.caller);
> }
>
>  EDIT 2 (2017) :
>
> In all modern browsers you can simply call: console.trace(); (MDN
> Reference)
>

Yes slightly long winded to say the least :)


> ---
>
> Although I do still miss just being able to get __FILE__ and __LINE__
>

Yeah it should be easy to have such stuff compiled by JIT

Aaron

> -Gus
>>>
>>> ---- On Thu, 23 Aug 2018 17:56:43 -0500 *Aaron Gray
>>> <aaronngray.lists at gmail.com <aaronngray.lists at gmail.com>>* wrote ----
>>>
>>> I wondering what people think about the idea of proposing being able to
>>> get the line number and filename of executing code in the code ? Maybe with
>>> something simular to C preprocessors __line_number__ and __filename__. Or
>>> as subobjects of global ?
>>>
>>> --
>>> Aaron Gray
>>>
>>> Independent Open Source Software Engineer, Computer Language Researcher,
>>> Information Theorist, and amateur computer scientist.
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>>
>>>
>>
>> --
>> Aaron Gray
>>
>> Independent Open Source Software Engineer, Computer Language Researcher,
>> Information Theorist, and amateur computer scientist.
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>

-- 
Aaron Gray

Independent Open Source Software Engineer, Computer Language Researcher,
Information Theorist, and amateur computer scientist.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180824/1c2b5fb7/attachment.html>


More information about the es-discuss mailing list