Bug 1577107 - Avoid following the prototype chain r=janv

With this commit we no longer follow the value's prototype chain when
creating index updates in IndexedDB.

Differential Revision: https://phabricator.services.mozilla.com/D44438

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Yaron Tausky 2019-09-13 09:35:09 +00:00
Родитель c9b081d8c9
Коммит b9add81961
1 изменённых файлов: 27 добавлений и 3 удалений

Просмотреть файл

@ -923,6 +923,9 @@ void IDBObjectStore::AppendIndexUpdateInfo(
const int64_t aIndexID, const KeyPath& aKeyPath, const bool aMultiEntry,
const nsCString& aLocale, JSContext* const aCx, JS::Handle<JS::Value> aVal,
nsTArray<IndexUpdateInfo>* const aUpdateInfoArray, ErrorResult* const aRv) {
// This precondition holds when `aVal` is the result of a structured clone.
js::AutoAssertNoContentJS noContentJS(aCx);
if (!aMultiEntry) {
Key key;
*aRv = aKeyPath.ExtractKey(aCx, aVal, key);
@ -948,7 +951,7 @@ void IDBObjectStore::AppendIndexUpdateInfo(
}
bool isArray;
if (!JS_IsArrayObject(aCx, val, &isArray)) {
if (NS_WARN_IF(!JS_IsArrayObject(aCx, val, &isArray))) {
IDB_REPORT_INTERNAL_ERR();
aRv->Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
@ -963,8 +966,27 @@ void IDBObjectStore::AppendIndexUpdateInfo(
}
for (uint32_t arrayIndex = 0; arrayIndex < arrayLength; arrayIndex++) {
JS::Rooted<JS::Value> arrayItem(aCx);
if (NS_WARN_IF(!JS_GetElement(aCx, array, arrayIndex, &arrayItem))) {
JS::RootedId indexId(aCx);
if (NS_WARN_IF(!JS_IndexToId(aCx, arrayIndex, &indexId))) {
IDB_REPORT_INTERNAL_ERR();
aRv->Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
}
bool hasOwnProperty;
if (NS_WARN_IF(
!JS_HasOwnPropertyById(aCx, array, indexId, &hasOwnProperty))) {
IDB_REPORT_INTERNAL_ERR();
aRv->Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
}
if (!hasOwnProperty) {
continue;
}
JS::RootedValue arrayItem(aCx);
if (NS_WARN_IF(!JS_GetPropertyById(aCx, array, indexId, &arrayItem))) {
IDB_REPORT_INTERNAL_ERR();
aRv->Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
@ -1419,6 +1441,8 @@ void IDBObjectStore::GetAddInfo(JSContext* aCx, ValueWrapper& aValueWrapper,
return;
}
js::AutoAssertNoContentJS noContentJS(aCx);
{
const nsTArray<IndexMetadata>& indexes = mSpec->indexes();
uint32_t idxCount = indexes.Length();