<commit_before>ipc = require 'ipc'
webContents = require 'web-contents'
webViewManager = null  # Doesn't exist in early initialization.

supportedWebViewEvents = [
  'did-finish-load'
  'did-fail-load'
  'did-frame-finish-load'
  'did-start-loading'
  'did-stop-loading'
  'did-get-redirect-request'
  'console-message'
  'new-window'
  'close'
  'crashed'
  'destroyed'
]

nextInstanceId = 0
guestInstances = {}
embedderElementsMap = {}
reverseEmbedderElementsMap = {}

# Generate guestInstanceId.
getNextInstanceId = (webContents) ->
  ++nextInstanceId

# Create a new guest instance.
createGuest = (embedder, params) ->
  webViewManager ?= process.atomBinding 'web_view_manager'

  id = getNextInstanceId embedder
  guest = webContents.create
    isGuest: true
    guestInstanceId: id
    storagePartitionId: params.storagePartitionId
  guestInstances[id] = {guest, embedder}

  # Destroy guest when the embedder is gone or navigated.
  destroyEvents = ['destroyed', 'crashed', 'did-navigate-to-different-page']
  destroy = ->
    destroyGuest id if guestInstances[id]?
    embedder.removeListener event, destroy for event in destroyEvents<commit_msg>Suppress EventEmitter warnings<commit_after>ipc = require 'ipc'
webContents = require 'web-contents'
webViewManager = null  # Doesn't exist in early initialization.

supportedWebViewEvents = [
  'did-finish-load'
  'did-fail-load'
  'did-frame-finish-load'
  'did-start-loading'
  'did-stop-loading'
  'did-get-redirect-request'
  'console-message'
  'new-window'
  'close'
  'crashed'
  'destroyed'
]

nextInstanceId = 0
guestInstances = {}
embedderElementsMap = {}
reverseEmbedderElementsMap = {}

# Generate guestInstanceId.
getNextInstanceId = (webContents) ->
  ++nextInstanceId

# Create a new guest instance.
createGuest = (embedder, params) ->
  webViewManager ?= process.atomBinding 'web_view_manager'

  id = getNextInstanceId embedder
  guest = webContents.create
    isGuest: true
    guestInstanceId: id
    storagePartitionId: params.storagePartitionId
  guestInstances[id] = {guest, embedder}

  # Destroy guest when the embedder is gone or navigated.
  destroyEvents = ['destroyed', 'crashed', 'did-navigate-to-different-page']
  destroy = ->
    destroyGuest id if guestInstances[id]?
    embedder.removeListener event, destroy for event in destroyEvents
  embedder.setMaxListeners 100  # we can have lots of <webview> in one page.
{'fraction_non_alphanumeric': 0.10616153205661949, 'fraction_numerical': 0.0020815986677768525, 'mean_word_length': 4.486301369863014, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, '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': '401156', 'n_tokens_mistral': 779, 'n_tokens_neox': 770, 'n_words': 182}