aboutsummaryrefslogtreecommitdiff
path: root/test.js
diff options
context:
space:
mode:
authorNateN1222 <nathannichols454@gmail.com>2017-10-11 20:10:01 -0500
committerNateN1222 <nathannichols454@gmail.com>2017-10-11 20:10:01 -0500
commit0eb20948e15a7763936032e1e0a55ee46969da7e (patch)
tree83dbe204bde1ff7c3362d62f5261cc7327f4b3d7 /test.js
parent080e11de5c73b45893ff09d94383217ac02309f3 (diff)
Made a debugging page for the evaluation code
Diffstat (limited to 'test.js')
-rw-r--r--test.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..1395588
--- /dev/null
+++ b/test.js
@@ -0,0 +1,95 @@
+var acorn = require('acorn/dist/acorn_loose');
+var walk = require("acorn/dist/walk");
+
+window.onload = function () {
+
+ document.getElementById("parse").addEventListener("click",function(){
+
+ var ast = acorn.parse_dammit(document.getElementById("input").value).body[0];
+ document.getElementById("output").innerHTML = JSON.stringify(ast, null, "\t"); // Indented with tab
+ console.log(ast);
+
+ var flag = false;
+ var amtloops = 0;
+
+ walk.recursive(ast, null, {
+ Literal(node, state, c) {
+ console.log("literal");
+ },
+ Identifier(node, state, c){
+ if(state.called === true){
+ console.log("calls '"+node.name+"'");
+ }
+ },
+ // The beggining of an "object chain" (obj1.obj2().property.value......)
+ ExpressionStatement(node, state, c) {
+ c(node["expression"],{});
+ },
+ CallExpression(node, state, c) {
+ console.log("CallExpression");
+ c(node["callee"],{"called":true});
+ for(var i = 0; i < node.arguments.length; i++){
+ console.log(node.arguments[i]);
+ c(node.arguments[i],{});
+ }
+ },
+ MemberExpression(node, state, c){
+ if(state.called === true){
+ console.log("calls '"+node.property.name+"'");
+ }
+ c(node["object"],{});
+ },
+ ArrayExpression(node, state, c){
+ var len = 0;
+ try{
+ var temp = script.substring(node["start"],node["end"]);
+ len = JSON.parse(temp).length;
+ } catch(e){
+ console.warn("Invalid array?");
+ len = 99;
+ }
+ if(len > 50){
+ console.log("%c NONTRIVIAL: Array longer than 50 elements. ("+len+")","color:red");
+ flag = false;
+ }
+
+ },
+ ForInStatement(node, state, c){
+ console.log("ForInStatement");
+ amtloops++;
+ },
+ ForStatement(node, state, c){
+ console.log("ForStatement");
+ amtloops++;
+ },
+ DoWhileStatement(node, state, c){
+ console.log("DoWhileStatement");
+ amtloops++;
+ },
+ WhileStatement(node, state, c){
+ console.log("WhileStatement");
+ amtloops++;
+ },
+ IfStatement(node, state, c){
+ console.log("IfStatement");
+ c(node.test,{});
+ c(node.consequent,{});
+ amtloops++;
+ },
+ SwitchStatement(node, state, c){
+ console.log("SwitchStatement");
+ amtloops++;
+ }
+
+ });
+ if(flag == false){
+ return false;
+ }
+ if(amtloops > 3){
+ console.log("%c NONTRIVIAL: Too many loops/conditionals.","color:red");
+ return false;
+ }
+ });
+
+}
+