Skip to content

Commit fd50619

Browse files
committed
Fastpath for hasOwnProperty == true.
1 parent ade59a0 commit fd50619

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,9 @@ namespace Js
10751075

10761076
BOOL JavascriptOperators::HasOwnProperty(Var instance, PropertyId propertyId, ScriptContext *requestContext)
10771077
{
1078-
BOOL result;
10791078
if (TaggedNumber::Is(instance))
10801079
{
1081-
result = false;
1080+
return FALSE;
10821081
}
10831082
else
10841083
{
@@ -1091,10 +1090,30 @@ namespace Js
10911090
}
10921091
else
10931092
{
1094-
return object && object->HasOwnProperty(propertyId);
1093+
#ifdef DEBUG
1094+
// In debug builds, calculate expectedAnswer up-front so that
1095+
// we can Assert the fastpath gets the right result.
1096+
BOOL expectedAnswer = object && object->HasOwnProperty(propertyId);
1097+
#endif
1098+
1099+
PropertyString *propString = requestContext->GetPropertyString(propertyId);
1100+
const PropertyCache *propCache = propString->GetPropertyCache();
1101+
1102+
if (object->GetType() == propCache->type)
1103+
{
1104+
// The type cached for the property was the same as the type of this object
1105+
// (i.e. obj in obj.hasOwnProperty), so we know the answer is "true".
1106+
Assert(expectedAnswer == TRUE); // sanity check on the fastpath result
1107+
return TRUE;
1108+
}
1109+
1110+
#ifndef DEBUG
1111+
// In release builds, wait until here to calculate the result.
1112+
BOOL expectedAnswer = object && object->HasOwnProperty(propertyId);
1113+
#endif
1114+
return expectedAnswer;
10951115
}
10961116
}
1097-
return result;
10981117
}
10991118

11001119
BOOL JavascriptOperators::GetOwnAccessors(Var instance, PropertyId propertyId, Var* getter, Var* setter, ScriptContext * requestContext)

0 commit comments

Comments
 (0)