How to determine the starting position of a script from within an automation call?

I have a host script that runs JScript. There are some cases where I have to keep track of whether the method of my exposed objects is called and where it is called from. To do this, I need to determine where the script mechanism is located, which is in my object method.

This should be the same information as when calling my OnScriptError site: source source source char and the cookie that I passed to ParseScriptText.

Is it possible to get this information without an error?

+4
source share
1 answer

Have you tried something like the code below? This should give you a complete stack trace with function names and argument values, but without line numbers.

I do not know what ParseScriptText is.

(from https://github.com/emwendelin/Javascript-Stacktrace and http://eriwen.com/javascript/stacktrace-update/ )

other: function(curr) { var ANON = '{anonymous}', fnRE = /function\s*([\w\-$]+)?\s*\(/i, stack = [], fn, args, maxStackSize = 10; while (curr && stack.length < maxStackSize) { fn = fnRE.test(curr.toString()) ? RegExp.$1 || ANON : ANON; args = Array.prototype.slice.call(curr['arguments']); stack[stack.length] = fn + '(' + this.stringifyArguments(args) + ')'; curr = curr.caller; } return stack; }, 
0
source

Source: https://habr.com/ru/post/1332195/


All Articles