docs: function MultiWindowRPCOptimizingEngine(newFrameName, newDelegateEngine) {
  // private
      var NO_RESULT = '__NO_NODE_RESULT';
  
      var frameName = newFrameName;
      var engine = newDelegateEngine || new JavascriptXPathEngine();
      var optimizer = new XPathOptimizer(engine);
  
      function createTestDocument() {
          if (! window.frames[frameName]) {
              var iframe = document.createElement('iframe');
  
              iframe.id = frameName;
              iframe.name = frameName;
              iframe.width = 0;
              iframe.height = 0;
  
              document.body.appendChild(iframe);
          }
      }
  
      function isMultiWindowMode() {
          return (typeof(runOptions) != 'undefined' &&
              runOptions &&
              runOptions.isMultiWindowMode());
      };
  
      /**
       * Returns whether a node is detached from any live documents. Detached
       * nodes should be considered invalidated and evicted from any caches.
       */
      function isDetached(node) {
          while (node = node.parentNode) {
              if (node.nodeType == 11) {
                  // it's a document fragment; we're detached (IE)
                  return true;
              }
              else if (node.nodeType == 9) {
                  // it's a normal document; we're attached
                  return false;
              }
          }
  
          // we didn't find a document; we're detached (most other browsers)
          return true;
      }
  
  // public
      // Override
      this.isAvailable = function() {
          // though currently it only makes sense to use this engine for IE, we
          // do not impose that restriction here.
          return engine.isAvailable();
      };
  
      // Override
      this.setDocument = function(newDocument) {
          this.doc = newDocument;
          engine.setDocument(newDocument);
          optimizer.setDocument(newDocument);
          return this;
      };
  
      /**
       * No optimization performed for multi-node selections. This is because the
       * optimizer only works for single node results.
       */
      // Override
      this.selectNodes = function(xpath, contextNode, namespaceResolver) {
          return engine.selectNodes(xpath, contextNode, namespaceResolver);
      };
  
      // Override
      this.selectSingleNode = function(xpath, contextNode, namespaceResolver) {
          var html = this.doc.documentElement.innerHTML;
          var knownOptimizations = optimizer.getKnownOptimizations();
          var optimization = knownOptimizations.get(html, xpath);
  
          if (optimization) {
              var node = optimization.node;
              var sourceIndex = optimization.sourceIndex;
  
              if (node == NO_RESULT) {
                  return null;
              }
  
              // node is still valid? (test ok even if sourceIndex is null)
              if (! isDetached(node) && node.sourceIndex == sourceIndex) {
                  safe_log('info', 'Found cached node for ' + xpath);
                  return node;
              }
          }
  
          var node;
          var finder = optimizer.setNamespaceResolver(namespaceResolver)
              .setTestDocument(this.getTestDocument())
              .getOptimizedFinder(xpath, contextNode);
  
          if (finder) {
              node = finder(this.doc);
          }
          else {
              node = engine.selectSingleNode(xpath, contextNode,
                  namespaceResolver);
          }
  
          if (! optimization) {
              optimization = knownOptimizations.getOrCreate(html, xpath);
          }
  
          if (node) {
              optimization.node = node;
              optimization.sourceIndex = node.sourceIndex;
          }
          else {
              optimization.node = NO_RESULT;
          }
  
          return node;
      };
  
      // Override
      this.countNodes = function(xpath, contextNode, namespaceResolver) {
          return optimizer.setNamespaceResolver(namespaceResolver)
              .setTestDocument(this.getTestDocument())
              .countNodes(xpath, contextNode);
      };
  
      // Override
      this.setIgnoreAttributesWithoutValue = function(ignore) {
          engine.setIgnoreAttributesWithoutValue(ignore);
          return this;
      };
  
      /**
       * Returns the "local" document as a frame in the Selenium runner document.
       */
      this.getTestDocument = function() {
          // made this a public method, because apparently private methods can't
          // access "this" of the instance.
          return (isMultiWindowMode()
              ? window.frames[frameName].document
              : this.doc);
      };
  
  // initialization
  
      // creating the frame and the document it contains is not a synchronous
      // operation (at least not for IE), so we should create it eagerly
      if (isMultiWindowMode()) {
          createTestDocument();
      }
  }