Chromium Code Reviews| 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)); | |
|
haraken
2016/07/20 16:22:12
Use CreateDataProperty instead of Set. If the sett
palakj1
2016/07/20 18:22:11
Is using CreateDataProperty on map identical to Se
jsbell
2016/07/20 18:41:48
CreateDataProperty is definitely not correct here;
haraken
2016/07/20 19:02:14
Thanks for the clarification! Yeah, I realized tha
adamk
2016/07/20 19:04:04
jsbell's reading of the code is correct: v8::Map::
| |
| 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 for (const auto& idx : observationIndex) | |
| 45 m_records.add(observations[idx].objectStoreId, HeapVector<Member<IDBObse rvation>>()).storedValue->value.append(IDBObservation::create(observations[idx]) ); | |
| 30 } | 46 } |
| 31 | 47 |
| 32 DEFINE_TRACE(IDBObserverChanges) | 48 DEFINE_TRACE(IDBObserverChanges) |
| 33 { | 49 { |
| 34 visitor->trace(m_database); | 50 visitor->trace(m_database); |
| 35 visitor->trace(m_transaction); | 51 visitor->trace(m_transaction); |
| 36 visitor->trace(m_records); | 52 visitor->trace(m_records); |
| 37 } | 53 } |
| 38 | 54 |
| 39 } // namespace blink | 55 } // namespace blink |
| OLD | NEW |