Skip to content
Snippets Groups Projects
navig.js 11.45 KiB


var handlers = [];

var parsedTree;

(function(check_pred){

var tracer_items = [];

var tracer_length = 0;
var tracer_pos = 0; 

$("#source_code").val(source_file);


function stepTo(step) {
  tracer_pos = step;
  updateSelection();
}

// Take a predicate in form of a JavaScript code (string) and returns either true or an error message (string).
function goToPred(pred) {

  function check(i){
    var item = datalog[i];
    var jsheap = jsheap_of_heap(item.heap);
    var obj = jsenv_of_env(jsheap, item.env);
    var objX = {};
    if (item.ctx !== undefined){
        objX = jsenv_of_env(jsheap, item.ctx);
    }
    objX.line = item.line;
    objX.type = item.type;
    objX.heap = jsheap;
    obj.X = objX; // If we want to change the “X” identifier, just change this line.
    try {
      if (check_pred(pred, obj)){
          stepTo(i);
          return true;
      }
    } catch(e){
      error++;
    }

    return false;
  }

  var error = 0;

  if (datalog.length === 0)
      return false;

  for (var i = (tracer_pos + 1) % datalog.length, current = tracer_pos;
       i !== current;
       i++, i %= datalog.length)
    if (check(i))
      return true;

  if (check(tracer_pos))
    return true;

  if (error === datalog.length)
    return "There was an execution error at every execution of your condition: are you sure that this is a valid JavaScript code?";

  return "Not found";
}

function button_reach_handler() {
  var pred = $("#text_condition").val();