Changeset 65439 in webkit
- Timestamp:
- Aug 16, 2010 10:30:58 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r65438 r65439 1 2010-08-16 Marcus Bulach <bulach@chromium.org> 2 3 Reviewed by Jeremy Orlow. 4 5 Implements IDBKeyPath extractor. 6 https://bugs.webkit.org/show_bug.cgi?id=43276 7 8 Unit-test IDBKeyPathExtractorTest.cpp. 9 LayoutTests will arrive as IndexedDB infrastructure is fleshed out. 10 11 * bindings/v8/IDBBindingUtilities.cpp: 12 (WebCore::getValueFrom): 13 (WebCore::createIDBKeyFromSerializedValueAndKeyPath): 14 * bindings/v8/IDBBindingUtilities.h: 15 1 16 2010-08-13 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> 2 17 -
trunk/WebCore/bindings/v8/IDBBindingUtilities.cpp
r63064 r65439 30 30 31 31 #include "IDBKey.h" 32 #include "IDBKeyPath.h" 33 #include "SerializedScriptValue.h" 32 34 #include "V8Binding.h" 35 #include <wtf/Vector.h> 33 36 34 37 namespace WebCore { … … 46 49 } 47 50 51 template<typename T> 52 bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value) 53 { 54 v8::Local<v8::Object> object = v8Value->ToObject(); 55 if (!object->Has(indexOrName)) 56 return false; 57 v8Value = object->Get(indexOrName); 58 return true; 59 } 60 61 PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath) 62 { 63 v8::HandleScope scope; 64 v8::Handle<v8::Value> v8Value(value->deserialize()); 65 for (size_t i = 0; i < keyPath.size(); ++i) { 66 switch (keyPath[i].type) { 67 case IDBKeyPathElement::IsIndexed: 68 if (!v8Value->IsArray() || !getValueFrom(keyPath[i].index, v8Value)) 69 return 0; 70 break; 71 case IDBKeyPathElement::IsNamed: 72 if (!v8Value->IsObject() || !getValueFrom(v8String(keyPath[i].identifier), v8Value)) 73 return 0; 74 break; 75 default: 76 ASSERT_NOT_REACHED(); 77 } 78 } 79 return createIDBKeyFromValue(v8Value); 80 } 81 48 82 } // namespace WebCore 49 83 -
trunk/WebCore/bindings/v8/IDBBindingUtilities.h
r63064 r65439 35 35 36 36 class IDBKey; 37 class SerializedScriptValue; 38 struct IDBKeyPathElement; 37 39 38 40 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value>); 41 PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement, 0>& keyPath); 39 42 40 43 } -
trunk/WebKit/chromium/ChangeLog
r65417 r65439 1 2010-08-16 Marcus Bulach <bulach@chromium.org> 2 3 Reviewed by Jeremy Orlow. 4 5 Implements IDBKeyPath extractor. 6 https://bugs.webkit.org/show_bug.cgi?id=43276 7 8 Unit-test IDBKeyPathExtractorTest.cpp. 9 LayoutTests will arrive as IndexedDB infrastructure is fleshed out. 10 11 12 * WebKit.gyp: 13 * public/WebIDBKey.h: 14 * public/WebIDBKeyPath.h: Added. 15 (WebKit::WebIDBKeyPath::WebIDBKeyPath): 16 (WebKit::WebIDBKeyPath::~WebIDBKeyPath): 17 * public/WebPrivateOwnPtr.h: Added. 18 (WebKit::WebPrivateOwnPtr::WebPrivateOwnPtr): 19 (WebKit::WebPrivateOwnPtr::~WebPrivateOwnPtr): 20 (WebKit::WebPrivateOwnPtr::reset): 21 (WebKit::WebPrivateOwnPtr::get): 22 (WebKit::WebPrivateOwnPtr::operator->): 23 * src/WebIDBKey.cpp: 24 (WebKit::WebIDBKey::createFromValueAndKeyPath): 25 * src/WebIDBKeyPath.cpp: Added. 26 (WebKit::WebIDBKeyPath::create): 27 (WebKit::WebIDBKeyPath::WebIDBKeyPath): 28 (WebKit::WebIDBKeyPath::parseError): 29 (WebKit::WebIDBKeyPath::assign): 30 (WebKit::WebIDBKeyPath::reset): 31 (WebKit::WebIDBKeyPath::operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>&): 32 * tests/IDBBindingUtilitiesTest.cpp: Added. 33 (WebCore::LocalContext::LocalContext): 34 (WebCore::LocalContext::~LocalContext): 35 (WebCore::checkKeyFromValueAndKeyPathInternal): 36 (WebCore::checkKeyPathNullValue): 37 (WebCore::checkKeyPathStringValue): 38 (WebCore::checkKeyPathNumberValue): 39 (WebCore::TEST): 40 1 41 2010-07-28 Marcus Bulach <bulach@chromium.org> 2 42 -
trunk/WebKit/chromium/WebKit.gyp
r65417 r65439 187 187 'public/WebIDBIndex.h', 188 188 'public/WebIDBKey.h', 189 'public/WebIDBKeyPath.h', 189 190 'public/WebIDBObjectStore.h', 190 191 'public/WebInputElement.h', … … 226 227 'public/WebPopupType.h', 227 228 'public/WebPrivatePtr.h', 229 'public/WebPrivateOwnPtr.h', 228 230 'public/WebRange.h', 229 231 'public/WebRect.h', … … 431 433 'src/WebIDBIndexImpl.h', 432 434 'src/WebIDBKey.cpp', 435 'src/WebIDBKeyPath.cpp', 433 436 'src/WebIDBKeyRange.cpp', 434 437 'src/WebIDBObjectStoreImpl.cpp', … … 704 707 'sources': [ 705 708 'tests/DragImageTest.cpp', 709 'tests/IDBBindingUtilitiesTest.cpp', 706 710 'tests/IDBKeyPathTest.cpp', 707 711 'tests/KeyboardTest.cpp', -
trunk/WebKit/chromium/public/WebIDBKey.h
r63755 r65439 35 35 namespace WebKit { 36 36 37 class WebIDBKeyPath; 38 class WebSerializedScriptValue; 39 37 40 class WebIDBKey { 38 41 public: … … 41 44 WEBKIT_API static WebIDBKey createNull(); 42 45 WEBKIT_API static WebIDBKey createInvalid(); 46 WEBKIT_API static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&); 43 47 44 48 WebIDBKey(const WebString& string) { assign(string); } -
trunk/WebKit/chromium/public/WebIDBKeyPath.h
r65438 r65439 24 24 */ 25 25 26 #i nclude "config.h"27 # include "IDBBindingUtilities.h"26 #ifndef WebIDBKeyPath_h 27 #define WebIDBKeyPath_h 28 28 29 #if ENABLE(INDEXED_DATABASE) 29 #include "WebCommon.h" 30 #include "WebPrivateOwnPtr.h" 31 #include "WebVector.h" 30 32 31 #include "IDBKey.h" 32 #include "V8Binding.h" 33 namespace WebCore { struct IDBKeyPathElement; } 33 34 34 namespace W ebCore {35 namespace WTF { template<typename T, size_t inlineCapacity> class Vector; } 35 36 36 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value) 37 { 38 if (value->IsNull()) 39 return IDBKey::create(); 40 if (value->IsInt32()) 41 return IDBKey::create(value->Int32Value()); 42 if (value->IsString()) 43 return IDBKey::create(v8ValueToWebCoreString(value)); 44 // FIXME: Implement dates. 45 return 0; 46 } 37 namespace WebKit { 47 38 48 } // namespace WebCore 39 class WebString; 49 40 41 class WebIDBKeyPath { 42 public: 43 static WebIDBKeyPath create(const WebString&); 44 WebIDBKeyPath(const WebIDBKeyPath& keyPath) { assign(keyPath); } 45 ~WebIDBKeyPath() { reset(); } 46 47 WEBKIT_API int parseError() const; 48 WEBKIT_API void assign(const WebIDBKeyPath&); 49 WEBKIT_API void reset(); 50 51 #if WEBKIT_IMPLEMENTATION 52 operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>& () const; 50 53 #endif 54 55 private: 56 WebIDBKeyPath(); 57 58 #if WEBKIT_IMPLEMENTATION 59 WebIDBKeyPath(const WTF::Vector<WebCore::IDBKeyPathElement, 0>&, int parseError); 60 #endif 61 62 WebPrivateOwnPtr<WTF::Vector<WebCore::IDBKeyPathElement, 0> > m_private; 63 int m_parseError; 64 }; 65 66 } // namespace WebKit 67 68 #endif // WebIDBKeyPath_h -
trunk/WebKit/chromium/public/WebPrivateOwnPtr.h
r65438 r65439 24 24 */ 25 25 26 #i nclude "config.h"27 # include "IDBBindingUtilities.h"26 #ifndef WebPrivateOwnPtr_h 27 #define WebPrivateOwnPtr_h 28 28 29 #i f ENABLE(INDEXED_DATABASE)29 #include "WebCommon.h" 30 30 31 #include "IDBKey.h" 32 #include "V8Binding.h" 31 namespace WebKit { 33 32 34 namespace WebCore { 33 // This class is an implementation detail of the WebKit API. It exists 34 // to help simplify the implementation of WebKit interfaces that merely 35 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it 36 // wraps a naked pointer rather than a reference counted. 37 // Note: you must call reset(0) on the implementation side in order to delete 38 // the WebCore pointer. 39 template <typename T> 40 class WebPrivateOwnPtr { 41 public: 42 WebPrivateOwnPtr() : m_ptr(0) {} 43 ~WebPrivateOwnPtr() { WEBKIT_ASSERT(!m_ptr); } 35 44 36 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value) 37 { 38 if (value->IsNull()) 39 return IDBKey::create(); 40 if (value->IsInt32()) 41 return IDBKey::create(value->Int32Value()); 42 if (value->IsString()) 43 return IDBKey::create(v8ValueToWebCoreString(value)); 44 // FIXME: Implement dates. 45 return 0; 46 } 45 #if WEBKIT_IMPLEMENTATION 46 explicit WebPrivateOwnPtr(T* ptr) 47 : m_ptr(ptr) 48 { 49 } 47 50 48 } // namespace WebCore 51 void reset(T* ptr) 52 { 53 delete m_ptr; 54 m_ptr = ptr; 55 } 56 57 T* get() const { return m_ptr; } 58 59 T* operator->() const 60 { 61 WEBKIT_ASSERT(m_ptr); 62 return m_ptr; 63 } 64 #endif // WEBKIT_IMPLEMENTATION 65 66 private: 67 T* m_ptr; 68 69 WebPrivateOwnPtr(const WebPrivateOwnPtr&); 70 void operator=(const WebPrivateOwnPtr&); 71 }; 72 73 } // namespace WebKit 49 74 50 75 #endif -
trunk/WebKit/chromium/src/WebIDBKey.cpp
r63755 r65439 31 31 #if ENABLE(INDEXED_DATABASE) 32 32 33 #include "IDBBindingUtilities.h" 33 34 #include "IDBKey.h" 35 #include "IDBKeyPath.h" 36 #include "SerializedScriptValue.h" 37 #include "WebIDBKeyPath.h" 38 #include "WebSerializedScriptValue.h" 34 39 35 40 using namespace WebCore; … … 49 54 key.assignInvalid(); 50 55 return key; 56 } 57 58 WebIDBKey WebIDBKey::createFromValueAndKeyPath(const WebSerializedScriptValue& serializedScriptValue, const WebIDBKeyPath& idbKeyPath) 59 { 60 if (serializedScriptValue.isNull()) 61 return WebIDBKey::createInvalid(); 62 return WebCore::createIDBKeyFromSerializedValueAndKeyPath(serializedScriptValue, idbKeyPath); 51 63 } 52 64 -
trunk/WebKit/chromium/src/WebIDBKeyPath.cpp
r65438 r65439 25 25 26 26 #include "config.h" 27 #include " IDBBindingUtilities.h"27 #include "WebIDBKeyPath.h" 28 28 29 29 #if ENABLE(INDEXED_DATABASE) 30 30 31 #include "IDBKey.h" 32 #include "V8Binding.h" 31 #include "IDBKeyPath.h" 32 #include "WebString.h" 33 #include "WebVector.h" 34 #include <wtf/Vector.h> 33 35 34 namespace WebCore { 36 using namespace WebCore; 35 37 36 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value) 38 namespace WebKit { 39 40 WebIDBKeyPath WebIDBKeyPath::create(const WebString& keyPath) 37 41 { 38 if (value->IsNull()) 39 return IDBKey::create(); 40 if (value->IsInt32()) 41 return IDBKey::create(value->Int32Value()); 42 if (value->IsString()) 43 return IDBKey::create(v8ValueToWebCoreString(value)); 44 // FIXME: Implement dates. 45 return 0; 42 WTF::Vector<IDBKeyPathElement> idbElements; 43 IDBKeyPathParseError idbError; 44 IDBParseKeyPath(keyPath, idbElements, idbError); 45 return WebIDBKeyPath(idbElements, static_cast<int>(idbError)); 46 46 } 47 47 48 } // namespace WebCore 48 WebIDBKeyPath::WebIDBKeyPath(const WTF::Vector<IDBKeyPathElement>& elements, int parseError) 49 : m_private(new WTF::Vector<IDBKeyPathElement>(elements)) 50 , m_parseError(parseError) 51 { 52 } 49 53 50 #endif 54 int WebIDBKeyPath::parseError() const 55 { 56 return m_parseError; 57 } 58 59 void WebIDBKeyPath::assign(const WebIDBKeyPath& keyPath) 60 { 61 m_parseError = keyPath.m_parseError; 62 m_private.reset(new WTF::Vector<IDBKeyPathElement>(keyPath)); 63 } 64 65 void WebIDBKeyPath::reset() 66 { 67 m_private.reset(0); 68 } 69 70 WebIDBKeyPath::operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>&() const 71 { 72 return *m_private.get(); 73 } 74 75 } // namespace WebKit 76 77 #endif // ENABLE(INDEXED_DATABASE)
Note: See TracChangeset
for help on using the changeset viewer.