User:Lupin/Scripter/evaluator

From Wikipedia, the free encyclopedia

//////////////////////////////////////////////////////////////// // Evaluator // Source: http://krolik.net/js-eval.shtml

var evaluatorHTML='<FORM ID="Tester" NAME="Tester" onsubmit="return TesterExecute();" >' +

 '<TEXTAREA NAME="MyCommand" COLS=60 ROWS=25 WRAP="off"></TEXTAREA>' +
 '<TEXTAREA NAME="MyResult" COLS=40 ROWS=25 WRAP="off"></TEXTAREA>' + 
 '
' + '<INPUT TYPE=BUTTON value="Show Object" onclick="ObjectDumpClicked();" >' + '<INPUT TYPE=BUTTON value="Execute" onclick="TesterExecute();">' + '</FORM>';

function ObjectDump(strObject) {

 var strOutput; 
 var vTemp; 
 var vAnotherTemp; 
 var vElement;
 vElement = eval(strObject); 
 strOutput = "typeof = " + typeof(vElement) + "\n\n";
 AppendOutput(strOutput);
 for (var x in vElement )  
 { 
  vTemp = strObject + "." + x.toString() ; 
  vAnotherTemp = strObject + "[" + x + "]" ; 
  strOutput = strOutput + vTemp + " = " + eval(vTemp) + "\n";
  AppendOutput(vTemp + " = " + eval(vTemp) + "\n");
 } 
 return strOutput ;  
} 
function AppendOutput(strText)
{
 document.Tester.MyResult.value = document.Tester.MyResult.value + strText;
}
function Output(strText)
{
 document.Tester.MyResult.value = strText;
}
function ObjectDumpClicked() 
{
 document.Tester.MyResult.value="";
 ObjectDump(document.Tester.MyCommand.value); 
 return false;
}
function TesterExecute() 
{       
 document.Tester.MyResult.value="";
 document.Tester.MyResult.value=eval(document.Tester.MyCommand.value); 
 return false;
}

function addEvaluator() {

 var evalNode=document.createElement('div');
 evalNode.id='evalNode';
 evalNode.innerHTML=evaluatorHTML;
 document.body.appendChild(evalNode);
 document.Tester=document.getElementById('Tester');

}

addOnloadFunction(addEvaluator);

// // end evaluator ////////////////////////////////////////////////////////////////