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

Side by Side Diff: Source/modules/indexeddb/IDBObjectStore.cpp

Issue 236783002: Pass NewScriptState to idbAnyToScriptValue() and idbKeyToScriptValue() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBObjectStore.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 : m_metadata(metadata) 54 : m_metadata(metadata)
55 , m_transaction(transaction) 55 , m_transaction(transaction)
56 , m_deleted(false) 56 , m_deleted(false)
57 { 57 {
58 ASSERT(m_transaction); 58 ASSERT(m_transaction);
59 // We pass a reference to this object before it can be adopted. 59 // We pass a reference to this object before it can be adopted.
60 relaxAdoptionRequirement(); 60 relaxAdoptionRequirement();
61 ScriptWrappable::init(this); 61 ScriptWrappable::init(this);
62 } 62 }
63 63
64 ScriptValue IDBObjectStore::keyPath(ExecutionContext* context) const 64 ScriptValue IDBObjectStore::keyPath(NewScriptState* scriptState) const
65 { 65 {
66 DOMRequestState requestState(toIsolate(context)); 66 return idbAnyToScriptValue(scriptState, IDBAny::create(m_metadata.keyPath));
67 return idbAnyToScriptValue(&requestState, IDBAny::create(m_metadata.keyPath) );
68 } 67 }
69 68
70 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const 69 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const
71 { 70 {
72 IDB_TRACE("IDBObjectStore::indexNames"); 71 IDB_TRACE("IDBObjectStore::indexNames");
73 RefPtr<DOMStringList> indexNames = DOMStringList::create(); 72 RefPtr<DOMStringList> indexNames = DOMStringList::create();
74 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) 73 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it)
75 indexNames->append(it->value.name); 74 indexNames->append(it->value.name);
76 indexNames->sort(); 75 indexNames->sort();
77 return indexNames.release(); 76 return indexNames.release();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 292 }
294 293
295 namespace { 294 namespace {
296 // This class creates the index keys for a given index by extracting 295 // This class creates the index keys for a given index by extracting
297 // them from the SerializedScriptValue, for all the existing values in 296 // them from the SerializedScriptValue, for all the existing values in
298 // the objectStore. It only needs to be kept alive by virtue of being 297 // the objectStore. It only needs to be kept alive by virtue of being
299 // a listener on an IDBRequest object, in the same way that JavaScript 298 // a listener on an IDBRequest object, in the same way that JavaScript
300 // cursor success handlers are kept alive. 299 // cursor success handlers are kept alive.
301 class IndexPopulator FINAL : public EventListener { 300 class IndexPopulator FINAL : public EventListener {
302 public: 301 public:
303 static PassRefPtr<IndexPopulator> create(PassRefPtr<IDBDatabase> database, i nt64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetada ta) 302 static PassRefPtr<IndexPopulator> create(NewScriptState* scriptState, PassRe fPtr<IDBDatabase> database, int64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
304 { 303 {
305 return adoptRef(new IndexPopulator(database, transactionId, objectStoreI d, indexMetadata)); 304 return adoptRef(new IndexPopulator(scriptState, database, transactionId, objectStoreId, indexMetadata));
306 } 305 }
307 306
308 virtual bool operator==(const EventListener& other) OVERRIDE 307 virtual bool operator==(const EventListener& other) OVERRIDE
309 { 308 {
310 return this == &other; 309 return this == &other;
311 } 310 }
312 311
313 private: 312 private:
314 IndexPopulator(PassRefPtr<IDBDatabase> database, int64_t transactionId, int6 4_t objectStoreId, const IDBIndexMetadata& indexMetadata) 313 IndexPopulator(NewScriptState* scriptState, PassRefPtr<IDBDatabase> database , int64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMet adata)
315 : EventListener(CPPEventListenerType) 314 : EventListener(CPPEventListenerType)
315 , m_scriptState(scriptState)
316 , m_database(database) 316 , m_database(database)
317 , m_transactionId(transactionId) 317 , m_transactionId(transactionId)
318 , m_objectStoreId(objectStoreId) 318 , m_objectStoreId(objectStoreId)
319 , m_indexMetadata(indexMetadata) 319 , m_indexMetadata(indexMetadata)
320 { 320 {
321 } 321 }
322 322
323 virtual void handleEvent(ExecutionContext* context, Event* event) OVERRIDE 323 virtual void handleEvent(ExecutionContext* context, Event* event) OVERRIDE
324 { 324 {
325 ASSERT(event->type() == EventTypeNames::success); 325 ASSERT(event->type() == EventTypeNames::success);
326 EventTarget* target = event->target(); 326 EventTarget* target = event->target();
327 IDBRequest* request = static_cast<IDBRequest*>(target); 327 IDBRequest* request = static_cast<IDBRequest*>(target);
328 328
329 RefPtr<IDBAny> cursorAny = request->resultAsAny(); 329 RefPtr<IDBAny> cursorAny = request->resultAsAny();
330 RefPtr<IDBCursorWithValue> cursor; 330 RefPtr<IDBCursorWithValue> cursor;
331 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) 331 if (cursorAny->type() == IDBAny::IDBCursorWithValueType)
332 cursor = cursorAny->idbCursorWithValue(); 332 cursor = cursorAny->idbCursorWithValue();
333 333
334 Vector<int64_t> indexIds; 334 Vector<int64_t> indexIds;
335 indexIds.append(m_indexMetadata.id); 335 indexIds.append(m_indexMetadata.id);
336 if (cursor && !cursor->isDeleted()) { 336 if (cursor && !cursor->isDeleted()) {
337 cursor->continueFunction(static_cast<IDBKey*>(0), static_cast<IDBKey *>(0), ASSERT_NO_EXCEPTION); 337 cursor->continueFunction(static_cast<IDBKey*>(0), static_cast<IDBKey *>(0), ASSERT_NO_EXCEPTION);
338 338
339 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey(); 339 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey();
340 ScriptValue value = cursor->value(context); 340 ScriptValue value = cursor->value(m_scriptState.get());
341 341
342 IDBObjectStore::IndexKeys indexKeys; 342 IDBObjectStore::IndexKeys indexKeys;
343 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys); 343 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys);
344 344
345 Vector<IDBObjectStore::IndexKeys> indexKeysList; 345 Vector<IDBObjectStore::IndexKeys> indexKeysList;
346 indexKeysList.append(indexKeys); 346 indexKeysList.append(indexKeys);
347 347
348 m_database->backend()->setIndexKeys(m_transactionId, m_objectStoreId , primaryKey.release(), indexIds, indexKeysList); 348 m_database->backend()->setIndexKeys(m_transactionId, m_objectStoreId , primaryKey.release(), indexIds, indexKeysList);
349 } else { 349 } else {
350 // Now that we are done indexing, tell the backend to go 350 // Now that we are done indexing, tell the backend to go
351 // back to processing tasks of type NormalTask. 351 // back to processing tasks of type NormalTask.
352 m_database->backend()->setIndexesReady(m_transactionId, m_objectStor eId, indexIds); 352 m_database->backend()->setIndexesReady(m_transactionId, m_objectStor eId, indexIds);
353 m_database.clear(); 353 m_database.clear();
354 } 354 }
355 355
356 } 356 }
357 357
358 RefPtr<NewScriptState> m_scriptState;
358 RefPtr<IDBDatabase> m_database; 359 RefPtr<IDBDatabase> m_database;
359 const int64_t m_transactionId; 360 const int64_t m_transactionId;
360 const int64_t m_objectStoreId; 361 const int64_t m_objectStoreId;
361 const IDBIndexMetadata m_indexMetadata; 362 const IDBIndexMetadata m_indexMetadata;
362 }; 363 };
363 } 364 }
364 365
365 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, const Dictionary& options, ExceptionS tate& exceptionState) 366 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(NewScriptState* scriptState, co nst String& name, const IDBKeyPath& keyPath, const Dictionary& options, Exceptio nState& exceptionState)
366 { 367 {
367 bool unique = false; 368 bool unique = false;
368 options.get("unique", unique); 369 options.get("unique", unique);
369 370
370 bool multiEntry = false; 371 bool multiEntry = false;
371 options.get("multiEntry", multiEntry); 372 options.get("multiEntry", multiEntry);
372 373
373 return createIndex(context, name, keyPath, unique, multiEntry, exceptionStat e); 374 return createIndex(scriptState, name, keyPath, unique, multiEntry, exception State);
374 } 375 }
375 376
376 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, Excepti onState& exceptionState) 377 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(NewScriptState* scriptState, co nst String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, Excep tionState& exceptionState)
377 { 378 {
378 IDB_TRACE("IDBObjectStore::createIndex"); 379 IDB_TRACE("IDBObjectStore::createIndex");
379 if (!m_transaction->isVersionChange()) { 380 if (!m_transaction->isVersionChange()) {
380 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage); 381 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage);
381 return nullptr; 382 return nullptr;
382 } 383 }
383 if (isDeleted()) { 384 if (isDeleted()) {
384 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 385 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
385 return nullptr; 386 return nullptr;
386 } 387 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 419 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
419 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( )); 420 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( ));
420 m_indexMap.set(name, index); 421 m_indexMap.set(name, index);
421 m_metadata.indexes.set(indexId, metadata); 422 m_metadata.indexes.set(indexId, metadata);
422 m_transaction->db()->indexCreated(id(), metadata); 423 m_transaction->db()->indexCreated(id(), metadata);
423 424
424 ASSERT(!exceptionState.hadException()); 425 ASSERT(!exceptionState.hadException());
425 if (exceptionState.hadException()) 426 if (exceptionState.hadException())
426 return nullptr; 427 return nullptr;
427 428
428 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask); 429 RefPtr<IDBRequest> indexRequest = openCursor(scriptState->executionContext() , static_cast<IDBKeyRange*>(0), blink::WebIDBCursor::Next, WebIDBDatabase::Preem ptiveTask);
429 indexRequest->preventPropagation(); 430 indexRequest->preventPropagation();
430 431
431 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 432 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
432 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(transaction() ->db(), m_transaction->id(), id(), metadata); 433 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState, transaction()->db(), m_transaction->id(), id(), metadata);
433 indexRequest->setOnsuccess(indexPopulator); 434 indexRequest->setOnsuccess(indexPopulator);
434
435 return index.release(); 435 return index.release();
436 } 436 }
437 437
438 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e xceptionState) 438 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e xceptionState)
439 { 439 {
440 IDB_TRACE("IDBObjectStore::index"); 440 IDB_TRACE("IDBObjectStore::index");
441 if (isDeleted()) { 441 if (isDeleted()) {
442 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 442 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
443 return nullptr; 443 return nullptr;
444 } 444 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 618 }
619 return IDBIndexMetadata::InvalidId; 619 return IDBIndexMetadata::InvalidId;
620 } 620 }
621 621
622 WebIDBDatabase* IDBObjectStore::backendDB() const 622 WebIDBDatabase* IDBObjectStore::backendDB() const
623 { 623 {
624 return m_transaction->backendDB(); 624 return m_transaction->backendDB();
625 } 625 }
626 626
627 } // namespace WebCore 627 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBObjectStore.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698