OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/indexeddb/IDBObserverChanges.h" | 5 #include "modules/indexeddb/IDBObserverChanges.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8Binding.h" |
9 #include "bindings/modules/v8/ToV8ForModules.h" | 10 #include "bindings/modules/v8/ToV8ForModules.h" |
10 #include "bindings/modules/v8/V8BindingForModules.h" | 11 #include "bindings/modules/v8/V8BindingForModules.h" |
11 #include "modules/indexeddb/IDBAny.h" | 12 #include "modules/indexeddb/IDBAny.h" |
| 13 #include "modules/indexeddb/IDBObservation.h" |
| 14 #include "public/platform/modules/indexeddb/WebIDBObservation.h" |
12 | 15 |
13 namespace blink { | 16 namespace blink { |
14 | 17 |
15 ScriptValue IDBObserverChanges::records(ScriptState* scriptState) | 18 ScriptValue IDBObserverChanges::records(ScriptState* scriptState) |
16 { | 19 { |
17 return ScriptValue::from(scriptState, m_records); | 20 v8::Local<v8::Context> context(scriptState->context()); |
| 21 v8::Isolate* isolate(scriptState->isolate()); |
| 22 v8::Local<v8::Map> map = v8::Map::New(isolate); |
| 23 for (const auto& it : m_records) { |
| 24 v8::Local<v8::String> key = v8String(isolate, m_database->getObjectStore
Name(it.key)); |
| 25 v8::Local<v8::Value> value = toV8(it.value, context->Global(), isolate); |
| 26 v8CallOrCrash(map->Set(context, key, value)); |
| 27 } |
| 28 return ScriptValue::from(scriptState, map); |
18 } | 29 } |
19 | 30 |
20 IDBObserverChanges* IDBObserverChanges::create(IDBDatabase* database, IDBTransac
tion* transaction, IDBAny* records) | 31 IDBObserverChanges* IDBObserverChanges::create(IDBDatabase* database, const WebV
ector<WebIDBObservation>& observations, const WebVector<int32_t>& observationInd
ex) |
21 { | 32 { |
22 return new IDBObserverChanges(database, transaction, records); | 33 return new IDBObserverChanges(database, observations, observationIndex); |
23 } | 34 } |
24 | 35 |
25 IDBObserverChanges::IDBObserverChanges(IDBDatabase* database, IDBTransaction* tr
ansaction, IDBAny* records) | 36 IDBObserverChanges::IDBObserverChanges(IDBDatabase* database, const WebVector<We
bIDBObservation>& observations, const WebVector<int32_t>& observationIndex) |
26 : m_database(database) | 37 : m_database(database) |
27 , m_transaction(transaction) | |
28 , m_records(records) | |
29 { | 38 { |
| 39 extractChanges(observations, observationIndex); |
| 40 } |
| 41 |
| 42 void IDBObserverChanges::extractChanges(const WebVector<WebIDBObservation>& obse
rvations, const WebVector<int32_t>& observationIndex) |
| 43 { |
| 44 // TODO(dmurph): Avoid getting and setting repeated times. |
| 45 for (const auto& idx : observationIndex) |
| 46 m_records.add(observations[idx].objectStoreId, HeapVector<Member<IDBObse
rvation>>()).storedValue->value.append(IDBObservation::create(observations[idx])
); |
30 } | 47 } |
31 | 48 |
32 DEFINE_TRACE(IDBObserverChanges) | 49 DEFINE_TRACE(IDBObserverChanges) |
33 { | 50 { |
34 visitor->trace(m_database); | 51 visitor->trace(m_database); |
35 visitor->trace(m_transaction); | 52 visitor->trace(m_transaction); |
36 visitor->trace(m_records); | 53 visitor->trace(m_records); |
37 } | 54 } |
38 | 55 |
39 } // namespace blink | 56 } // namespace blink |
OLD | NEW |