<commit_before>class PostMessage

  @postMessage: (message, targetOrigin) =>
    escapedJSONMessage = escape(JSON.stringify(message))

    steroids.nativeBridge.nativeCall
      method: "broadcastJavascript"
      parameters:
        javascript: "steroids.PostMessage.dispatchMessageEvent('#{escapedJSONMessage}', '*');"
      successCallbacks: []
      failureCallbacks: []
      recurringCallbacks: []



  @dispatchMessageEvent: (escapedJSONMessage, targetOrigin) =>
    message = JSON.parse(unescape(escapedJSONMessage))

    e = document.createEvent "MessageEvent"

    #                  type       bubles etc    message    origin
    e.initMessageEvent "message", false, false, message, "", "", window, null

    window.dispatchEvent e<commit_msg>Wrapped the dispatchMessageEvent in a setTimeout of 1 milisec.. to make sure everything is executed in the webkit thread. With the new native bridge, the javascript executed might be done in other threads and this can lock the UI.<commit_after>class PostMessage

  @postMessage: (message, targetOrigin) =>
    escapedJSONMessage = escape(JSON.stringify(message))

    steroids.nativeBridge.nativeCall
      method: "broadcastJavascript"
      parameters:
        javascript: "steroids.PostMessage.dispatchMessageEvent('#{escapedJSONMessage}', '*');"
      successCallbacks: []
      failureCallbacks: []
      recurringCallbacks: []



  @dispatchMessageEvent: (escapedJSONMessage, targetOrigin) =>
    #wrap in a setTimeout to garantee that runs in the webkit thread.
    setTimeout ->
      message = JSON.parse(unescape(escapedJSONMessage))

      e = document.createEvent "MessageEvent"

      #                  type       bubles etc    message    origin
      e.initMessageEvent "message", false, false, message, "", "", window, null

      window.dispatchEvent e
    ,
      1
{'fraction_non_alphanumeric': 0.09363091997822537, 'fraction_numerical': 0.0010887316276537834, 'mean_word_length': 3.386634844868735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1422654', 'n_tokens_mistral': 502, 'n_tokens_neox': 476, 'n_words': 127}