Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Unified Diff: Source/WebCore/bindings/v8/IDBBindingUtilities.cpp

Issue 11348011: Revert 128789 - IndexedDB: Use ScriptValue instead of SerializedScriptValue for get/openCursor (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1271/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/WebCore/bindings/v8/IDBBindingUtilities.cpp
===================================================================
--- Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (revision 132816)
+++ Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (working copy)
@@ -209,6 +209,25 @@
return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string());
}
+static PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> prpValue, const String& keyPath)
+{
+ Vector<String> keyPathElements;
+ IDBKeyPathParseError error;
+ IDBParseKeyPath(keyPath, keyPathElements, error);
+ ASSERT(error == IDBKeyPathParseErrorNone);
+
+ RefPtr<SerializedScriptValue> value = prpValue;
+
+ v8::HandleScope handleScope;
+ v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext());
+
+ v8::Handle<v8::Value> v8Value(value->deserialize());
+ v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size()));
+ if (v8Key.IsEmpty())
+ return 0;
+ return createIDBKeyFromValue(v8Key);
+}
+
// FIXME: The only reason this exists is because we need a v8::Context and scope inside a timer. Is there a better / more general way to do this?
ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPtr<SerializedScriptValue> prpValue)
{
@@ -217,11 +236,34 @@
return ScriptValue(prpValue->deserialize());
}
-bool injectIDBKeyIntoScriptValue(PassRefPtr<IDBKey> key, ScriptValue& value, const IDBKeyPath& keyPath)
+PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> prpValue, const IDBKeyPath& keyPath)
{
- IDB_TRACE("injectIDBKeyIntoScriptValue");
+ IDB_TRACE("createIDBKeyFromSerializedValueAndKeyPath");
+ ASSERT(!keyPath.isNull());
+ RefPtr<SerializedScriptValue> value = prpValue;
+
+ if (keyPath.type() == IDBKeyPath::ArrayType) {
+ IDBKey::KeyArray result;
+ const Vector<String>& array = keyPath.array();
+ for (size_t i = 0; i < array.size(); ++i) {
+ RefPtr<IDBKey> key = createIDBKeyFromSerializedValueAndKeyPath(value, array[i]);
+ if (!key)
+ return 0;
+ result.append(key);
+ }
+ return IDBKey::createArray(result);
+ }
+
ASSERT(keyPath.type() == IDBKeyPath::StringType);
+ return createIDBKeyFromSerializedValueAndKeyPath(value, keyPath.string());
+}
+
+PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDBKey> key, PassRefPtr<SerializedScriptValue> value, const IDBKeyPath& keyPath)
+{
+ IDB_TRACE("injectIDBKeyIntoSerializedValue");
+
+ ASSERT(keyPath.type() == IDBKeyPath::StringType);
Vector<String> keyPathElements;
IDBKeyPathParseError error;
IDBParseKeyPath(keyPath.string(), keyPathElements, error);
@@ -233,15 +275,15 @@
v8::HandleScope handleScope;
v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext());
- v8::Handle<v8::Value> v8Value(value.v8Value());
+ v8::Handle<v8::Value> v8Value(value->deserialize());
v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1));
if (parent.IsEmpty())
- return false;
+ return 0;
if (!set(parent, keyPathElements.last(), toV8(key.get())))
- return false;
+ return 0;
- return true;
+ return SerializedScriptValue::create(v8Value);
}
bool canInjectIDBKeyIntoScriptValue(const ScriptValue& scriptValue, const IDBKeyPath& keyPath)
« no previous file with comments | « Source/WebCore/bindings/v8/IDBBindingUtilities.h ('k') | Source/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698