'Resolves a variable type string to a JSObject representing a well-
known JavaScript type
@param varType {str} The type to look up as a dot-separated string, e.g.
"Foo.Bar.baz" or "Array"
@param jsobject {JSObject} The starting JSObject candidate (in case
varType is well-known)
@param scopeStack {list} The scope stack, with the outermost (and
therefore last searched) scope at the lowest index
@param depth {int} (For internal use to prevent deep recursion)
@returns {JSObject or None} The variable type, or None'

def _lookupVariableType(self, varType, jsobject, scopeStack, depth=0):

    assert ((not varType) or isinstance(varType, (str, unicode))), ('varType    %r    is    not    a    string' % varType)
    if ((depth < 10) and varType):
        if (varType.lower() in known_javascript_types):
            return jsobject
        sp = varType.split('.')
        namePos = 0
        while (namePos < len(sp)):
            name = sp[namePos]
            foundScope = self._findScopeWithName(name, scopeStack, type='variables')
            alternateScopeStack = scopeStack
            while (foundScope and isinstance(foundScope, JSArgument) and (not foundScope.type) and (foundScope.parent in alternateScopeStack)):
                log.debug('found    untyped    argument    %r    on    %r,    trying    next', foundScope.name, foundScope.parent.name)
                alternateScopeStack[alternateScopeStack.index(foundScope.parent):] = []
                foundScope = self._findScopeWithName(name, alternateScopeStack, type='variables')
            if (not foundScope):
                foundScope = self._findScopeWithName(name, scopeStack, type='members')
            if (not foundScope):
                foundScope = self._findScopeWithName(name, scopeStack, type='classes')
                if foundScope:
                    scopeStack.append(foundScope)
            if (not foundScope):
                break
            if isinstance(foundScope, JSVariable):
                assert ((foundScope.type is None) or isinstance(foundScope.type, (str, unicode))), ('foundScope    %r    has    invalid    type    %r' % (foundScope, foundScope.type))
                foundScope = self._lookupVariableType(foundScope.type, foundScope, scopeStack, (depth + 1))
            namePos += 1
        return foundScope
    return None
