home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Debugger / instrumentCommon.js next >
Encoding:
JavaScript  |  2003-09-05  |  9.6 KB  |  286 lines

  1.  
  2. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  3.  
  4.  
  5. //*************************GLOBALS**************************
  6.  
  7.  
  8. var didInitResults = false;
  9.  
  10. var blockFileName = 'none';
  11. var blockLineStart = 1;
  12. var blockOffsetStart = 0;
  13.  
  14.  
  15. //*************************API**************************
  16.  
  17.  
  18. function startBlock(fileName, lineNumber, offset)
  19. {
  20.    blockFileName = fileName;
  21.    blockLineStart = new Number(lineNumber);
  22.    blockLineStart = blockLineStart.valueOf();
  23.    blockOffsetStart = new Number(offset);
  24.    blockOffsetStart = blockOffsetStart.valueOf();
  25. }
  26.  
  27. function getStartFunctionInstrument(lineNumber, offset, isInFunction)
  28. {
  29.    return "{MM_Depth++}";
  30. }
  31.  
  32. function getEndFunctionInstrument(lineNumber, offset, isInFunction)
  33. {
  34.    return "{MM_Depth--}";
  35. }
  36.  
  37. function getOnUnloadInstrument()
  38. {
  39.    var str = "MM_disconnectDbg();";
  40.    return str;
  41. }
  42.  
  43. function reportWarning(filePath, fileName, errorNumber, strDesc, lineNumber, offset)
  44. {
  45.    initResultsWin();
  46.  
  47.    var type = MM.MSG_dbgTypeWarning + ' ' + errorNumber;
  48.  
  49.    var args = processReportItemArgs(type, filePath, fileName, errorNumber, strDesc, lineNumber, offset);
  50.  
  51.    dw.runCommand("debugSyntaxResults.htm", "addItem", args[0], args[1], args[2], args[3], args[4]);
  52. }
  53.  
  54. function reportError(filePath, fileName, errorNumber, strDesc, lineNumber, offset)
  55. {
  56.    initResultsWin();
  57.  
  58.    var type = MM.MSG_dbgTypeError + ' ' + errorNumber;
  59.  
  60.    var args = processReportItemArgs(type, filePath, fileName, errorNumber, strDesc, lineNumber, offset);
  61.  
  62.    dw.runCommand("debugSyntaxResults.htm", "addItem", args[0], args[1], args[2], args[3], args[4]);
  63.    //dw.runCommand("debugSyntaxResults.htm", "addItem", desc, filePath, off1, off2, new Array(fileName, line, type, strDesc));
  64.    //resultsWin.addItem(this, '', desc, filePath, off1, off2, new Array(fileName, line, type, strDesc));
  65.    //resultsWin.addItem('', desc, off1, off2, fileName, line, type, strDesc);
  66.    /*
  67.    ///////// old way to do it
  68.    dw.results.addResultItem(filePath, 
  69.                '', //strIcon - path to icon to use. If a number between 1 and 10, use the built-in icon for that number (these will be specified later). 
  70.                fileName, // string to display to user in first column (usually file name) 
  71.                strDesc, // description to go along with entry 
  72.                line,
  73.                off1,
  74.                off2);
  75.  
  76.    ///////// really really old way to do it
  77.    dw.results.addResultItem(fileName, 
  78.                '', //strIcon - path to icon to use. If a number between 1 and 10, use the built-in icon for that number (these will be specified later). 
  79.                strDesc, // string to display to user in first column (usually file name) 
  80.                strDesc, // description to go along with entry 
  81.                lineNumber + blockLineStart,
  82.                offset + blockOffsetStart,
  83.                offset + blockOffsetStart+1);
  84.    /////////
  85.    alert("warning: line "+lineNumber+" of "+fileName+": "+strDesc);
  86.    */
  87. }
  88.  
  89.  
  90.  
  91. //*******************LOCAL FUNCTIONS*********************
  92.  
  93.  
  94. function initResultsWin()
  95. {
  96.    // new way is in the debugSyntaxResults.htm command
  97.    if ( !didInitResults ) {
  98.       dw.runCommand("debugSyntaxResults.htm", "init", 
  99.          MM.MSG_dbgResultsTitle, MM.MSG_dbgButtonGoTo, 
  100.          new Array(MM.MSG_dbgColHeadFile, MM.MSG_dbgColHeadLine, MM.MSG_dbgColHeadType, MM.MSG_dbgColHeadDescription), 
  101.          new Array(120, 40, 80, 330));
  102.       didInitResults = true;
  103.    }
  104.    /*
  105.    ///////// old way to do it
  106.    var didInitResults = false;
  107.    if ( !resultsWin ) {
  108.       resultsWin = dw.createResultsWindow(MM.MSG_dbgResultsTitle, 
  109.                      new Array(MM.MSG_dbgColHeadFile, MM.MSG_dbgColHeadLine, MM.MSG_dbgColHeadType, MM.MSG_dbgColHeadDescription));
  110.       resultsWin.setColumnWidths(74, 40, 60, 330);
  111.       resultsWin.setButtons(this, new Array(MM.MSG_dbgButtonGoTo, "goToLine()"));
  112.       didInitResults = true;
  113.    }
  114.    ///////// really really old way to do it
  115.    if ( !didInitResultsWin ) {
  116.       dw.createResultsWindow();
  117.       didInitResultsWin = true;
  118.    }
  119.    */
  120. }
  121.  
  122.  
  123. function processReportItemArgs(type, filePath, fileName, errorNumber, strDesc, lineNumber, offset)
  124. {
  125.    var desc = type + ' ' + strDesc;
  126.    var line = new Number(lineNumber);
  127.    line = line.valueOf() + blockLineStart;
  128.    var off1 = new Number(offset);
  129.    off1 = off1.valueOf() + blockOffsetStart;
  130.    var off2 = new Number(offset);
  131.    off2 = off2.valueOf() + blockOffsetStart + 1;
  132.    // extend selection to end of line (off2 includes the next linefeed)
  133.    var doc = dw.getDocumentDOM(filePath);
  134.    if ( doc ) {
  135.       var off2Char = doc.source.getText(off2, off2+1);
  136.       while ( off2Char.length == 1 && off2Char != '\r' && off2Char != '\n' ) {
  137.          off2++;
  138.          off2Char = doc.source.getText(off2, off2+1);
  139.       }
  140.       // sn 7/13/01: I'm tweaking this to match both characters of a CRLF,
  141.       // otherwise we would try to select just the CR, which would throw
  142.       // an assertion in the text engine.  (This problem was caused by my
  143.       // recent change to make the document.source API layer reflect the
  144.       // true line break style in use, even if it's CRLF.)
  145.       if (off2Char == '\r' && doc.source.getText(off2+1, off2+2) == '\n')
  146.           off2++;
  147.       off2++;
  148.    }
  149.  
  150.    // chop off after the \n in the list item description
  151.    var n = strDesc.indexOf('\n');
  152.    if ( n >= 0 && n < strDesc.length-1 ) {
  153.       strDesc = strDesc.substring(0, n);
  154.    }
  155.  
  156.    // (windows only) 
  157.    // replace the \n with \r\n in the full item description
  158.    if (navigator.platform != "MacPPC")
  159.    {
  160.       n = desc.indexOf('\n');
  161.       if ( n >= 0 && n < desc.length-1 ) {
  162.          desc = desc.substring(0, n) + "\r\n" + desc.substring(n+1, desc.length);
  163.       }
  164.    }
  165.  
  166.    // return the args list for the call to dw.runCommand
  167.    return new Array(desc, filePath, off1, off2, new Array(fileName, line, type, strDesc));
  168. }
  169.  
  170. function getCommonHeadFunctions()
  171. {
  172.    var str = "";
  173.    str += "function MM_wasAlreadyLoaded() {\n";
  174.    str += "   var cData = unescape(document.cookie);\n";
  175.    str += "   var name = \"MM_debugDocURL\";\n";
  176.    str += "   var nStart = cData.indexOf(name);\n";
  177.    str += "   var value='';\n";
  178.    str += "   var vStart;\n";
  179.    str += "   var vLength = unescape(document.URL).length;\n";
  180.    str += "   var nameValue = name + \"=\" + unescape(document.URL);\n";
  181.    str += "   if (nStart != -1)\n";
  182.    str += "   {\n";
  183.    str += "      vStart = nStart + \"MM_debugDocURL\".length + 1;\n";
  184.    str += "      value = cData.substring(vStart, vStart + vLength);\n";
  185.    str += "   }\n";
  186.    str += "   if (value != unescape(document.URL))\n";
  187.    str += "      document.cookie = nameValue;\n";
  188.    str += "   return (value == unescape(document.URL));\n";
  189.    str += "}\n";
  190.  
  191.    // jschang 31752 - add the member function reverseFind to the Array object
  192.    // for use by the built-in instrumentation for MM_localVars
  193.    str += "function MM_Array_reverseFind(str) {\n";
  194.    str += "   var i = this.length-1;\n";
  195.    str += "   while(i>=0){\n";
  196.    str += "      if(this[i]==str){break;}\n";
  197.    str += "      else {i--;}\n";
  198.    str += "   }\n";
  199.    str += "   return i;\n";
  200.    str += "}\n";
  201.    str += "Array.prototype.reverseFind = MM_Array_reverseFind;\n";
  202.    return str;
  203. }
  204.  
  205. function getCommonBodyInstrument()
  206. {
  207.    var strIndex = getMessageIndex();
  208.  
  209.    var str = "";
  210.    str += "<noscript> \n";
  211.    str += "<p>\n";
  212.    str += MM.MSG_dbgNoScript[strIndex];
  213.    str += "</p>\n";
  214.    str += "</noscript> \n";
  215.    return str;
  216. }
  217.  
  218. function getIE4NetscapeHeadFunctions()
  219. {
  220.    str = "";
  221.    str += "document.MM_debugLocalVars = new String('the debug eval context');\n";
  222.    return str;
  223. }
  224.  
  225. function getIE4NetscapeStepInstrument(lineNumber, offset, isInFunction)
  226. {
  227.    var line = blockLineStart + new Number(lineNumber);
  228.    var off = blockOffsetStart + new Number(offset);
  229.    // check !MM_bEval in case the user requests an value from the 
  230.    // debugger that happens to call instrumented code
  231.    var str = "";
  232.     //"{"
  233.    if ( isInFunction == "true" ) {
  234.         str += "MM_bD=true;";
  235.         str += "while(MM_bD&&!MM_bInEval){";
  236.         //"}"
  237.         str +=     "var MM_evalCtxt=eval('document.MM_debugLocalVars'),MM_bArg=false;";
  238.         str +=     "if(!MM_bArg&&MM_D.length>0)";
  239.         str +=     "{";
  240.         str +=         "MM_evalCtxt.length=0;";
  241.         str +=         "MM_bArg=true;";
  242.         str +=         "for(MM_p=0;MM_p<MM_localVars.length;MM_p++){";
  243.         str +=             "eval('MM_evalCtxt.'+MM_localVars[MM_p]+'='+MM_localVars[MM_p]);";
  244.         str +=             "eval('MM_evalCtxt.'+MM_localVars[MM_p]);";
  245.         str +=         "}";
  246.         str +=         "MM_bArg=true;";
  247.         str +=     "}";
  248.         str +=     "var MM_didEval=(MM_D.length>0);";
  249.         str +=     "MM_bD=MM_Debug(MM_evalDbg(MM_evalCtxt,MM_D),'";
  250.     }
  251.    else {
  252.         str += "MM_bD=true;";
  253.         str += "while(MM_bD&&!MM_bInEval){";
  254.         str +=     "MM_bD=MM_Debug(MM_evalDbg(this,MM_D),'";
  255.         //"}"
  256.     }
  257.  
  258.    str +=                                blockFileName +"',";
  259.    str +=                                line +",";
  260.    str +=                                off;
  261.    str +=                            ");";
  262.  
  263.    if ( isInFunction == "true" ) {
  264.         str +=     "if(MM_didEval){";
  265.         str +=         "for(MM_p=0;MM_p<MM_localVars.length;MM_p++){";
  266.         str +=             "eval(MM_localVars[MM_p]+'=MM_evalCtxt.'+MM_localVars[MM_p]);";
  267.         str +=         "}";
  268.         str +=     "}";
  269.     }
  270.    str += "}";
  271.    return str;
  272. }
  273.  
  274. function getMessageIndex() {
  275.    var charSet = dw.getDocumentDOM().getCharSet().toLowerCase();
  276.    var messageIndex;
  277.    // if the encoding is either "shift_jis" or "x-sjis" 
  278.    // put up Japanese messages.
  279.    if (charSet == "shift_jis" || charSet == "x-sjis" || charSet == "euc-kr" || charSet == "big5" || charSet == "gb2312") 
  280.         messageIndex = 1;
  281.    else 
  282.         messageIndex = 0;
  283.  
  284.    return messageIndex;
  285. }
  286.