<commit_before>
/**
 * Module requirements.
 */

var Transport = require('../transport')
  , Polling = require('./polling')
  , util = require('../util')

/**
 * Module exports.
 */

module.exports = JSONPPolling;

/**
 * Cached regular expressions.
 */

var rNewline = /\n/g

/**
 * Noop.
 */

function empty () { }

/**
 * JSONP Polling constructor.
 *
 * @param {Object} opts.
 * @api public
 */

function JSONPPolling (opts) {
  Transport.call(this, opts);
  this.setIndex();
};

/**
 * Inherits from Polling.
 */

util.inherits(JSONPPolling, Polling);

/**
 * Transport name.
 *
 * @api public
 */

JSONPPolling.prototype.name = 'polling-jsonp';

/**
 * Sets JSONP global callback.
 *
 * @api private
 */

JSONPPolling.prototype.setIndex = function () {
  // if we have an index already, set it to empy
  if (undefined != this.index) {
    eio.j[this.index] = empty;
  }

  var self = this;
  this.index = eio.j.length;
  eio.j.push(function (msg) {
    self.onData(msg);
  });
};

/**
 * Opens the socket.
 *
 * @api private
 */

JSONPPolling.prototype.doOpen = function () {
  var self = this;
  util.defer(function () {
    Polling.prototype.doOpen.call(self);
  });
};

/**
 * Closes the socket
 *
 * @api private
 */

JSONPPolling.prototype.doClose = function () {
  this.setIndex();

  if (this.script) {
    this.script.parentNode.removeChild(this.script);
  }

  Polling.prototype.doClose.call(this);
};

/**
 * Starts a poll cycle.
 *
 * @api private
 */

JSONPPolling.prototype.doPoll = function () {
  var self = this
    , script = document.createElement('script')
    , query = io.util.query(
           this.socket.options.query
        , 't='+ (+new Date) + '&i=' + this.index
      );<commit_msg>Detach form (POST) upon close in JSONP<commit_after>
/**
 * Module requirements.
 */

var Transport = require('../transport')
  , Polling = require('./polling')
  , util = require('../util')

/**
 * Module exports.
 */

module.exports = JSONPPolling;

/**
 * Cached regular expressions.
 */

var rNewline = /\n/g

/**
 * Noop.
 */

function empty () { }

/**
 * JSONP Polling constructor.
 *
 * @param {Object} opts.
 * @api public
 */

function JSONPPolling (opts) {
  Transport.call(this, opts);
  this.setIndex();
};

/**
 * Inherits from Polling.
 */

util.inherits(JSONPPolling, Polling);

/**
 * Transport name.
 *
 * @api public
 */

JSONPPolling.prototype.name = 'polling-jsonp';

/**
 * Sets JSONP global callback.
 *
 * @api private
 */

JSONPPolling.prototype.setIndex = function () {
  // if we have an index already, set it to empy
  if (undefined != this.index) {
    eio.j[this.index] = empty;
  }

  var self = this;
  this.index = eio.j.length;
  eio.j.push(function (msg) {
    self.onData(msg);
  });
};

/**
 * Opens the socket.
 *
 * @api private
 */

JSONPPolling.prototype.doOpen = function () {
  var self = this;
  util.defer(function () {
    Polling.prototype.doOpen.call(self);
  });
};

/**
 * Closes the socket
 *
 * @api private
 */

JSONPPolling.prototype.doClose = function () {
  this.setIndex();

  if (this.script) {
    this.script.parentNode.removeChild(this.script);
    this.script = null;
  }

  if (this.form) {
    this.form.parentNode.removeChild(this.form);
    this.form = null;
  }

  Polling.prototype.doClose.call(this);
};

/**
 * Starts a poll cycle.
 *
 * @api private
 */

JSONPPolling.prototype.doPoll = function () {
  var self = this
    , script = document.createElement('script')
    , query = io.util.query(
           this.socket.options.query
        , 't='+ (+new Date) + '&i=' + this.index
      );
{'fraction_non_alphanumeric': 0.1738401341531582, 'fraction_numerical': 0.0, 'mean_word_length': 2.743723849372385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4988101', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1268, 'n_words': 261}