Title: [124402] trunk/Source
Revision
124402
Author
[email protected]
Date
2012-08-01 20:08:10 -0700 (Wed, 01 Aug 2012)

Log Message

IndexedDB: ObjectStoreMetaDataKey::m_metaDataType should use byte type
https://bugs.webkit.org/show_bug.cgi?id=92725

Patch by Xingnan Wang <[email protected]> on 2012-08-01
Reviewed by Kentaro Hara.

Source/WebCore:

No new tests - Low level functions covered by existing layout tests and also covered by Chromium
webkit_unit_tests IDBLevelIDBCodingTest.*.

* Modules/indexeddb/IDBLevelDBCoding.cpp:
(IDBLevelDBCoding):
(WebCore::IDBLevelDBCoding::decodeByte):
(WebCore::IDBLevelDBCoding::DatabaseFreeListKey::decode):
(WebCore::IDBLevelDBCoding::DatabaseNameKey::decode):
(WebCore::IDBLevelDBCoding::ObjectStoreMetaDataKey::decode):
(WebCore::IDBLevelDBCoding::ObjectStoreMetaDataKey::encode):
(WebCore::IDBLevelDBCoding::ObjectStoreMetaDataKey::metaDataType):
(WebCore::IDBLevelDBCoding::IndexMetaDataKey::decode):
(WebCore::IDBLevelDBCoding::ObjectStoreFreeListKey::decode):
(WebCore::IDBLevelDBCoding::IndexFreeListKey::decode):
(WebCore::IDBLevelDBCoding::ObjectStoreNamesKey::decode):
(WebCore::IDBLevelDBCoding::IndexNamesKey::decode):
* Modules/indexeddb/IDBLevelDBCoding.h:
(IDBLevelDBCoding):

Source/WebKit/chromium:

Add two new tests in IDBLevelDBCodingTest.cpp. One for an added function decodeByte() and
another for verifying that encodeByte() and encodeVarInt() are indentical when the encoded
values are <= 127.

* tests/IDBLevelDBCodingTest.cpp:
(IDBLevelDBCoding::TEST):
(IDBLevelDBCoding):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (124401 => 124402)


--- trunk/Source/WebCore/ChangeLog	2012-08-02 02:31:18 UTC (rev 124401)
+++ trunk/Source/WebCore/ChangeLog	2012-08-02 03:08:10 UTC (rev 124402)
@@ -1,3 +1,29 @@
+2012-08-01  Xingnan Wang  <[email protected]>
+
+        IndexedDB: ObjectStoreMetaDataKey::m_metaDataType should use byte type
+        https://bugs.webkit.org/show_bug.cgi?id=92725
+
+        Reviewed by Kentaro Hara.
+
+        No new tests - Low level functions covered by existing layout tests and also covered by Chromium
+        webkit_unit_tests IDBLevelIDBCodingTest.*.
+
+        * Modules/indexeddb/IDBLevelDBCoding.cpp:
+        (IDBLevelDBCoding):
+        (WebCore::IDBLevelDBCoding::decodeByte):
+        (WebCore::IDBLevelDBCoding::DatabaseFreeListKey::decode):
+        (WebCore::IDBLevelDBCoding::DatabaseNameKey::decode):
+        (WebCore::IDBLevelDBCoding::ObjectStoreMetaDataKey::decode):
+        (WebCore::IDBLevelDBCoding::ObjectStoreMetaDataKey::encode):
+        (WebCore::IDBLevelDBCoding::ObjectStoreMetaDataKey::metaDataType):
+        (WebCore::IDBLevelDBCoding::IndexMetaDataKey::decode):
+        (WebCore::IDBLevelDBCoding::ObjectStoreFreeListKey::decode):
+        (WebCore::IDBLevelDBCoding::IndexFreeListKey::decode):
+        (WebCore::IDBLevelDBCoding::ObjectStoreNamesKey::decode):
+        (WebCore::IDBLevelDBCoding::IndexNamesKey::decode):
+        * Modules/indexeddb/IDBLevelDBCoding.h:
+        (IDBLevelDBCoding):
+
 2012-08-01  James Robinson  <[email protected]>
 
         [chromium] Use new-style tracing macros with explicit category

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.cpp (124401 => 124402)


--- trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.cpp	2012-08-02 02:31:18 UTC (rev 124401)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.cpp	2012-08-02 03:08:10 UTC (rev 124402)
@@ -64,7 +64,7 @@
 //
 // Object store meta-data:
 //
-//     The prefix is followed by a type byte, then a variable-length integer, and then another variable-length integer (FIXME: this should be a byte).
+//     The prefix is followed by a type byte, then a variable-length integer, and then another type byte.
 //
 //     <database id, 0, 0, 50, object store id, 0> => utf16 object store name [ObjectStoreMetaDataKey]
 //     <database id, 0, 0, 50, object store id, 1> => utf16 key path [ObjectStoreMetaDataKey]
@@ -162,7 +162,7 @@
 static const unsigned char ObjectStoreNamesTypeByte = 200;
 static const unsigned char IndexNamesKeyTypeByte = 201;
 
-static const int64_t ObjectMetaDataTypeMaximum = INT64_MAX;
+static const unsigned char ObjectMetaDataTypeMaximum = 255;
 static const unsigned char IndexMetaDataTypeMaximum = 255;
 
 Vector<char> encodeByte(unsigned char c)
@@ -172,6 +172,15 @@
     return v;
 }
 
+const char* decodeByte(const char* p, const char* limit, unsigned char& foundChar)
+{
+    if (p >= limit)
+        return 0;
+
+    foundChar = *p++;
+    return p;
+}
+
 Vector<char> maxIDBKey()
 {
     return encodeByte(IDBKeyNullTypeByte);
@@ -961,7 +970,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == DatabaseFreeListTypeByte);
     if (p == limit)
         return 0;
@@ -1005,7 +1015,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == DatabaseNameTypeByte);
     if (p == limit)
         return 0;
@@ -1068,7 +1079,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == ObjectStoreMetaDataTypeByte);
     if (p == limit)
         return 0;
@@ -1078,16 +1090,16 @@
     ASSERT(result->m_objectStoreId);
     if (p == limit)
         return 0;
-    return decodeVarInt(p, limit, result->m_metaDataType);
+    return decodeByte(p, limit, result->m_metaDataType);
 }
 
-Vector<char> ObjectStoreMetaDataKey::encode(int64_t databaseId, int64_t objectStoreId, int64_t metaDataType)
+Vector<char> ObjectStoreMetaDataKey::encode(int64_t databaseId, int64_t objectStoreId, unsigned char metaDataType)
 {
     KeyPrefix prefix(databaseId, 0, 0);
     Vector<char> ret = prefix.encode();
     ret.append(encodeByte(ObjectStoreMetaDataTypeByte));
     ret.append(encodeVarInt(objectStoreId));
-    ret.append(encodeVarInt(metaDataType));
+    ret.append(encodeByte(metaDataType));
     return ret;
 }
 
@@ -1106,7 +1118,7 @@
     ASSERT(m_objectStoreId >= 0);
     return m_objectStoreId;
 }
-int64_t ObjectStoreMetaDataKey::metaDataType() const
+unsigned char ObjectStoreMetaDataKey::metaDataType() const
 {
     ASSERT(m_metaDataType >= 0);
     return m_metaDataType;
@@ -1142,7 +1154,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == IndexMetaDataTypeByte);
     if (p == limit)
         return 0;
@@ -1154,8 +1167,7 @@
         return 0;
     if (p == limit)
         return 0;
-    result->m_metaDataType = *p++;
-    return p;
+    return decodeByte(p, limit, result->m_metaDataType);
 }
 
 Vector<char> IndexMetaDataKey::encode(int64_t databaseId, int64_t objectStoreId, int64_t indexId, unsigned char metaDataType)
@@ -1213,7 +1225,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == ObjectStoreFreeListTypeByte);
     if (p == limit)
         return 0;
@@ -1266,7 +1279,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == IndexFreeListTypeByte);
     if (p == limit)
         return 0;
@@ -1326,7 +1340,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == ObjectStoreNamesTypeByte);
     return decodeStringWithLength(p, limit, result->m_objectStoreName);
 }
@@ -1363,7 +1378,8 @@
     ASSERT(!prefix.m_indexId);
     if (p == limit)
         return 0;
-    unsigned char typeByte = *p++;
+    unsigned char typeByte;
+    p = decodeByte(p, limit, typeByte);
     ASSERT_UNUSED(typeByte, typeByte == IndexNamesKeyTypeByte);
     if (p == limit)
         return 0;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.h (124401 => 124402)


--- trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.h	2012-08-02 02:31:18 UTC (rev 124401)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.h	2012-08-02 03:08:10 UTC (rev 124402)
@@ -44,6 +44,7 @@
 const unsigned char MinimumIndexId = 30;
 
 Vector<char> encodeByte(unsigned char);
+const char* decodeByte(const char* p, const char* limit, unsigned char& foundChar);
 Vector<char> maxIDBKey();
 Vector<char> minIDBKey();
 Vector<char> encodeBool(bool);
@@ -161,16 +162,16 @@
 
     ObjectStoreMetaDataKey();
     static const char* decode(const char* start, const char* limit, ObjectStoreMetaDataKey* result);
-    static Vector<char> encode(int64_t databaseId, int64_t objectStoreId, int64_t metaDataType);
+    static Vector<char> encode(int64_t databaseId, int64_t objectStoreId, unsigned char metaDataType);
     static Vector<char> encodeMaxKey(int64_t databaseId);
     static Vector<char> encodeMaxKey(int64_t databaseId, int64_t objectStoreId);
     int64_t objectStoreId() const;
-    int64_t metaDataType() const;
+    unsigned char metaDataType() const;
     int compare(const ObjectStoreMetaDataKey& other);
 
 private:
     int64_t m_objectStoreId;
-    int64_t m_metaDataType; // FIXME: Make this a byte.
+    unsigned char m_metaDataType;
 };
 
 class IndexMetaDataKey {

Modified: trunk/Source/WebKit/chromium/ChangeLog (124401 => 124402)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-08-02 02:31:18 UTC (rev 124401)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-08-02 03:08:10 UTC (rev 124402)
@@ -1,3 +1,18 @@
+2012-08-01  Xingnan Wang  <[email protected]>
+
+        IndexedDB: ObjectStoreMetaDataKey::m_metaDataType should use byte type
+        https://bugs.webkit.org/show_bug.cgi?id=92725
+
+        Reviewed by Kentaro Hara.
+
+        Add two new tests in IDBLevelDBCodingTest.cpp. One for an added function decodeByte() and 
+        another for verifying that encodeByte() and encodeVarInt() are indentical when the encoded 
+        values are <= 127.
+
+        * tests/IDBLevelDBCodingTest.cpp:
+        (IDBLevelDBCoding::TEST):
+        (IDBLevelDBCoding):
+
 2012-08-01  James Robinson  <[email protected]>
 
         [chromium] Use new-style tracing macros with explicit category

Modified: trunk/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp (124401 => 124402)


--- trunk/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp	2012-08-02 02:31:18 UTC (rev 124401)
+++ trunk/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp	2012-08-02 03:08:10 UTC (rev 124402)
@@ -84,6 +84,24 @@
     EXPECT_EQ(expected, encodeByte(c));
 }
 
+TEST(IDBLevelDBCodingTest, DecodeByte)
+{
+    Vector<unsigned char> testCases;
+    testCases.append(0);
+    testCases.append(1);
+    testCases.append(255);
+
+    for (size_t i = 0; i < testCases.size(); ++i) {
+        unsigned char n = testCases[i];
+        Vector<char> v = encodeByte(n);
+
+        unsigned char res;
+        const char* p = decodeByte(v.data(), v.data() + v.size(), res);
+        EXPECT_EQ(n, res);
+        EXPECT_EQ(v.data() + v.size(), p);
+    }
+}
+   
 TEST(IDBLevelDBCodingTest, EncodeBool)
 {
     {
@@ -682,6 +700,24 @@
     }
 }
 
+TEST(IDBLevelDBCodingTest, EncodeVarIntVSEncodeByteTest)
+{
+    Vector<unsigned char> testCases;
+    testCases.append(0);
+    testCases.append(1);
+    testCases.append(127);
+
+    for (size_t i = 0; i < testCases.size(); ++i) {
+        unsigned char n = testCases[i];
+
+        Vector<char> vA = encodeByte(n);
+        Vector<char> vB = encodeVarInt(static_cast<int64_t>(n));
+
+        EXPECT_EQ(vA.size(), vB.size());
+        EXPECT_EQ(*(vA.data()), *(vB.data()));
+    }
+}
+
 } // namespace
 
 #endif // USE(LEVELDB)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to