Chrome Javascript Error Line Number
Contents |
here for a quick overview of the site Help Center Detailed answers to
Javascript Eval Syntax Error Line Number
any questions you might have Meta Discuss the workings and policies javascript error chrome //browser/content/urlbarbindings.xml line 674 aurl is undefined of this site About Us Learn more about Stack Overflow the company Business Learn more
Chrome Javascript Error Stack Trace
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack chrome javascript error console Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Accessing line number in V8 JavaScript (Chrome & Node.js) up vote 39 down vote favorite 23 JavaScript developers who have spent time in languages like C often miss google chrome javascript error the ability to use certain types of introspection, like logging line numbers, and what method the current method was invoked from. Well if you're using V8 (Chrome, Node.js) you can employ the following. javascript node.js google-chrome v8 share|improve this question asked Jul 8 '12 at 20:35 james_womack 6,15733759 add a comment| 2 Answers 2 active oldest votes up vote 64 down vote accepted Object.defineProperty(global, '__stack', { get: function(){ var orig = Error.prepareStackTrace; Error.prepareStackTrace = function(_, stack){ return stack; }; var err = new Error; Error.captureStackTrace(err, arguments.callee); var stack = err.stack; Error.prepareStackTrace = orig; return stack; } }); Object.defineProperty(global, '__line', { get: function(){ return __stack[1].getLineNumber(); } }); console.log(__line); The above will log 19. Combined with arguments.callee.caller you can get closer to the type of useful logging you get in C via macros. share|improve this answer answered Jul 8 '12 at 20:35 james_womack 6,15733759 2 code.google.com/p/v8/wiki/… has a list of other methods available in
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Chrome Break On Javascript Error
Overflow the company Business Learn more about hiring developers or posting ads with us javascript catch error line number Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Javascript Try Catch Error Line Number
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to get JavaScript caller function line number? How to get JavaScript caller source URL? up http://stackoverflow.com/questions/11386492/accessing-line-number-in-v8-javascript-chrome-node-js vote 75 down vote favorite 31 I am using the following for getting the JavaScript caller function name: var callerFunc = arguments.callee.caller.toString(); callerFuncName = (callerFunc.substring(callerFunc.indexOf("function") + 8, callerFunc.indexOf("(")) || "anoynmous") Is there a way to discover the line number from which the method was called? Also, is there a way to get the name of the JavaScript file the method was called from? Or the source URL? javascript share|improve this question http://stackoverflow.com/questions/1340872/how-to-get-javascript-caller-function-line-number-how-to-get-javascript-caller edited Mar 3 '14 at 21:07 Kara 3,12873147 asked Aug 27 '09 at 12:49 Tal 56331018 2 I don't think this is possible in IE, or else we would have a way to get around there CRAPPY error messages that deliver no detail. But if it is possible I would LOVE to know as well! –Zoidberg Aug 27 '09 at 13:00 add a comment| 13 Answers 13 active oldest votes up vote 21 down vote accepted kangax's solution introduces unnecessary try..catch scope. If you need to access the line number of something in JavaScript (as long as you are using Firefox or Opera), just access (new Error).lineNumber. share|improve this answer answered Aug 28 '09 at 17:16 Eli Grey 22.6k105283 7 Hi, Thanks for that addon. do you know if its possible to get line number from previous call ? Lets say method A calls B , and now in B I would like to know in what line under A the call was made? –Tal Aug 30 '09 at 11:12 64 This is ticked, but doesn't answer the question, which is how to get the line number of the caller function. –mikemaccana Apr 17 '12 at 8:45 2 Also, this is extremely limited. The best solution
Errors thrown in an eval. Starred by 9 users Reported by cho...@ualberta.net, Jan 23 2012 Back to list Status: Fixed Owner: yangguo@chromium.org https://bugs.chromium.org/p/v8/issues/detail?id=1914 Closed: Jun 2012 HW: ---- OS: ---- Priority: ---- Type: FeatureRequest Sign in to add a comment Can we augment the Error object to include the fileName and lineNumber? I realize this is non-standard behavior per the EMCAScript 5 specification, but it is supported in some browsers (e.g. Firefox). This is helpful in running eval'd code, javascript error for example. A SyntaxError could locate what line number actually caused the SyntaxError. In embedded V8, it is possible in C++-land to get the fileName and lineNumber. Much better from the user's perspective would be if they are available with the Error object in JavaScript-land. Comment 1 by compwiz...@gmail.com, May 6 2012 Processing It would be nice to chrome javascript error get line number (and possibly offset or column number) of a SyntaxError that is thrown in eval'd code. Right now there is no way to get the line numbers from the v8::Script object after a SyntaxError. Node.JS bug upstream: https://github.com/joyent/node/issues/2734 Project Member Comment 2 by yangguo@chromium.org, May 8 2012 Processing Labels: Type-FeatureRequest Owner: yangguo@chromium.org Status: Accepted Summary: Capture correct line numbers for Errors thrown in an eval. (was: NULL) The problem described in the first post is already solved. Every Error object created in V8 has a .stack property that contains the string representation of the stack trace captured at creation point. It's easy to parse the file name and line numbers from that string. An alternative is described in http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi. The actual problem here is that the line numbers in eval'ed code is not being captured. This would be a feature request. Comment 3 by compwiz...@gmail.com, May 8 2012 Processing @yangguo - Yes, my apologies; you are correct. I would like to request that line numbers from eval'ed strings are