<commit_before>(function() {
  if (typeof window === 'undefined') return;

  /**
   * Turns an array-like object into an array of serialized strings, suitable for the native layer
   * @param args
   * @returns {unknown[]}
   */
  var convertArguments = function(args) {
    args = Array.from(args);
    return args.map(function(elt) {
        return JSON.stringify({value: elt});
    });
  };

  /**
   * Flattens (max 2-level deep) the provided array
   * @param array
   * @returns array
   */
  var flatten = function(array) {
    return array.reduce(function(acc, cur) {
      if (Array.isArray(cur)) cur.forEach(function(elt) { acc.push(elt); });
      else acc.push(cur);
      return acc;
    }, []);
  };

  window.WonderPushInAppSDK = window.WonderPushPopupSDK = new Proxy({}, new function() {

    /**
     * Calls the provided func of the native layer:
     * - handles argument serialization
     * - handles result deserialization
     * - handles errors
     * @param func
     * @param args
     * @returns {Promise<any>}
     */
    var callNativeLayer = function(func, args) {
      try {
        var result = func.apply(window._wpiam, convertArguments(args));
        if (result === null || result === undefined) {
            return Promise.resolve();
        }
        if (typeof result === 'string') {
            try {
              var decoded = JSON.parse(result);
              if ("result" in decoded) return Promise.resolve(decoded.result);
              if ("error" in decoded) return Promise.reject(new Error(decoded.error));
            } catch (e) {
              console.error(e);
              // Return result as-is.
            }
        }
        return Promise.resolve(result);
      } catch (e) {
        return Promise.reject(e);
      }
    };

    /**
     * The main Proxy method
     * @type {any}
     */
    this.get = function(target, prop, receiver) {
      if (this.hasOwnProperty(prop)) return this[prop];
      var func = window._wpiam[prop];
      if (!func) {
        return undefined;
      }
      return function() {
        // Delay dismiss
        if (prop === 'dismiss') {
            return new Promise(function (res, rej) {
                setTimeout(function() {
                    callNativeLayer(func, arguments).then(res, rej);
                }, 10);
            });
        }
        return callNativeLayer(func, arguments);
      };
    }.bind(this);

    /**
     * Takes tags as arguments:<commit_msg>Popups: same behavior as iOS for unknown method<commit_after>(function() {
  if (typeof window === 'undefined') return;

  /**
   * Turns an array-like object into an array of serialized strings, suitable for the native layer
   * @param args
   * @returns {unknown[]}
   */
  var convertArguments = function(args) {
    args = Array.from(args);
    return args.map(function(elt) {
        return JSON.stringify({value: elt});
    });
  };

  /**
   * Flattens (max 2-level deep) the provided array
   * @param array
   * @returns array
   */
  var flatten = function(array) {
    return array.reduce(function(acc, cur) {
      if (Array.isArray(cur)) cur.forEach(function(elt) { acc.push(elt); });
      else acc.push(cur);
      return acc;
    }, []);
  };

  window.WonderPushInAppSDK = window.WonderPushPopupSDK = new Proxy({}, new function() {

    /**
     * Calls the provided func of the native layer:
     * - handles argument serialization
     * - handles result deserialization
     * - handles errors
     * @param func
     * @param args
     * @returns {Promise<any>}
     */
    var callNativeLayer = function(func, args) {
      try {
        var result = func.apply(window._wpiam, convertArguments(args));
        if (result === null || result === undefined) {
            return Promise.resolve();
        }
        if (typeof result === 'string') {
            try {
              var decoded = JSON.parse(result);
              if ("result" in decoded) return Promise.resolve(decoded.result);
              if ("error" in decoded) return Promise.reject(new Error(decoded.error));
            } catch (e) {
              console.error(e);
              // Return result as-is.
            }
        }
        return Promise.resolve(result);
      } catch (e) {
        return Promise.reject(e);
      }
    };

    /**
     * The main Proxy method
     * @type {any}
     */
    this.get = function(target, prop, receiver) {
      if (this.hasOwnProperty(prop)) return this[prop];
      var func = window._wpiam[prop];
      if (!func) {
        return function() { return Promise.reject(new Error('Unknown method '+prop)); };
      }
      return function() {
        // Delay dismiss
        if (prop === 'dismiss') {
            return new Promise(function (res, rej) {
                setTimeout(function() {
                    callNativeLayer(func, arguments).then(res, rej);
                }, 10);
            });
        }
        return callNativeLayer(func, arguments);
      };
    }.bind(this);

    /**
     * Takes tags as arguments:
{'fraction_non_alphanumeric': 0.13291013687760364, 'fraction_numerical': 0.0011902400317397343, 'mean_word_length': 1.9869668246445498, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '664929', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1418, 'n_words': 377}