src/com/google/javascript/jscomp/FunctionInjector.java
/**
   * @param fnNode The function to evaluate for inlining.
   * @param needAliases A set of function parameter names that can not be
   *     used without aliasing. Returned by getUnsafeParameterNames().
   * @param referencesThis Whether fnNode contains references to its this
   *     object.
   * @param containsFunctions Whether fnNode contains inner functions.
   * @return Whether the inlining can occur.
   */
@param fnNode The function to evaluate for inlining.
@param needAliases A set of function parameter names that can not be
used without aliasing.
@param fnNode The function to evaluate for inlining . @param needAliases A set of function parameter names that can not be used without aliasing .
CanInlineResult canInlineReferenceToFunction(
      Reference ref, Node fnNode, ImmutableSet<String> needAliases,
      boolean referencesThis, boolean containsFunctions) {
    Node callNode = ref.callNode;
    if (!isSupportedCallType(callNode)) {
      return CanInlineResult.NO;
    }
    if (hasSpreadCallArgument(callNode)) {
      return CanInlineResult.NO;
    }
    if (containsFunctions) {
      if (!assumeMinimumCapture && !ref.scope.isGlobal()) {
        return CanInlineResult.NO;
      } else if (NodeUtil.isWithinLoop(callNode)) {
        return CanInlineResult.NO;
      }
    }
    if (referencesThis && !NodeUtil.isFunctionObjectCall(callNode)) {
      return CanInlineResult.NO;
    }
    if (ref.mode == InliningMode.DIRECT) {
      return canInlineReferenceDirectly(ref, fnNode, needAliases);
    } else {
      return canInlineReferenceAsStatementBlock(ref, fnNode, needAliases);
    }
  }
CanInlineResult canInlineReferenceToFunction ( Reference ref , Node fnNode , ImmutableSet < String > needAliases , boolean referencesThis , boolean containsFunctions ) { Node callNode = ref . callNode ; if ( ! isSupportedCallType ( callNode ) ) { return CanInlineResult . NO ; } if ( hasSpreadCallArgument ( callNode ) ) { return CanInlineResult . NO ; } if ( containsFunctions ) { if ( ! assumeMinimumCapture && ! ref . scope . isGlobal ( ) ) { return CanInlineResult . NO ; } else if ( NodeUtil . isWithinLoop ( callNode ) ) { return CanInlineResult . NO ; } } if ( referencesThis && ! NodeUtil . isFunctionObjectCall ( callNode ) ) { return CanInlineResult . NO ; } if ( ref . mode == InliningMode . DIRECT ) { return canInlineReferenceDirectly ( ref , fnNode , needAliases ) ; } else { return canInlineReferenceAsStatementBlock ( ref , fnNode , needAliases ) ; } }
@param fnNode The function to evaluate for inlining.
@param fnNode The function to evaluate for inlining .
// TODO(johnlenz): This function takes too many parameter, without // context.  Modify the API to take a structure describing the function. // Allow direct function calls or "fn.call" style calls. // Limit where functions that contain functions can be inline.  Introducing // an inner function into another function can capture a variable and cause // a memory leak.  This isn't a problem in the global scope as those values // last until explicitly cleared. // TODO(johnlenz): Allow inlining into any scope without local names or inner functions. // An inner closure maybe relying on a local value holding a value for a // single iteration through a loop. // TODO(johnlenz): Add support for 'apply' // TODO(johnlenz): Allow 'this' references to be replaced with a // global 'this' object.