code: function getActiveRange() {
  	var ret;
  	if (globalRange) {
  		ret = globalRange;
  	} else if (getSelection().rangeCount) {
  		ret = getSelection().getRangeAt(0);
  	} else {
  		return null;
  	}
  	if ([Node.TEXT_NODE, Node.ELEMENT_NODE].indexOf(ret.startContainer.nodeType) == -1
  	|| [Node.TEXT_NODE, Node.ELEMENT_NODE].indexOf(ret.endContainer.nodeType) == -1
  	|| !ret.startContainer.ownerDocument
  	|| !ret.endContainer.ownerDocument
  	|| !isDescendant(ret.startContainer, ret.startContainer.ownerDocument)
  	|| !isDescendant(ret.endContainer, ret.endContainer.ownerDocument)) {
  		throw "Invalid active range; test bug?";
  	}
  	return ret;
  }
docs: "The active range is the range of the selection given by calling getSelection() on the context object. (Thus the active range may be null.)"  We cheat and return globalRange if that's defined.  We also ensure that the active range meets the requirements that selection boundary points are supposed to meet, i.e., that the nodes are both Text or Element nodes that descend from a Document.