<commit_before>
var ConnectionProto = getConnectionProto();

/*
 * Hijack method calls
 */
var original_Connection_apply = ConnectionProto.apply;
ConnectionProto.apply = function () {
  var args = Array.prototype.slice.call(arguments);
  if(args.length) {
    var callback = args[args.length - 1];
    if(typeof callback === 'function') {
      args[args.length - 1] = zone.bind(callback);
      original_Connection_apply.apply(this, args);
    };
  };
};

/*
 * Hijack DDP subscribe method
 * Used when connecting to external DDP servers
 */
var original_Connection_subscribe = ConnectionProto.subscribe;
ConnectionProto.subscribe = function () {
  var args = Array.prototype.slice.call(arguments);
  if(args.length) {
    var callback = args[args.length - 1];
    if(typeof callback === 'function') {
      args[args.length - 1] = zone.bind(callback);
    } else if(callback) {
      ['onReady', 'onError'].forEach(function (funName) {
        if(typeof callback[funName] === "function") {
          callback[funName] = zone.bind(callback[funName]);
        };
      });
    }
    original_Connection_subscribe.apply(this, args);
  }
}

/**
 * Hijack Meteor.subscribe because Meteor.subscribe binds to
 * Connection.subscribe before the hijack
 */
var original_Meteor_subscribe = Meteor.subscribe;
Meteor.subscribe = function () {
  var args = Array.prototype.slice.call(arguments);
  if(args.length) {
    var callback = args[args.length - 1];
    if(typeof callback === 'function') {
      args[args.length - 1] = zone.bind(callback);
    } else if(callback) {
      ['onReady', 'onError'].forEach(function (funName) {
        if(typeof callback[funName] === "function") {
          callback[funName] = zone.bind(callback[funName]);
        };
      });
    }
    original_Meteor_subscribe.apply(this, args);
  }
}

var original_Cursor_observe = LocalCollection.Cursor.prototype.observe;
LocalCollection.Cursor.prototype.observe = hijackCursor(original_Cursor_observe);


function getConnectionProto() {
  var con = DDP.connect(window.location.origin);
  con.disconnect();
  var proto = con.constructor.prototype;
  return proto;
}
<commit_msg>better hijacking for clean stacktrace<commit_after>
var ConnectionProto = getConnectionProto();

/*
 * Hijack method calls
 */
var original_Connection_apply = ConnectionProto.apply;
ConnectionProto.apply = hijackConnection(original_Connection_apply);

// for better stackTraces
var originalMeteorCall = Meteor.call;
Meteor.call = hijackConnection(originalMeteorCall);

/*
 * Hijack DDP subscribe method
 * Used when connecting to external DDP servers
 */
var original_Connection_subscribe = ConnectionProto.subscribe;
ConnectionProto.subscribe = hijackSubscribe(original_Connection_subscribe);

/**
 * Hijack Meteor.subscribe because Meteor.subscribe binds to
 * Connection.subscribe before the hijack
 */
var original_Meteor_subscribe = Meteor.subscribe;
Meteor.subscribe = hijackSubscribe(original_Meteor_subscribe);

var original_Cursor_observe = LocalCollection.Cursor.prototype.observe;
LocalCollection.Cursor.prototype.observe = hijackCursor(original_Cursor_observe);


function getConnectionProto() {
  var con = DDP.connect(window.location.origin);
  con.disconnect();
  var proto = con.constructor.prototype;
  return proto;
}

{'fraction_non_alphanumeric': 0.11784409257003654, 'fraction_numerical': 0.0018270401948842874, 'mean_word_length': 4.367647058823529, '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': '3256244', 'n_tokens_mistral': 965, 'n_tokens_neox': 939, 'n_words': 198}