anchor.diff:    String assembleProgram() {
       measure(() {
         computeNeededClasses();
  +
  +      // Compute the required type checks to know which classes need a
  +      // 'is$' method.
  +      computeRequiredTypeChecks();
  +
         mainBuffer.add(GENERATED_BY);
         addComment(HOOKS_API_USAGE, mainBuffer);
         mainBuffer.add('function ${namer.isolateName}()$_{}\n');
         mainBuffer.add('init()$N$n');
  -      // Shorten the code by using "$$" as temporary.
  -      classesCollector = r"$$";
  -      mainBuffer.add('var $classesCollector$_=$_{}$N');
         // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary.
         isolateProperties = namer.CURRENT_ISOLATE;
         mainBuffer.add(
             'var $isolateProperties$_=$_$isolatePropertiesName$N');
  -      emitClasses(mainBuffer);
  -      mainBuffer.add(boundClosureBuffer);
  -      // Clear the buffer, so that we can reuse it for the native classes.
  -      boundClosureBuffer.clear();
  +
  +      if (!regularClasses.isEmpty ||
  +          !deferredClasses.isEmpty ||
  +          !nativeClasses.isEmpty) {
  +        // Shorten the code by using "$$" as temporary.
  +        classesCollector = r"$$";
  +        mainBuffer.add('var $classesCollector$_=$_{}$N$n');
  +      }
  +
  +      // Emit native classes on [nativeBuffer].  As a side-effect,
  +      // this will produce "bound closures" in [boundClosures].  The
  +      // bound closures are JS AST nodes that add properties to $$
  +      // [classesCollector].  The bound closures are not emitted until
  +      // we have emitted all other classes (native or not).
  +      final CodeBuffer nativeBuffer = new CodeBuffer();
  +      if (!nativeClasses.isEmpty) {
  +        addComment('Native classes', nativeBuffer);
  +        for (ClassElement element in nativeClasses) {
  +          nativeEmitter.generateNativeClass(element);
  +        }
  +        nativeEmitter.assembleCode(nativeBuffer);
  +      }
  +
  +      // Might also create boundClosures.
  +      if (!regularClasses.isEmpty) {
  +        addComment('Classes', mainBuffer);
  +        for (ClassElement element in regularClasses) {
  +          generateClass(element, mainBuffer);
  +        }
  +      }
  +
  +      // Might also create boundClosures.
  +      if (!deferredClasses.isEmpty) {
  +        emitDeferredPreambleWhenEmpty(deferredBuffer);
  +        deferredBuffer.add('\$\$$_=$_{}$N');
  +
  +        for (ClassElement element in deferredClasses) {
  +          generateClass(element, deferredBuffer);
  +        }
  +
  +        deferredBuffer.add('$finishClassesName(\$\$,'
  +                           '$_${namer.CURRENT_ISOLATE},'
  +                           '$_$isolatePropertiesName)$N');
  +        // Reset the map.
  +        deferredBuffer.add("\$\$$_=${_}null$N$n");
  +      }
  +
  +      emitClosureClassIfNeeded(mainBuffer);
  +
  +      // Now that we have emitted all classes, we know all the bound
  +      // closures that will be needed.
  +      for (jsAst.Node node in boundClosures) {
  +        // TODO(ahe): Some of these can be deferred.
  +        mainBuffer.add(jsAst.prettyPrint(node, compiler));
  +        mainBuffer.add("$N$n");
  +      }
  +
  +      emitFinishClassesInvocationIfNecessary(mainBuffer);
  +
  +      // After this assignment we will produce invalid JavaScript code if we use
  +      // the classesCollector variable.
  +      classesCollector = 'classesCollector should not be used from now on';
  +
         emitStaticFunctions(mainBuffer);
         emitStaticFunctionGetters(mainBuffer);
  -      // We need to finish the classes before we construct compile time
  -      // constants.
  -      emitFinishClassesInvocationIfNecessary(mainBuffer);
  +
         emitRuntimeTypeSupport(mainBuffer);
         emitCompileTimeConstants(mainBuffer);
         // Static field initializations require the classes and compile-time
  
positive.code:   }
  
    CodeEmitterTask(Compiler compiler, Namer namer, this.generateSourceMap)
        : boundClosureBuffer = new CodeBuffer(),
          mainBuffer = new CodeBuffer(),
          this.namer = namer,
          boundClosureCache = new Map<int, String>(),
          interceptorClosureCache = new Map<int, String>(),
  
negative.code:         boundClosureBuilder.addProperty(operator, new jsAst.LiteralBool(true));
        });
  
        boundClosures.add(
            js[classesCollector][mangledName].assign(
                boundClosureBuilder.toObjectInitializer()));
  
        closureClass = namer.isolateAccess(closureClassElement);
  
  