<commit_before>/*
 Source is originated from https://github.com/morungos/java-xmlhttprequest

 Articles about Nashorn:
 - https://blog.codecentric.de/en/2014/06/project-nashorn-javascript-jvm-polyglott/
 */
(function nashornEventLoopMain(context) {
  'use strict';

  var Timer = Java.type('java.util.Timer');
  var TimerTask =  Java.type("java.util.TimerTask");
  var HashMap = Java.type('java.util.HashMap');

//   var finalException = null;

  var timerMap = new HashMap(1);
  var globalTimerId = 1;

  var timer = new Timer('jsEventLoop', false);

  var onTaskFinished = function () {
  };

//   var shutdown = function () {
//     timer.cancel();
//   };

  function createTimerTask (fn, timerId, args, repeated) {
    return new TimerTask {
      run: function () {
        try {
          fn.apply(context, args);
          if (!repeated) timerMap.remove(timerId);
        } catch (e) {

          // Store the error
//           finalException = e;
          console.error(e);
          // Clear the task
          if (repeated) {
            var task = timerMap.get(timerId);
            if (task) task.cancel();
          }
          timerMap.remove(timerId);
        }
      }
    }
  }

  var setTimeout = function (fn, millis /* [, args...] */) {
    var args = [].slice.call(arguments, 2, arguments.length);

    var timerId = globalTimerId++;
    var task = createTimerTask(fn, timerId, args, false);

    timerMap.put(timerId, task);

    timer.schedule(task, millis);

    return timerId;
  };

  var clearTimeout = function (timerId) {
    var task = timerMap.get(timerId);
    if (task) {
      task.cancel();
      timerMap.remove(timerId);
    }
  };

  var setInterval = function (fn, delay /* [, args...] */) {
    var args = [].slice.call(arguments, 2, arguments.length);

    var timerId = globalTimerId++;
    var task = createTimerTask(fn, timerId, args, true);
    timerMap.put(timerId, task);

    timer.scheduleAtFixedRate(task, delay, delay);

    return timerId;
  };

  var clearInterval = function (timerId) {
    clearTimeout(timerId);
  };

  context.setTimeout = setTimeout;
  context.clearTimeout = clearTimeout;
  context.setInterval = setInterval;
  context.clearInterval = clearInterval;
  context.__nashorn_polyfill_timerMap = timerMap;
  context.__nashorn_polyfill_timer = timer;
})(typeof global !== "undefined" && global || typeof self !== "undefined" && self || this);<commit_msg>Changed to __NASHORN_POLYFILL_TIMER__ which is inject by Nashorn engine with ScheduledExecutorService<commit_after>/*
 Source is originated from https://github.com/morungos/java-xmlhttprequest

 Articles about Nashorn:
 - https://blog.codecentric.de/en/2014/06/project-nashorn-javascript-jvm-polyglott/
 */
(function nashornEventLoopMain(context) {
  'use strict';

  var TimerTask =  Java.type("java.util.TimerTask");
  var TimeUnit = Java.type("java.util.concurrent.TimeUnit");
  var HashMap = Java.type('java.util.HashMap');

//   var finalException = null;

  var timerMap = new HashMap(1);
  var globalTimerId = 1;

  var timer = context.__NASHORN_POLYFILL_TIMER__;

  var onTaskFinished = function () {
  };

//   var shutdown = function () {
//     timer.cancel();
//   };

  function createTimerTask (fn, timerId, args, repeated) {
    return new TimerTask {
      run: function () {
        try {
          fn.apply(context, args);
          if (!repeated) timerMap.remove(timerId);
        } catch (e) {
//           console.error(e);
//           console.trace(e);
//           console.trace(fn);
//           console.trace(args);
//           console.trace(repeated);
          // Clear the task
          if (repeated) {
            var task = timerMap.get(timerId);
            if (task) task.cancel();
          }
          timerMap.remove(timerId);
        }
      }
    }
  }

  var setTimeout = function (fn, millis /* [, args...] */) {
    var args = [].slice.call(arguments, 2, arguments.length);

    var timerId = globalTimerId++;
    var task = createTimerTask(fn, timerId, args, false);

    timerMap.put(timerId, task);

    timer.schedule(task, millis, TimeUnit.MILLISECONDS);

    return timerId;
  };

  var clearTimeout = function (timerId) {
    var task = timerMap.get(timerId);
    if (task) {
      task.cancel();
      timerMap.remove(timerId);
    }
  };

  var setInterval = function (fn, delay /* [, args...] */) {
    var args = [].slice.call(arguments, 2, arguments.length);

    var timerId = globalTimerId++;
    var task = createTimerTask(fn, timerId, args, true);
    timerMap.put(timerId, task);

    timer.scheduleWithFixedDelay(task, delay, delay, TimeUnit.MILLISECONDS);

    return timerId;
  };

  var clearInterval = function (timerId) {
    clearTimeout(timerId);
  };

  context.setTimeout = setTimeout;
  context.clearTimeout = clearTimeout;
  context.setInterval = setInterval;
  context.clearInterval = clearInterval;
  context.__nashorn_polyfill_timerMap = timerMap;
})(typeof global !== "undefined" && global || typeof self !== "undefined" && self || this);
{'fraction_non_alphanumeric': 0.1384920634920635, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 2.759134973900075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4081119', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1545, 'n_words': 350}