Changeset 65439 in webkit


Ignore:
Timestamp:
Aug 16, 2010 10:30:58 AM (14 years ago)
Author:
bulach@chromium.org
Message:

2010-08-16 Marcus Bulach <bulach@chromium.org>

Reviewed by Jeremy Orlow.

Implements IDBKeyPath extractor.
https://bugs.webkit.org/show_bug.cgi?id=43276

Unit-test IDBKeyPathExtractorTest.cpp.
LayoutTests will arrive as IndexedDB infrastructure is fleshed out.

  • bindings/v8/IDBBindingUtilities.cpp: (WebCore::getValueFrom): (WebCore::createIDBKeyFromSerializedValueAndKeyPath):
  • bindings/v8/IDBBindingUtilities.h:

2010-08-16 Marcus Bulach <bulach@chromium.org>

Reviewed by Jeremy Orlow.

Implements IDBKeyPath extractor.
https://bugs.webkit.org/show_bug.cgi?id=43276

Unit-test IDBKeyPathExtractorTest.cpp.
LayoutTests will arrive as IndexedDB infrastructure is fleshed out.

  • WebKit.gyp:
  • public/WebIDBKey.h:
  • public/WebIDBKeyPath.h: Added. (WebKit::WebIDBKeyPath::WebIDBKeyPath): (WebKit::WebIDBKeyPath::~WebIDBKeyPath):
  • public/WebPrivateOwnPtr.h: Added. (WebKit::WebPrivateOwnPtr::WebPrivateOwnPtr): (WebKit::WebPrivateOwnPtr::~WebPrivateOwnPtr): (WebKit::WebPrivateOwnPtr::reset): (WebKit::WebPrivateOwnPtr::get): (WebKit::WebPrivateOwnPtr::operator->):
  • src/WebIDBKey.cpp: (WebKit::WebIDBKey::createFromValueAndKeyPath):
  • src/WebIDBKeyPath.cpp: Added. (WebKit::WebIDBKeyPath::create): (WebKit::WebIDBKeyPath::WebIDBKeyPath): (WebKit::WebIDBKeyPath::parseError): (WebKit::WebIDBKeyPath::assign): (WebKit::WebIDBKeyPath::reset): (WebKit::WebIDBKeyPath::operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>&):
  • tests/IDBBindingUtilitiesTest.cpp: Added. (WebCore::LocalContext::LocalContext): (WebCore::LocalContext::~LocalContext): (WebCore::checkKeyFromValueAndKeyPathInternal): (WebCore::checkKeyPathNullValue): (WebCore::checkKeyPathStringValue): (WebCore::checkKeyPathNumberValue): (WebCore::TEST):
Location:
trunk
Files:
1 added
7 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65438 r65439  
     12010-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
    1162010-08-13  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
    217
  • trunk/WebCore/bindings/v8/IDBBindingUtilities.cpp

    r63064 r65439  
    3030
    3131#include "IDBKey.h"
     32#include "IDBKeyPath.h"
     33#include "SerializedScriptValue.h"
    3234#include "V8Binding.h"
     35#include <wtf/Vector.h>
    3336
    3437namespace WebCore {
     
    4649}
    4750
     51template<typename T>
     52bool 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
     61PassRefPtr<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
    4882} // namespace WebCore
    4983
  • trunk/WebCore/bindings/v8/IDBBindingUtilities.h

    r63064 r65439  
    3535
    3636class IDBKey;
     37class SerializedScriptValue;
     38struct IDBKeyPathElement;
    3739
    3840PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value>);
     41PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value,  const Vector<IDBKeyPathElement, 0>& keyPath);
    3942
    4043}
  • trunk/WebKit/chromium/ChangeLog

    r65417 r65439  
     12010-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
    1412010-07-28  Marcus Bulach  <bulach@chromium.org>
    242
  • trunk/WebKit/chromium/WebKit.gyp

    r65417 r65439  
    187187                'public/WebIDBIndex.h',
    188188                'public/WebIDBKey.h',
     189                'public/WebIDBKeyPath.h',
    189190                'public/WebIDBObjectStore.h',
    190191                'public/WebInputElement.h',
     
    226227                'public/WebPopupType.h',
    227228                'public/WebPrivatePtr.h',
     229                'public/WebPrivateOwnPtr.h',
    228230                'public/WebRange.h',
    229231                'public/WebRect.h',
     
    431433                'src/WebIDBIndexImpl.h',
    432434                'src/WebIDBKey.cpp',
     435                'src/WebIDBKeyPath.cpp',
    433436                'src/WebIDBKeyRange.cpp',
    434437                'src/WebIDBObjectStoreImpl.cpp',
     
    704707                    'sources': [
    705708                        'tests/DragImageTest.cpp',
     709                        'tests/IDBBindingUtilitiesTest.cpp',
    706710                        'tests/IDBKeyPathTest.cpp',
    707711                        'tests/KeyboardTest.cpp',
  • trunk/WebKit/chromium/public/WebIDBKey.h

    r63755 r65439  
    3535namespace WebKit {
    3636
     37class WebIDBKeyPath;
     38class WebSerializedScriptValue;
     39
    3740class WebIDBKey {
    3841public:
     
    4144    WEBKIT_API static WebIDBKey createNull();
    4245    WEBKIT_API static WebIDBKey createInvalid();
     46    WEBKIT_API static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&);
    4347
    4448    WebIDBKey(const WebString& string) { assign(string); }
  • trunk/WebKit/chromium/public/WebIDBKeyPath.h

    r65438 r65439  
    2424 */
    2525
    26 #include "config.h"
    27 #include "IDBBindingUtilities.h"
     26#ifndef WebIDBKeyPath_h
     27#define WebIDBKeyPath_h
    2828
    29 #if ENABLE(INDEXED_DATABASE)
     29#include "WebCommon.h"
     30#include "WebPrivateOwnPtr.h"
     31#include "WebVector.h"
    3032
    31 #include "IDBKey.h"
    32 #include "V8Binding.h"
     33namespace WebCore { struct IDBKeyPathElement; }
    3334
    34 namespace WebCore {
     35namespace WTF { template<typename T, size_t inlineCapacity> class Vector; }
    3536
    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 }
     37namespace WebKit {
    4738
    48 } // namespace WebCore
     39class WebString;
    4940
     41class WebIDBKeyPath {
     42public:
     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;
    5053#endif
     54
     55private:
     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  
    2424 */
    2525
    26 #include "config.h"
    27 #include "IDBBindingUtilities.h"
     26#ifndef WebPrivateOwnPtr_h
     27#define WebPrivateOwnPtr_h
    2828
    29 #if ENABLE(INDEXED_DATABASE)
     29#include "WebCommon.h"
    3030
    31 #include "IDBKey.h"
    32 #include "V8Binding.h"
     31namespace WebKit {
    3332
    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.
     39template <typename T>
     40class WebPrivateOwnPtr {
     41public:
     42    WebPrivateOwnPtr() : m_ptr(0) {}
     43    ~WebPrivateOwnPtr() { WEBKIT_ASSERT(!m_ptr); }
    3544
    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    }
    4750
    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
     66private:
     67    T* m_ptr;
     68
     69    WebPrivateOwnPtr(const WebPrivateOwnPtr&);
     70    void operator=(const WebPrivateOwnPtr&);
     71};
     72
     73} // namespace WebKit
    4974
    5075#endif
  • trunk/WebKit/chromium/src/WebIDBKey.cpp

    r63755 r65439  
    3131#if ENABLE(INDEXED_DATABASE)
    3232
     33#include "IDBBindingUtilities.h"
    3334#include "IDBKey.h"
     35#include "IDBKeyPath.h"
     36#include "SerializedScriptValue.h"
     37#include "WebIDBKeyPath.h"
     38#include "WebSerializedScriptValue.h"
    3439
    3540using namespace WebCore;
     
    4954    key.assignInvalid();
    5055    return key;
     56}
     57
     58WebIDBKey WebIDBKey::createFromValueAndKeyPath(const WebSerializedScriptValue& serializedScriptValue, const WebIDBKeyPath& idbKeyPath)
     59{
     60    if (serializedScriptValue.isNull())
     61        return WebIDBKey::createInvalid();
     62    return WebCore::createIDBKeyFromSerializedValueAndKeyPath(serializedScriptValue, idbKeyPath);
    5163}
    5264
  • trunk/WebKit/chromium/src/WebIDBKeyPath.cpp

    r65438 r65439  
    2525
    2626#include "config.h"
    27 #include "IDBBindingUtilities.h"
     27#include "WebIDBKeyPath.h"
    2828
    2929#if ENABLE(INDEXED_DATABASE)
    3030
    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>
    3335
    34 namespace WebCore {
     36using namespace WebCore;
    3537
    36 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value)
     38namespace WebKit {
     39
     40WebIDBKeyPath WebIDBKeyPath::create(const WebString& keyPath)
    3741{
    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));
    4646}
    4747
    48 } // namespace WebCore
     48WebIDBKeyPath::WebIDBKeyPath(const WTF::Vector<IDBKeyPathElement>& elements, int parseError)
     49    : m_private(new WTF::Vector<IDBKeyPathElement>(elements))
     50    , m_parseError(parseError)
     51{
     52}
    4953
    50 #endif
     54int WebIDBKeyPath::parseError() const
     55{
     56    return m_parseError;
     57}
     58
     59void WebIDBKeyPath::assign(const WebIDBKeyPath& keyPath)
     60{
     61    m_parseError = keyPath.m_parseError;
     62    m_private.reset(new WTF::Vector<IDBKeyPathElement>(keyPath));
     63}
     64
     65void WebIDBKeyPath::reset()
     66{
     67    m_private.reset(0);
     68}
     69
     70WebIDBKeyPath::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.