src/third_party/mozjs/extract/intl/l10n/L10nRegistry.jsm
/**
 * This function generates an iterator over FluentBundles for a single locale
 * for a given list of resourceIds for all possible combinations of sources.
 *
 * This function is called recursively to generate all possible permutations
 * and uses the last, optional parameter, to pass the already resolved
 * sources order.
 *
 * Notice: Any changes to this method should be copied
 * to the `generateResourceSetsForLocaleSync` equivalent below.
 *
 * @param {String} locale
 * @param {Array} sourcesOrder
 * @param {Array} resourceIds
 * @param {Array} [resolvedOrder]
 * @returns {AsyncIterator<FluentBundle>}
 */
This function generates an iterator over FluentBundles for a single locale
for a given list of resourceIds for all possible combinations of sources.

This function is called recursively to generate all possible permutations
and uses the last, optional parameter, to pass the already resolved
sources order.

Any changes to this method should be copied
to the `generateResourceSetsForLocaleSync` equivalent below.


This function generates an iterator over FluentBundles for a single locale for a given list of resourceIds for all possible combinations of sources . This function is called recursively to generate all possible permutations and uses the last optional parameter to pass the already resolved sources order . Any changes to this method should be copied to the ` generateResourceSetsForLocaleSync ` equivalent below .
async function* generateResourceSetsForLocale(locale, sourcesOrder, resourceIds, resolvedOrder = []) {
  const resolvedLength = resolvedOrder.length;
  const resourcesLength = resourceIds.length;
  for (const sourceName of sourcesOrder) {
    const order = resolvedOrder.concat(sourceName);
     If the combination resolved to `false` is the last
     in the resolvedOrder, we want to continue in this
     loop, but if it's somewhere in the middle, we can
     safely bail from the whole branch.
    for (let [idx, sourceName] of order.entries()) {
      const source = L10nRegistry.sources.get(sourceName);
      if (!source || source.hasFile(locale, resourceIds[idx]) === false) {
        if (idx === order.length - 1) {
          continue;
        } else {
          return;
        }
      }
    }
     If the number of resolved sources equals the number of resources,
     create the right context and return it if it loads.
    if (resolvedLength + 1 === resourcesLength) {
      let dataSet = await generateResourceSet(locale, order, resourceIds);
       Here we check again to see if the newly resolved
       resources returned `false` on any position.
      if (!dataSet.includes(false)) {
        yield dataSet;
      }
    } else if (resolvedLength < resourcesLength) {
       otherwise recursively load another generator that walks over the
       partially resolved list of sources.
      yield * generateResourceSetsForLocale(locale, sourcesOrder, resourceIds, order);
    }
  }
}
async function * generateResourceSetsForLocale ( locale , sourcesOrder , resourceIds , resolvedOrder = [ ] ) { const resolvedLength = resolvedOrder . length ; const resourcesLength = resourceIds . length ; for ( const sourceName of sourcesOrder ) { const order = resolvedOrder . concat ( sourceName ) ; for ( let [ idx , sourceName ] of order . entries ( ) ) { const source = L10nRegistry . sources . get ( sourceName ) ; if ( ! source || source . hasFile ( locale , resourceIds [ idx ] ) === false ) { if ( idx === order . length - 1 ) { continue ; } else { return ; } } } if ( resolvedLength + 1 === resourcesLength ) { let dataSet = await generateResourceSet ( locale , order , resourceIds ) ; if ( ! dataSet . includes ( false ) ) { yield dataSet ; } } else if ( resolvedLength < resourcesLength ) { yield * generateResourceSetsForLocale ( locale , sourcesOrder , resourceIds , order ) ; } } }
This function generates an iterator over FluentBundles for a single locale
 for a given list of resourceIds for all possible combinations of sources.
This function generates an iterator over FluentBundles for a single locale for a given list of resourceIds for all possible combinations of sources .
// Inside that loop we have a list of resources and the sources for them, like this: //   ['test.ftl', 'menu.ftl', 'foo.ftl'] //   ['app', 'platform', 'app'] // We want to bail out early if we know that any of // the (res)x(source) combinations in the permutation // are unavailable. // The combination may have been `undefined` when we // stepped into this branch, and now is resolved to // `false`. // // If the combination resolved to `false` is the last // in the resolvedOrder, we want to continue in this // loop, but if it's somewhere in the middle, we can // safely bail from the whole branch. // If the number of resolved sources equals the number of resources, // create the right context and return it if it loads. // Here we check again to see if the newly resolved // resources returned `false` on any position. // otherwise recursively load another generator that walks over the // partially resolved list of sources.