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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return 0; 202 return 0;
203 result.append(key); 203 result.append(key);
204 } 204 }
205 return IDBKey::createArray(result); 205 return IDBKey::createArray(result);
206 } 206 }
207 207
208 ASSERT(keyPath.type() == IDBKeyPath::StringType); 208 ASSERT(keyPath.type() == IDBKeyPath::StringType);
209 return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string()); 209 return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string());
210 } 210 }
211 211
212 static PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<S erializedScriptValue> prpValue, const String& keyPath)
213 {
214 Vector<String> keyPathElements;
215 IDBKeyPathParseError error;
216 IDBParseKeyPath(keyPath, keyPathElements, error);
217 ASSERT(error == IDBKeyPathParseErrorNone);
218
219 RefPtr<SerializedScriptValue> value = prpValue;
220
221 v8::HandleScope handleScope;
222 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext ());
223
224 v8::Handle<v8::Value> v8Value(value->deserialize());
225 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, k eyPathElements.size()));
226 if (v8Key.IsEmpty())
227 return 0;
228 return createIDBKeyFromValue(v8Key);
229 }
230
212 // 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? 231 // 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?
213 ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPt r<SerializedScriptValue> prpValue) 232 ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPt r<SerializedScriptValue> prpValue)
214 { 233 {
215 v8::HandleScope handleScope; 234 v8::HandleScope handleScope;
216 v8::Context::Scope contextScope(toV8Context(scriptContext, UseCurrentWorld)) ; 235 v8::Context::Scope contextScope(toV8Context(scriptContext, UseCurrentWorld)) ;
217 return ScriptValue(prpValue->deserialize()); 236 return ScriptValue(prpValue->deserialize());
218 } 237 }
219 238
220 bool injectIDBKeyIntoScriptValue(PassRefPtr<IDBKey> key, ScriptValue& value, con st IDBKeyPath& keyPath) 239 PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<Serializ edScriptValue> prpValue, const IDBKeyPath& keyPath)
221 { 240 {
222 IDB_TRACE("injectIDBKeyIntoScriptValue"); 241 IDB_TRACE("createIDBKeyFromSerializedValueAndKeyPath");
242 ASSERT(!keyPath.isNull());
243
244 RefPtr<SerializedScriptValue> value = prpValue;
245
246 if (keyPath.type() == IDBKeyPath::ArrayType) {
247 IDBKey::KeyArray result;
248 const Vector<String>& array = keyPath.array();
249 for (size_t i = 0; i < array.size(); ++i) {
250 RefPtr<IDBKey> key = createIDBKeyFromSerializedValueAndKeyPath(value , array[i]);
251 if (!key)
252 return 0;
253 result.append(key);
254 }
255 return IDBKey::createArray(result);
256 }
257
258 ASSERT(keyPath.type() == IDBKeyPath::StringType);
259 return createIDBKeyFromSerializedValueAndKeyPath(value, keyPath.string());
260 }
261
262 PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDB Key> key, PassRefPtr<SerializedScriptValue> value, const IDBKeyPath& keyPath)
263 {
264 IDB_TRACE("injectIDBKeyIntoSerializedValue");
223 265
224 ASSERT(keyPath.type() == IDBKeyPath::StringType); 266 ASSERT(keyPath.type() == IDBKeyPath::StringType);
225 Vector<String> keyPathElements; 267 Vector<String> keyPathElements;
226 IDBKeyPathParseError error; 268 IDBKeyPathParseError error;
227 IDBParseKeyPath(keyPath.string(), keyPathElements, error); 269 IDBParseKeyPath(keyPath.string(), keyPathElements, error);
228 ASSERT(error == IDBKeyPathParseErrorNone); 270 ASSERT(error == IDBKeyPathParseErrorNone);
229 271
230 if (!keyPathElements.size()) 272 if (!keyPathElements.size())
231 return 0; 273 return 0;
232 274
233 v8::HandleScope handleScope; 275 v8::HandleScope handleScope;
234 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext ()); 276 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext ());
235 277
236 v8::Handle<v8::Value> v8Value(value.v8Value()); 278 v8::Handle<v8::Value> v8Value(value->deserialize());
237 v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPathElement s, keyPathElements.size() - 1)); 279 v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPathElement s, keyPathElements.size() - 1));
238 if (parent.IsEmpty()) 280 if (parent.IsEmpty())
239 return false; 281 return 0;
240 282
241 if (!set(parent, keyPathElements.last(), toV8(key.get()))) 283 if (!set(parent, keyPathElements.last(), toV8(key.get())))
242 return false; 284 return 0;
243 285
244 return true; 286 return SerializedScriptValue::create(v8Value);
245 } 287 }
246 288
247 bool canInjectIDBKeyIntoScriptValue(const ScriptValue& scriptValue, const IDBKey Path& keyPath) 289 bool canInjectIDBKeyIntoScriptValue(const ScriptValue& scriptValue, const IDBKey Path& keyPath)
248 { 290 {
249 IDB_TRACE("canInjectIDBKeyIntoScriptValue"); 291 IDB_TRACE("canInjectIDBKeyIntoScriptValue");
250 ASSERT(keyPath.type() == IDBKeyPath::StringType); 292 ASSERT(keyPath.type() == IDBKeyPath::StringType);
251 Vector<String> keyPathElements; 293 Vector<String> keyPathElements;
252 IDBKeyPathParseError error; 294 IDBKeyPathParseError error;
253 IDBParseKeyPath(keyPath.string(), keyPathElements, error); 295 IDBParseKeyPath(keyPath.string(), keyPathElements, error);
254 ASSERT(error == IDBKeyPathParseErrorNone); 296 ASSERT(error == IDBKeyPathParseErrorNone);
255 297
256 if (!keyPathElements.size()) 298 if (!keyPathElements.size())
257 return false; 299 return false;
258 300
259 v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); 301 v8::Handle<v8::Value> v8Value(scriptValue.v8Value());
260 return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements. size() - 1); 302 return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements. size() - 1);
261 } 303 }
262 304
263 } // namespace WebCore 305 } // namespace WebCore
264 306
265 #endif 307 #endif
OLDNEW
« 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