diff --git a/lib/Runtime/Language/JavascriptOperators.cpp b/lib/Runtime/Language/JavascriptOperators.cpp index a91a5b009d1..0078bcfe0a3 100644 --- a/lib/Runtime/Language/JavascriptOperators.cpp +++ b/lib/Runtime/Language/JavascriptOperators.cpp @@ -1075,10 +1075,9 @@ namespace Js BOOL JavascriptOperators::HasOwnProperty(Var instance, PropertyId propertyId, ScriptContext *requestContext) { - BOOL result; if (TaggedNumber::Is(instance)) { - result = false; + return FALSE; } else { @@ -1091,10 +1090,30 @@ namespace Js } else { - return object && object->HasOwnProperty(propertyId); +#ifdef DEBUG + // In debug builds, calculate expectedAnswer up-front so that + // we can Assert the fastpath gets the right result. + BOOL expectedAnswer = object && object->HasOwnProperty(propertyId); +#endif + + PropertyString *propString = requestContext->GetPropertyString(propertyId); + const PropertyCache *propCache = propString->GetPropertyCache(); + + if (object->GetType() == propCache->type) + { + // The type cached for the property was the same as the type of this object + // (i.e. obj in obj.hasOwnProperty), so we know the answer is "true". + Assert(expectedAnswer == TRUE); // sanity check on the fastpath result + return TRUE; + } + +#ifndef DEBUG + // In release builds, wait until here to calculate the result. + BOOL expectedAnswer = object && object->HasOwnProperty(propertyId); +#endif + return expectedAnswer; } } - return result; } BOOL JavascriptOperators::GetOwnAccessors(Var instance, PropertyId propertyId, Var* getter, Var* setter, ScriptContext * requestContext)