Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/indexeddb/IDBObjectStore.h" | 26 #include "modules/indexeddb/IDBObjectStore.h" |
| 27 | 27 |
| 28 #include <v8.h> | |
|
cmumford
2017/02/07 20:10:37
<v8.h> below I think.
| |
| 29 | |
| 30 #include <memory> | |
| 31 | |
| 28 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ScriptState.h" | 33 #include "bindings/core/v8/ScriptState.h" |
| 30 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 34 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 31 #include "bindings/modules/v8/ToV8ForModules.h" | 35 #include "bindings/modules/v8/ToV8ForModules.h" |
| 32 #include "bindings/modules/v8/V8BindingForModules.h" | 36 #include "bindings/modules/v8/V8BindingForModules.h" |
| 33 #include "core/dom/DOMStringList.h" | 37 #include "core/dom/DOMStringList.h" |
| 34 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/dom/ExecutionContext.h" | 39 #include "core/dom/ExecutionContext.h" |
| 36 #include "modules/indexeddb/IDBAny.h" | 40 #include "modules/indexeddb/IDBAny.h" |
| 37 #include "modules/indexeddb/IDBCursorWithValue.h" | 41 #include "modules/indexeddb/IDBCursorWithValue.h" |
| 38 #include "modules/indexeddb/IDBDatabase.h" | 42 #include "modules/indexeddb/IDBDatabase.h" |
| 39 #include "modules/indexeddb/IDBKeyPath.h" | 43 #include "modules/indexeddb/IDBKeyPath.h" |
| 40 #include "modules/indexeddb/IDBTracing.h" | 44 #include "modules/indexeddb/IDBTracing.h" |
| 45 #include "platform/Histogram.h" | |
| 41 #include "platform/SharedBuffer.h" | 46 #include "platform/SharedBuffer.h" |
| 42 #include "public/platform/WebBlobInfo.h" | 47 #include "public/platform/WebBlobInfo.h" |
| 43 #include "public/platform/WebData.h" | 48 #include "public/platform/WebData.h" |
| 44 #include "public/platform/WebVector.h" | 49 #include "public/platform/WebVector.h" |
| 45 #include "public/platform/modules/indexeddb/WebIDBKey.h" | 50 #include "public/platform/modules/indexeddb/WebIDBKey.h" |
| 46 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" | 51 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" |
| 47 #include <memory> | |
| 48 #include <v8.h> | |
| 49 | 52 |
| 50 using blink::WebBlobInfo; | 53 using blink::WebBlobInfo; |
| 51 using blink::WebIDBCallbacks; | 54 using blink::WebIDBCallbacks; |
| 52 using blink::WebIDBCursor; | 55 using blink::WebIDBCursor; |
| 53 using blink::WebIDBDatabase; | 56 using blink::WebIDBDatabase; |
| 54 using blink::WebVector; | 57 using blink::WebVector; |
| 55 | 58 |
| 56 namespace blink { | 59 namespace blink { |
| 57 | 60 |
| 58 namespace { | 61 namespace { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 const ScriptValue& objectValue, | 317 const ScriptValue& objectValue, |
| 315 IndexKeys* indexKeys) { | 318 IndexKeys* indexKeys) { |
| 316 DCHECK(indexKeys); | 319 DCHECK(indexKeys); |
| 317 NonThrowableExceptionState exceptionState; | 320 NonThrowableExceptionState exceptionState; |
| 318 IDBKey* indexKey = ScriptValue::to<IDBKey*>( | 321 IDBKey* indexKey = ScriptValue::to<IDBKey*>( |
| 319 isolate, objectValue, exceptionState, indexMetadata.keyPath); | 322 isolate, objectValue, exceptionState, indexMetadata.keyPath); |
| 320 | 323 |
| 321 if (!indexKey) | 324 if (!indexKey) |
| 322 return; | 325 return; |
| 323 | 326 |
| 327 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
| 328 EnumerationHistogram, keyTypeHistogram, | |
| 329 new EnumerationHistogram( | |
| 330 "WebCore.IndexedDB.ObjectStore.IndexEntry.KeyType", | |
| 331 static_cast<int>(IDBKey::TypeEnumMax))); | |
| 332 | |
| 324 if (!indexMetadata.multiEntry || indexKey->getType() != IDBKey::ArrayType) { | 333 if (!indexMetadata.multiEntry || indexKey->getType() != IDBKey::ArrayType) { |
| 325 if (!indexKey->isValid()) | 334 if (!indexKey->isValid()) |
| 326 return; | 335 return; |
| 327 | 336 |
| 328 indexKeys->push_back(indexKey); | 337 indexKeys->push_back(indexKey); |
| 338 keyTypeHistogram.count(static_cast<int>(indexKey->getType())); | |
| 329 } else { | 339 } else { |
| 330 DCHECK(indexMetadata.multiEntry); | 340 DCHECK(indexMetadata.multiEntry); |
| 331 DCHECK_EQ(indexKey->getType(), IDBKey::ArrayType); | 341 DCHECK_EQ(indexKey->getType(), IDBKey::ArrayType); |
| 332 indexKeys->appendVector(indexKey->toMultiEntryArray()); | 342 IDBKey::KeyArray array = indexKey->toMultiEntryArray(); |
| 343 for (const IDBKey* key : array) | |
| 344 keyTypeHistogram.count(static_cast<int>(key->getType())); | |
| 345 indexKeys->appendVector(array); | |
| 333 } | 346 } |
| 334 } | 347 } |
| 335 | 348 |
| 336 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, | 349 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, |
| 337 const ScriptValue& value, | 350 const ScriptValue& value, |
| 338 const ScriptValue& key, | 351 const ScriptValue& key, |
| 339 ExceptionState& exceptionState) { | 352 ExceptionState& exceptionState) { |
| 340 IDB_TRACE("IDBObjectStore::add"); | 353 IDB_TRACE("IDBObjectStore::add"); |
| 341 return put(scriptState, WebIDBPutModeAddOnly, IDBAny::create(this), value, | 354 return put(scriptState, WebIDBPutModeAddOnly, IDBAny::create(this), value, |
| 342 key, exceptionState); | 355 key, exceptionState); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } | 453 } |
| 441 | 454 |
| 442 if (!usesInLineKeys && !hasKeyGenerator && !key) { | 455 if (!usesInLineKeys && !hasKeyGenerator && !key) { |
| 443 exceptionState.throwDOMException(DataError, | 456 exceptionState.throwDOMException(DataError, |
| 444 "The object store uses out-of-line keys " | 457 "The object store uses out-of-line keys " |
| 445 "and has no key generator and the key " | 458 "and has no key generator and the key " |
| 446 "parameter was not provided."); | 459 "parameter was not provided."); |
| 447 return nullptr; | 460 return nullptr; |
| 448 } | 461 } |
| 449 if (usesInLineKeys) { | 462 if (usesInLineKeys) { |
| 450 if (clone.isEmpty()) | 463 if (clone.isEmpty()) { |
| 451 clone = | 464 clone = |
| 452 deserializeScriptValue(scriptState, serializedValue.get(), &blobInfo); | 465 deserializeScriptValue(scriptState, serializedValue.get(), &blobInfo); |
| 466 } | |
| 453 IDBKey* keyPathKey = ScriptValue::to<IDBKey*>(scriptState->isolate(), clone, | 467 IDBKey* keyPathKey = ScriptValue::to<IDBKey*>(scriptState->isolate(), clone, |
| 454 exceptionState, keyPath); | 468 exceptionState, keyPath); |
| 455 if (exceptionState.hadException()) | 469 if (exceptionState.hadException()) |
| 456 return nullptr; | 470 return nullptr; |
| 457 if (keyPathKey && !keyPathKey->isValid()) { | 471 if (keyPathKey && !keyPathKey->isValid()) { |
| 458 exceptionState.throwDOMException(DataError, | 472 exceptionState.throwDOMException(DataError, |
| 459 "Evaluating the object store's key path " | 473 "Evaluating the object store's key path " |
| 460 "yielded a value that is not a valid " | 474 "yielded a value that is not a valid " |
| 461 "key."); | 475 "key."); |
| 462 return nullptr; | 476 return nullptr; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 483 IDBDatabase::notValidKeyErrorMessage); | 497 IDBDatabase::notValidKeyErrorMessage); |
| 484 return nullptr; | 498 return nullptr; |
| 485 } | 499 } |
| 486 | 500 |
| 487 if (!backendDB()) { | 501 if (!backendDB()) { |
| 488 exceptionState.throwDOMException(InvalidStateError, | 502 exceptionState.throwDOMException(InvalidStateError, |
| 489 IDBDatabase::databaseClosedErrorMessage); | 503 IDBDatabase::databaseClosedErrorMessage); |
| 490 return nullptr; | 504 return nullptr; |
| 491 } | 505 } |
| 492 | 506 |
| 507 if (key && usesInLineKeys) { | |
| 508 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
| 509 EnumerationHistogram, keyTypeHistogram, | |
| 510 new EnumerationHistogram("WebCore.IndexedDB.ObjectStore.Record.KeyType", | |
| 511 static_cast<int>(IDBKey::TypeEnumMax))); | |
| 512 keyTypeHistogram.count(static_cast<int>(key->getType())); | |
| 513 } | |
| 514 | |
| 493 Vector<int64_t> indexIds; | 515 Vector<int64_t> indexIds; |
| 494 HeapVector<IndexKeys> indexKeys; | 516 HeapVector<IndexKeys> indexKeys; |
| 495 for (const auto& it : metadata().indexes) { | 517 for (const auto& it : metadata().indexes) { |
| 496 if (clone.isEmpty()) | 518 if (clone.isEmpty()) { |
| 497 clone = | 519 clone = |
| 498 deserializeScriptValue(scriptState, serializedValue.get(), &blobInfo); | 520 deserializeScriptValue(scriptState, serializedValue.get(), &blobInfo); |
| 521 } | |
| 499 IndexKeys keys; | 522 IndexKeys keys; |
| 500 generateIndexKeysForValue(scriptState->isolate(), *it.value, clone, &keys); | 523 generateIndexKeysForValue(scriptState->isolate(), *it.value, clone, &keys); |
| 501 indexIds.push_back(it.key); | 524 indexIds.push_back(it.key); |
| 502 indexKeys.push_back(keys); | 525 indexKeys.push_back(keys); |
| 503 } | 526 } |
| 504 | 527 |
| 505 IDBRequest* request = | 528 IDBRequest* request = |
| 506 IDBRequest::create(scriptState, source, m_transaction.get()); | 529 IDBRequest::create(scriptState, source, m_transaction.get()); |
| 507 Vector<char> wireBytes; | 530 Vector<char> wireBytes; |
| 508 serializedValue->toWireBytes(wireBytes); | 531 serializedValue->toWireBytes(wireBytes); |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1088 } | 1111 } |
| 1089 } | 1112 } |
| 1090 return IDBIndexMetadata::InvalidId; | 1113 return IDBIndexMetadata::InvalidId; |
| 1091 } | 1114 } |
| 1092 | 1115 |
| 1093 WebIDBDatabase* IDBObjectStore::backendDB() const { | 1116 WebIDBDatabase* IDBObjectStore::backendDB() const { |
| 1094 return m_transaction->backendDB(); | 1117 return m_transaction->backendDB(); |
| 1095 } | 1118 } |
| 1096 | 1119 |
| 1097 } // namespace blink | 1120 } // namespace blink |
| OLD | NEW |