src/third_party/mozjs/extract/intl/l10n/L10nRegistry.jsm
/**
 * This is a synchronous version of the `generateResourceSetsForLocale`
 * method and should stay completely in sync with it at all
 * times except of the async/await changes.
 *
 * @param {String} locale
 * @param {Array} sourcesOrder
 * @param {Array} resourceIds
 * @param {Array} [resolvedOrder]
 * @returns {Iterator<FluentBundle>}
 */
This is a synchronous version of the `generateResourceSetsForLocale`
method and should stay completely in sync with it at all
times except of the async/await changes.


This is a synchronous version of the ` generateResourceSetsForLocale ` method and should stay completely in sync with it at all times except of the async / await changes .
function* generateResourceSetsForLocaleSync(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 = generateResourceSetSync(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 * generateResourceSetsForLocaleSync(locale, sourcesOrder, resourceIds, order);
    }
  }
}
function * generateResourceSetsForLocaleSync ( 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 = generateResourceSetSync ( locale , order , resourceIds ) ; if ( ! dataSet . includes ( false ) ) { yield dataSet ; } } else if ( resolvedLength < resourcesLength ) { yield * generateResourceSetsForLocaleSync ( locale , sourcesOrder , resourceIds , order ) ; } } }
This is a synchronous version of the `generateResourceSetsForLocale`
 method and should stay completely in sync with it at all
 times except of the async/await changes.
This is a synchronous version of the ` generateResourceSetsForLocale ` method and should stay completely in sync with it at all times except of the async / await changes .
// 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.