Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After wondering about this for a long time, I finally sat down and worked it out. It's all part of a relatively sophisticated mechanism for collecting diagnostic information on the client which includes the ability to send a javascript callstack (including function name, and javascript file) back to the server.</p> <p>Take a look at the <strong>first 250 lines of the file init.debug.js</strong> which is located at</p> <p>%Program Files%\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\init.debug.js</p> <p>This file defines all the functions the 'ULS' implementation on the client.</p> <p>Of course, you'll need to have SharePoint 2010 installed for the file to exist on your local machine.</p> <p><strong>UPDATE --</strong> The following is an overview of roughly how the mechanism works. The real implementation does more than this</p> <p>Consider the following html page with a few js includes, each of which can call out into each other.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="ErrorHandling.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="File1.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="File2.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button onclick="DoStuff()"&gt;Do stuff&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>We have two js include files, File1.js</p> <pre><code> function ULSabc() { var o = new Object; o.File = "File1.js"; return o; } /* ULSabc is the unique label for this js file. Each function in this file can be decorated with a label corresponding with the same name */ function DoStuff() { ULSabc: ; //label matches name of function above DoMoreStuff(); } </code></pre> <p>and File2.js</p> <pre><code> function ULSdef() { var o = new Object; o.File = "File2.js"; return o; } function DoMoreStuff() { ULSdef: ; DoEvenMoreStuff(); } function DoEvenMoreStuff() { ULSdef: ; try { //throw an error throw "Testing"; } catch (e) { //handle the error by displaying the callstack DisplayCallStack(e); } } </code></pre> <p>Now, say our ErrorHandling file looks like this</p> <pre><code> function GetFunctionInfo(fn) { var info = ""; if (fn) { //if we have a function, convert it to a string var fnTxt = fn.toString(); //find the name of the function by removing the 'function' and () var fnName = fnTxt.substring(0, fnTxt.indexOf("(")).substring(8); info += "Function: " + fnName; //next use a regular expression to find a match for 'ULS???:' //which is the label within the function var match = fnTxt.match(/ULS[^\s;]*:/); if (match) { var ULSLabel = match[0]; //if our function definition contains a label, strip off the // : and add () to make it into a function we can call eval on ULSLabel = ULSLabel.substring(0, ULSLabel.length - 1) + "()"; //eval our function that is defined at the top of our js file var fileInfo = eval(ULSLabel); if (fileInfo &amp;&amp; fileInfo.File) { //add the .File property of the returned object to the info info += " =&gt; Script file: " + fileInfo.File; } } } return info; } function DisplayCallStack(e) { //first get a reference to the function that call this var caller = DisplayCallStack.caller; var stack = "Error! " + e + "\r\n"; //recursively loop through the caller of each function, //collecting the function name and script file as we go while (caller) { stack += GetFunctionInfo(caller) + "\r\n"; caller = caller.caller; } //alert the callstack, but we could alternately do something //else like send the info to the server via XmlHttp. alert(stack); } </code></pre> <p>When we click the button on the page, our script file will call through each of the functions and end at DisplayCallStack, at which point it will recursively loop through and collect the stack trace</p> <pre><code> Error! Testing Function: DoEvenMoreStuff =&gt; Script file: File2.js Function: DoMoreStuff =&gt; Script file: File2.js Function: DoStuff =&gt; Script file: File1.js Function: onclick </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload