diff --git a/js2/src/bytecodegen.cpp b/js2/src/bytecodegen.cpp index 9495be7f2b32..aff82b994c90 100644 --- a/js2/src/bytecodegen.cpp +++ b/js2/src/bytecodegen.cpp @@ -1991,7 +1991,11 @@ BinaryOpEquals: case ExprNode::This: { JSFunction *f = mScopeChain->getContainerFunction(); - JSType *theClass = mScopeChain->topClass(); + JSType *theClass; + if (f) + theClass = f->getClass(); + else + theClass = mScopeChain->topClass(); // 'this' is legal in prototype functions // and at the script top-level if ( ((f == NULL) && theClass) diff --git a/js2/src/js2runtime.cpp b/js2/src/js2runtime.cpp index 02622d921858..fb39ecfce4d5 100644 --- a/js2/src/js2runtime.cpp +++ b/js2/src/js2runtime.cpp @@ -698,19 +698,22 @@ Reference *ParameterBarrel::genReference(bool /* hasBase */, const String& name, JSType *ScopeChain::findType(const StringAtom& typeName, size_t pos) { JSValue v = getCompileTimeValue(typeName, NULL); - if (v.isType()) - return v.type; - else { - // Allow finding a function that has the same name as it's containing class - // i.e. the default constructor. - FunctionName *fnName = v.function->getFunctionName(); - if ((fnName->prefix == FunctionName::normal) - && v.isFunction() && v.function->getClass() - && (v.function->getClass()->mClassName->compare(*fnName->name) == 0)) - return v.function->getClass(); - m_cx->reportError(Exception::semanticError, "Unknown type", pos); - return NULL; - } + if (!v.isUndefined()) { + if (v.isType()) + return v.type; + else { + // Allow finding a function that has the same name as it's containing class + // i.e. the default constructor. + FunctionName *fnName = v.function->getFunctionName(); + if ((fnName->prefix == FunctionName::normal) + && v.isFunction() && v.function->getClass() + && (v.function->getClass()->mClassName->compare(*fnName->name) == 0)) + return v.function->getClass(); + m_cx->reportError(Exception::semanticError, "Unknown type", pos); + return NULL; + } + } + return NULL; } // Take the specified type in 't' and see if we have a compile-time