Skip to content

Commit a64343f

Browse files
committed
don't look up numeric properties from cache in json code
1 parent 32a33ae commit a64343f

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

lib/Runtime/Library/JSONStringifier.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,31 @@ _Ret_notnull_ Var
221221
JSONStringifier::ReadValue(_In_ JavascriptString* key, _In_opt_ const PropertyRecord* propertyRecord, _In_ RecyclableObject* holder)
222222
{
223223
Var value = nullptr;
224-
PropertyString* propertyString = JavascriptOperators::TryFromVar<PropertyString>(key);
225224
PropertyValueInfo info;
226-
if (propertyString != nullptr)
227-
{
228-
PropertyValueInfo::SetCacheInfo(&info, propertyString, propertyString->GetLdElemInlineCache(), false);
229-
if (propertyString->TryGetPropertyFromCache<false /* ownPropertyOnly */, false /* OutputExistence */>(holder, holder, &value, this->scriptContext, &info))
230-
{
231-
return value;
232-
}
233-
}
234225

235226
if (propertyRecord == nullptr)
236227
{
237228
key->GetPropertyRecord(&propertyRecord);
238229
}
239-
JavascriptOperators::GetProperty(holder, propertyRecord->GetPropertyId(), &value, this->scriptContext, &info);
230+
231+
if (propertyRecord->IsNumeric())
232+
{
233+
JavascriptOperators::GetItem(holder, propertyRecord->GetNumericValue(), &value, this->scriptContext);
234+
}
235+
else
236+
{
237+
PropertyString* propertyString = JavascriptOperators::TryFromVar<PropertyString>(key);
238+
if (propertyString != nullptr)
239+
{
240+
PropertyValueInfo::SetCacheInfo(&info, propertyString, propertyString->GetLdElemInlineCache(), false);
241+
if (propertyString->TryGetPropertyFromCache<false /* ownPropertyOnly */, false /* OutputExistence */>(holder, holder, &value, this->scriptContext, &info))
242+
{
243+
return value;
244+
}
245+
}
246+
JavascriptOperators::GetProperty(holder, propertyRecord->GetPropertyId(), &value, this->scriptContext, &info);
247+
}
248+
240249
return value;
241250
}
242251

test/JSON/cacheassert.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
JSON.stringify({}, [0]);
7+
JSON.stringify({0: {}}, [0]);
8+
9+
print("Pass")

test/JSON/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<tags>exclude_jenkins</tags>
1515
</default>
1616
</test>
17+
<test>
18+
<default>
19+
<files>cacheassert.js</files>
20+
</default>
21+
</test>
1722
<test>
1823
<default>
1924
<files>stringify-replacer.js</files>

0 commit comments

Comments
 (0)