Title: [201660] trunk/Source/WebCore
Revision
201660
Author
beid...@apple.com
Date
2016-06-03 14:42:03 -0700 (Fri, 03 Jun 2016)

Log Message

Miscellaneous IDBBindingUtilities cleanup.
https://bugs.webkit.org/show_bug.cgi?id=158353

Reviewed by Tim Horton.

No new tests (Straight refactor, yo).

Starting with removing a single form of scriptValueToIDBKey(), and making the return value be
Ref<IDBKey> instead of RefPtr<IDBKey>, update a whole bunch of code to understand that the ExecState
is non-null and the resulting key is non-null.

* Modules/indexeddb/IDBCursor.cpp:
(WebCore::IDBCursor::continueFunction):

* Modules/indexeddb/IDBFactory.cpp:
(WebCore::IDBFactory::cmp):

* Modules/indexeddb/IDBIndex.cpp:
(WebCore::IDBIndex::count):
(WebCore::IDBIndex::get):
(WebCore::IDBIndex::getKey):

* Modules/indexeddb/IDBKey.cpp:
(WebCore::IDBKey::compare):
(WebCore::IDBKey::isLessThan):
(WebCore::IDBKey::isEqual):
* Modules/indexeddb/IDBKey.h:
(WebCore::IDBKey::createMultiEntryArray):

* Modules/indexeddb/IDBKeyRange.cpp:
(WebCore::IDBKeyRange::only):
(WebCore::IDBKeyRange::lowerBound):
(WebCore::IDBKeyRange::upperBound):
(WebCore::IDBKeyRange::bound):
(WebCore::IDBKeyRange::isOnlyKey):

* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::get):
(WebCore::IDBObjectStore::modernDelete):
(WebCore::IDBObjectStore::count):

* bindings/js/IDBBindingUtilities.cpp:
(WebCore::get):
(WebCore::set):
(WebCore::createIDBKeyFromValue):
(WebCore::getNthValueOnKeyPath):
(WebCore::internalCreateIDBKeyFromScriptValueAndKeyPath):
(WebCore::ensureNthValueOnKeyPath):
(WebCore::canInjectNthValueOnKeyPath):
(WebCore::injectIDBKeyIntoScriptValue):
(WebCore::maybeCreateIDBKeyFromScriptValueAndKeyPath):
(WebCore::canInjectIDBKeyIntoScriptValue):
(WebCore::deserializeIDBValueToJSValue):
(WebCore::scriptValueToIDBKey):
(WebCore::createKeyPathArray):
* bindings/js/IDBBindingUtilities.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201659 => 201660)


--- trunk/Source/WebCore/ChangeLog	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/ChangeLog	2016-06-03 21:42:03 UTC (rev 201660)
@@ -1,3 +1,62 @@
+2016-06-03  Brady Eidson  <beid...@apple.com>
+
+        Miscellaneous IDBBindingUtilities cleanup.
+        https://bugs.webkit.org/show_bug.cgi?id=158353
+
+        Reviewed by Tim Horton.
+
+        No new tests (Straight refactor, yo).
+
+        Starting with removing a single form of scriptValueToIDBKey(), and making the return value be
+        Ref<IDBKey> instead of RefPtr<IDBKey>, update a whole bunch of code to understand that the ExecState
+        is non-null and the resulting key is non-null.
+        
+        * Modules/indexeddb/IDBCursor.cpp:
+        (WebCore::IDBCursor::continueFunction):
+        
+        * Modules/indexeddb/IDBFactory.cpp:
+        (WebCore::IDBFactory::cmp):
+        
+        * Modules/indexeddb/IDBIndex.cpp:
+        (WebCore::IDBIndex::count):
+        (WebCore::IDBIndex::get):
+        (WebCore::IDBIndex::getKey):
+        
+        * Modules/indexeddb/IDBKey.cpp:
+        (WebCore::IDBKey::compare):
+        (WebCore::IDBKey::isLessThan):
+        (WebCore::IDBKey::isEqual):
+        * Modules/indexeddb/IDBKey.h:
+        (WebCore::IDBKey::createMultiEntryArray):
+        
+        * Modules/indexeddb/IDBKeyRange.cpp:
+        (WebCore::IDBKeyRange::only):
+        (WebCore::IDBKeyRange::lowerBound):
+        (WebCore::IDBKeyRange::upperBound):
+        (WebCore::IDBKeyRange::bound):
+        (WebCore::IDBKeyRange::isOnlyKey):
+        
+        * Modules/indexeddb/IDBObjectStore.cpp:
+        (WebCore::IDBObjectStore::get):
+        (WebCore::IDBObjectStore::modernDelete):
+        (WebCore::IDBObjectStore::count):
+        
+        * bindings/js/IDBBindingUtilities.cpp:
+        (WebCore::get):
+        (WebCore::set):
+        (WebCore::createIDBKeyFromValue):
+        (WebCore::getNthValueOnKeyPath):
+        (WebCore::internalCreateIDBKeyFromScriptValueAndKeyPath):
+        (WebCore::ensureNthValueOnKeyPath):
+        (WebCore::canInjectNthValueOnKeyPath):
+        (WebCore::injectIDBKeyIntoScriptValue):
+        (WebCore::maybeCreateIDBKeyFromScriptValueAndKeyPath):
+        (WebCore::canInjectIDBKeyIntoScriptValue):
+        (WebCore::deserializeIDBValueToJSValue):
+        (WebCore::scriptValueToIDBKey):
+        (WebCore::createKeyPathArray):
+        * bindings/js/IDBBindingUtilities.h:
+
 2016-06-03  Benjamin Poulain  <benja...@webkit.org>
 
         Rename CheckedRadioButtons into RadioButtonGroups

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -269,9 +269,16 @@
 
 void IDBCursor::continueFunction(ScriptExecutionContext& context, JSValue keyValue, ExceptionCodeWithMessage& ec)
 {
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'continue' on 'IDBCursor': Script execution context does not have an execution state.");
+        return;
+    }
+
     RefPtr<IDBKey> key;
     if (!keyValue.isUndefined())
-        key = scriptValueToIDBKey(context, keyValue);
+        key = scriptValueToIDBKey(*exec, keyValue);
 
     continueFunction(key.get(), ec);
 }

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -144,11 +144,15 @@
 
 short IDBFactory::cmp(ScriptExecutionContext& context, JSValue firstValue, JSValue secondValue, ExceptionCodeWithMessage& ec)
 {
-    RefPtr<IDBKey> first = scriptValueToIDBKey(context, firstValue);
-    RefPtr<IDBKey> second = scriptValueToIDBKey(context, secondValue);
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'cmp' on 'IDBFactory': Script execution context does not have an execution state.");
+        return 0;
+    }
 
-    ASSERT(first);
-    ASSERT(second);
+    Ref<IDBKey> first = scriptValueToIDBKey(*exec, firstValue);
+    Ref<IDBKey> second = scriptValueToIDBKey(*exec, secondValue);
 
     if (!first->isValid() || !second->isValid()) {
         ec.code = IDBDatabaseException::DataError;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBIndex.cpp (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBIndex.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBIndex.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -160,14 +160,21 @@
 {
     LOG(IndexedDB, "IDBIndex::count");
 
-    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(context, key);
-    if (!idbKey || idbKey->type() == KeyType::Invalid) {
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBIndex': Script execution context does not have an execution state.");
+        return 0;
+    }
+
+    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
+    if (!idbKey->isValid()) {
         ec.code = IDBDatabaseException::DataError;
         ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBIndex': The parameter is not a valid key.");
         return nullptr;
     }
 
-    return doCount(context, IDBKeyRangeData(idbKey.get()), ec);
+    return doCount(context, IDBKeyRangeData(idbKey.ptr()), ec);
 }
 
 RefPtr<IDBRequest> IDBIndex::doCount(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)
@@ -244,14 +251,21 @@
 {
     LOG(IndexedDB, "IDBIndex::get");
 
-    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(context, key);
-    if (!idbKey || idbKey->type() == KeyType::Invalid) {
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBIndex': Script execution context does not have an execution state.");
+        return nullptr;
+    }
+
+    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
+    if (!idbKey->isValid()) {
         ec.code = IDBDatabaseException::DataError;
         ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key.");
         return nullptr;
     }
 
-    return doGet(context, IDBKeyRangeData(idbKey.get()), ec);
+    return doGet(context, IDBKeyRangeData(idbKey.ptr()), ec);
 }
 
 RefPtr<IDBRequest> IDBIndex::doGet(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)
@@ -290,14 +304,21 @@
 {
     LOG(IndexedDB, "IDBIndex::getKey");
 
-    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(context, key);
-    if (!idbKey || idbKey->type() == KeyType::Invalid) {
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBIndex': Script execution context does not have an execution state.");
+        return nullptr;
+    }
+
+    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
+    if (!idbKey->isValid()) {
         ec.code = IDBDatabaseException::DataError;
         ec.message = ASCIILiteral("Failed to execute 'getKey' on 'IDBIndex': The parameter is not a valid key.");
         return nullptr;
     }
 
-    return doGetKey(context, IDBKeyRangeData(idbKey.get()), ec);
+    return doGetKey(context, IDBKeyRangeData(idbKey.ptr()), ec);
 }
 
 RefPtr<IDBRequest> IDBIndex::doGetKey(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKey.cpp (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKey.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKey.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -51,29 +51,27 @@
     return true;
 }
 
-int IDBKey::compare(const IDBKey* other) const
+int IDBKey::compare(const IDBKey& other) const
 {
-    ASSERT(other);
-    if (m_type != other->m_type)
-        return m_type > other->m_type ? -1 : 1;
+    if (m_type != other.m_type)
+        return m_type > other.m_type ? -1 : 1;
 
     switch (m_type) {
     case KeyType::Array:
-        for (size_t i = 0; i < m_array.size() && i < other->m_array.size(); ++i) {
-            if (int result = m_array[i]->compare(other->m_array[i].get()))
+        for (size_t i = 0; i < m_array.size() && i < other.m_array.size(); ++i) {
+            if (int result = m_array[i]->compare(*other.m_array[i]))
                 return result;
         }
-        if (m_array.size() < other->m_array.size())
+        if (m_array.size() < other.m_array.size())
             return -1;
-        if (m_array.size() > other->m_array.size())
+        if (m_array.size() > other.m_array.size())
             return 1;
         return 0;
     case KeyType::String:
-        return -codePointCompare(other->m_string, m_string);
+        return -codePointCompare(other.m_string, m_string);
     case KeyType::Date:
     case KeyType::Number:
-        return (m_number < other->m_number) ? -1 :
-                (m_number > other-> m_number) ? 1 : 0;
+        return (m_number < other.m_number) ? -1 : ((m_number > other. m_number) ? 1 : 0);
     case KeyType::Invalid:
     case KeyType::Min:
     case KeyType::Max:
@@ -85,17 +83,13 @@
     return 0;
 }
 
-bool IDBKey::isLessThan(const IDBKey* other) const
+bool IDBKey::isLessThan(const IDBKey& other) const
 {
-    ASSERT(other);
     return compare(other) == -1;
 }
 
-bool IDBKey::isEqual(const IDBKey* other) const
+bool IDBKey::isEqual(const IDBKey& other) const
 {
-    if (!other)
-        return false;
-
     return !compare(other);
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKey.h (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKey.h	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKey.h	2016-06-03 21:42:03 UTC (rev 201660)
@@ -71,7 +71,7 @@
 
             bool skip = false;
             for (auto& resultKey : result) {
-                if (key->isEqual(resultKey.get())) {
+                if (key->isEqual(*resultKey)) {
                     skip = true;
                     break;
                 }
@@ -124,9 +124,9 @@
         return m_number;
     }
 
-    int compare(const IDBKey* other) const;
-    bool isLessThan(const IDBKey* other) const;
-    bool isEqual(const IDBKey* other) const;
+    int compare(const IDBKey& other) const;
+    bool isLessThan(const IDBKey& other) const;
+    bool isEqual(const IDBKey& other) const;
 
     size_t sizeEstimate() const { return m_sizeEstimate; }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -32,6 +32,7 @@
 #include "IDBDatabaseException.h"
 #include "IDBKey.h"
 #include "IDBKeyData.h"
+#include "ScriptExecutionContext.h"
 #include <runtime/JSCJSValue.h>
 
 using namespace JSC;
@@ -78,13 +79,17 @@
 
 RefPtr<IDBKeyRange> IDBKeyRange::only(ScriptExecutionContext& context, JSValue keyValue, ExceptionCode& ec)
 {
-    return only(scriptValueToIDBKey(context, keyValue), ec);
+    auto exec = context.execState();
+    if (!exec)
+        return nullptr;
+
+    return only(scriptValueToIDBKey(*exec, keyValue), ec);
 }
 
 RefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ExecState& state, JSValue boundValue, bool open, ExceptionCode& ec)
 {
     auto bound = scriptValueToIDBKey(state, boundValue);
-    if (!bound || !bound->isValid()) {
+    if (!bound->isValid()) {
         ec = IDBDatabaseException::DataError;
         return nullptr;
     }
@@ -95,7 +100,7 @@
 RefPtr<IDBKeyRange> IDBKeyRange::upperBound(ExecState& state, JSValue boundValue, bool open, ExceptionCode& ec)
 {
     auto bound = scriptValueToIDBKey(state, boundValue);
-    if (!bound || !bound->isValid()) {
+    if (!bound->isValid()) {
         ec = IDBDatabaseException::DataError;
         return nullptr;
     }
@@ -108,7 +113,7 @@
     auto lower = scriptValueToIDBKey(state, lowerValue);
     auto upper = scriptValueToIDBKey(state, upperValue);
 
-    if (!lower || !lower->isValid() || !upper || !upper->isValid()) {
+    if (!lower->isValid() || !upper->isValid()) {
         ec = IDBDatabaseException::DataError;
         return nullptr;
     }
@@ -126,7 +131,7 @@
 
 bool IDBKeyRange::isOnlyKey() const
 {
-    return m_lower && m_upper && !m_isLowerOpen && !m_isUpperOpen && m_lower->isEqual(m_upper.get());
+    return m_lower && m_upper && !m_isLowerOpen && !m_isUpperOpen && m_lower->isEqual(*m_upper);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp (201659 => 201660)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -165,6 +165,13 @@
     LOG(IndexedDB, "IDBObjectStore::get");
     ASSERT(currentThread() == m_transaction->database().originThreadID());
 
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': Script execution context does not have an execution state.");
+        return nullptr;
+    }
+
     if (!m_transaction->isActive()) {
         ec.code = IDBDatabaseException::TransactionInactiveError;
         ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': The transaction is inactive or finished.");
@@ -177,14 +184,14 @@
         return nullptr;
     }
 
-    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(context, key);
-    if (!idbKey || idbKey->type() == KeyType::Invalid) {
+    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
+    if (!idbKey->isValid()) {
         ec.code = IDBDatabaseException::DataError;
         ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': The parameter is not a valid key.");
         return nullptr;
     }
 
-    return m_transaction->requestGetRecord(context, *this, idbKey.get());
+    return m_transaction->requestGetRecord(context, *this, idbKey.ptr());
 }
 
 RefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext& context, IDBKeyRange* keyRange, ExceptionCodeWithMessage& ec)
@@ -389,14 +396,21 @@
 
 RefPtr<IDBRequest> IDBObjectStore::modernDelete(ScriptExecutionContext& context, JSValue key, ExceptionCodeWithMessage& ec)
 {
-    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(context, key);
-    if (!idbKey || idbKey->type() == KeyType::Invalid) {
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'delete' on 'IDBObjectStore': Script execution context does not have an execution state.");
+        return nullptr;
+    }
+
+    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
+    if (!idbKey->isValid()) {
         ec.code = IDBDatabaseException::DataError;
         ec.message = ASCIILiteral("Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key.");
         return nullptr;
     }
 
-    return doDelete(context, &IDBKeyRange::create(idbKey.releaseNonNull()).get(), ec);
+    return doDelete(context, &IDBKeyRange::create(WTFMove(idbKey)).get(), ec);
 }
 
 RefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext& context, ExceptionCodeWithMessage& ec)
@@ -580,14 +594,21 @@
 {
     LOG(IndexedDB, "IDBObjectStore::count");
 
-    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(context, key);
-    if (!idbKey || idbKey->type() == KeyType::Invalid) {
+    auto exec = context.execState();
+    if (!exec) {
+        ec.code = IDBDatabaseException::UnknownError;
+        ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBObjectStore': Script execution context does not have an execution state.");
+        return nullptr;
+    }
+
+    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
+    if (!idbKey->isValid()) {
         ec.code = IDBDatabaseException::DataError;
         ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key.");
         return nullptr;
     }
 
-    return doCount(context, IDBKeyRangeData(idbKey.get()), ec);
+    return doCount(context, IDBKeyRangeData(idbKey.ptr()), ec);
 }
 
 RefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext& context, IDBKeyRange* range, ExceptionCodeWithMessage& ec)

Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp (201659 => 201660)


--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp	2016-06-03 21:42:03 UTC (rev 201660)
@@ -50,18 +50,18 @@
 
 namespace WebCore {
 
-static bool get(ExecState* exec, JSValue object, const String& keyPathElement, JSValue& result)
+static bool get(ExecState& exec, JSValue object, const String& keyPathElement, JSValue& result)
 {
     if (object.isString() && keyPathElement == "length") {
-        result = jsNumber(object.toString(exec)->length());
+        result = jsNumber(object.toString(&exec)->length());
         return true;
     }
     if (!object.isObject())
         return false;
-    Identifier identifier = Identifier::fromString(&exec->vm(), keyPathElement);
-    if (!asObject(object)->hasProperty(exec, identifier))
+    Identifier identifier = Identifier::fromString(&exec.vm(), keyPathElement);
+    if (!asObject(object)->hasProperty(&exec, identifier))
         return false;
-    result = asObject(object)->get(exec, identifier);
+    result = asObject(object)->get(&exec, identifier);
     return true;
 }
 
@@ -71,12 +71,12 @@
     return object.isObject();
 }
 
-static bool set(ExecState* exec, JSValue& object, const String& keyPathElement, JSValue jsValue)
+static bool set(ExecState& exec, JSValue& object, const String& keyPathElement, JSValue jsValue)
 {
     if (!canSet(object, keyPathElement))
         return false;
-    Identifier identifier = Identifier::fromString(&exec->vm(), keyPathElement);
-    asObject(object)->putDirect(exec->vm(), identifier, jsValue);
+    Identifier identifier = Identifier::fromString(&exec.vm(), keyPathElement);
+    asObject(object)->putDirect(exec.vm(), identifier, jsValue);
     return true;
 }
 
@@ -118,14 +118,17 @@
 
 static const size_t maximumDepth = 2000;
 
-static RefPtr<IDBKey> createIDBKeyFromValue(ExecState* exec, JSValue value, Vector<JSArray*>& stack)
+static RefPtr<IDBKey> createIDBKeyFromValue(ExecState& exec, JSValue value, Vector<JSArray*>& stack)
 {
-    if (value.isNumber() && !std::isnan(value.toNumber(exec)))
-        return IDBKey::createNumber(value.toNumber(exec));
+    if (value.isNumber() && !std::isnan(value.toNumber(&exec)))
+        return IDBKey::createNumber(value.toNumber(&exec));
+
     if (value.isString())
-        return IDBKey::createString(value.toString(exec)->value(exec));
-    if (value.inherits(DateInstance::info()) && !std::isnan(valueToDate(exec, value)))
-        return IDBKey::createDate(valueToDate(exec, value));
+        return IDBKey::createString(value.toString(&exec)->value(&exec));
+
+    if (value.inherits(DateInstance::info()) && !std::isnan(valueToDate(&exec, value)))
+        return IDBKey::createDate(valueToDate(&exec, value));
+
     if (value.isObject()) {
         JSObject* object = asObject(value);
         if (isJSArray(object) || object->inherits(JSArray::info())) {
@@ -134,13 +137,15 @@
 
             if (stack.contains(array))
                 return nullptr;
+
             if (stack.size() >= maximumDepth)
                 return nullptr;
+
             stack.append(array);
 
             Vector<RefPtr<IDBKey>> subkeys;
             for (size_t i = 0; i < length; i++) {
-                JSValue item = array->getIndex(exec, i);
+                JSValue item = array->getIndex(&exec, i);
                 RefPtr<IDBKey> subkey = createIDBKeyFromValue(exec, item, stack);
                 if (!subkey)
                     subkeys.append(IDBKey::createInvalid());
@@ -155,12 +160,12 @@
     return nullptr;
 }
 
-static RefPtr<IDBKey> createIDBKeyFromValue(ExecState* exec, JSValue value)
+static Ref<IDBKey> createIDBKeyFromValue(ExecState& exec, JSValue value)
 {
     Vector<JSArray*> stack;
     RefPtr<IDBKey> key = createIDBKeyFromValue(exec, value, stack);
     if (key)
-        return key;
+        return *key;
     return IDBKey::createInvalid();
 }
 
@@ -174,7 +179,7 @@
     return keyPath;
 }
 
-static JSValue getNthValueOnKeyPath(ExecState* exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index)
+static JSValue getNthValueOnKeyPath(ExecState& exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index)
 {
     JSValue currentValue(rootValue);
     ASSERT(index <= keyPathElements.size());
@@ -186,7 +191,7 @@
     return currentValue;
 }
 
-static RefPtr<IDBKey> internalCreateIDBKeyFromScriptValueAndKeyPath(ExecState* exec, const JSValue& value, const String& keyPath)
+static RefPtr<IDBKey> internalCreateIDBKeyFromScriptValueAndKeyPath(ExecState& exec, const JSValue& value, const String& keyPath)
 {
     Vector<String> keyPathElements;
     IDBKeyPathParseError error;
@@ -200,7 +205,7 @@
     return createIDBKeyFromValue(exec, jsValue);
 }
 
-static JSValue ensureNthValueOnKeyPath(ExecState* exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index)
+static JSValue ensureNthValueOnKeyPath(ExecState& exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index)
 {
     JSValue currentValue(rootValue);
 
@@ -209,7 +214,7 @@
         JSValue parentValue(currentValue);
         const String& keyPathElement = keyPathElements[i];
         if (!get(exec, parentValue, keyPathElement, currentValue)) {
-            JSObject* object = constructEmptyObject(exec);
+            JSObject* object = constructEmptyObject(&exec);
             if (!set(exec, parentValue, keyPathElement, JSValue(object)))
                 return jsUndefined();
             currentValue = JSValue(object);
@@ -219,7 +224,7 @@
     return currentValue;
 }
 
-static bool canInjectNthValueOnKeyPath(ExecState* exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index)
+static bool canInjectNthValueOnKeyPath(ExecState& exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index)
 {
     if (!rootValue.isObject())
         return false;
@@ -250,7 +255,7 @@
     if (keyPathElements.isEmpty())
         return false;
 
-    JSValue parent = ensureNthValueOnKeyPath(&exec, value, keyPathElements, keyPathElements.size() - 1);
+    JSValue parent = ensureNthValueOnKeyPath(exec, value, keyPathElements, keyPathElements.size() - 1);
     if (parent.isUndefined())
         return false;
 
@@ -258,7 +263,7 @@
     if (!key)
         return false;
 
-    if (!set(&exec, parent, keyPathElements.last(), toJS(exec, *exec.lexicalGlobalObject(), key.get())))
+    if (!set(exec, parent, keyPathElements.last(), toJS(exec, *exec.lexicalGlobalObject(), key.get())))
         return false;
 
     return true;
@@ -274,7 +279,7 @@
         Vector<RefPtr<IDBKey>> result;
         result.reserveInitialCapacity(array.size());
         for (auto& string : array) {
-            RefPtr<IDBKey> key = internalCreateIDBKeyFromScriptValueAndKeyPath(&exec, value, string);
+            RefPtr<IDBKey> key = internalCreateIDBKeyFromScriptValueAndKeyPath(exec, value, string);
             if (!key)
                 return nullptr;
             result.uncheckedAppend(WTFMove(key));
@@ -283,10 +288,10 @@
     }
 
     ASSERT(keyPath.type() == IDBKeyPath::Type::String);
-    return internalCreateIDBKeyFromScriptValueAndKeyPath(&exec, value, keyPath.string());
+    return internalCreateIDBKeyFromScriptValueAndKeyPath(exec, value, keyPath.string());
 }
 
-bool canInjectIDBKeyIntoScriptValue(ExecState& execState, const JSValue& scriptValue, const IDBKeyPath& keyPath)
+bool canInjectIDBKeyIntoScriptValue(ExecState& exec, const JSValue& scriptValue, const IDBKeyPath& keyPath)
 {
     LOG(StorageAPI, "canInjectIDBKeyIntoScriptValue");
 
@@ -299,11 +304,11 @@
     if (!keyPathElements.size())
         return false;
 
-    return canInjectNthValueOnKeyPath(&execState, scriptValue, keyPathElements, keyPathElements.size() - 1);
+    return canInjectNthValueOnKeyPath(exec, scriptValue, keyPathElements, keyPathElements.size() - 1);
 }
 
 
-static JSValue deserializeIDBValueToJSValue(ExecState& state, const IDBValue& value)
+static JSValue deserializeIDBValueToJSValue(ExecState& exec, const IDBValue& value)
 {
     // FIXME: I think it's peculiar to use undefined to mean "null data" and null to mean "empty data".
     // But I am not changing this at the moment because at least some callers are specifically checking isUndefined.
@@ -317,9 +322,9 @@
 
     auto serializedValue = SerializedScriptValue::createFromWireBytes(Vector<uint8_t>(data));
 
-    state.vm().apiLock().lock();
-    JSValue result = serializedValue->deserialize(&state, state.lexicalGlobalObject(), 0, NonThrowing, value.blobURLs(), value.blobFilePaths());
-    state.vm().apiLock().unlock();
+    exec.vm().apiLock().lock();
+    JSValue result = serializedValue->deserialize(&exec, exec.lexicalGlobalObject(), 0, NonThrowing, value.blobURLs(), value.blobFilePaths());
+    exec.vm().apiLock().unlock();
 
     return result;
 }
@@ -328,11 +333,11 @@
 {
     // FIXME: I think it's peculiar to return an empty JSValue, undefined, and null for three different error cases.
 
-    auto* execState = context.execState();
-    if (!execState)
+    auto* exec = context.execState();
+    if (!exec)
         return { };
 
-    return deserializeIDBValueToJSValue(*execState, value);
+    return deserializeIDBValueToJSValue(*exec, value);
 }
 
 JSValue deserializeIDBValueDataToJSValue(ExecState& exec, const ThreadSafeDataBuffer& valueData)
@@ -340,17 +345,11 @@
     return deserializeIDBValueToJSValue(exec, IDBValue(valueData));
 }
 
-RefPtr<IDBKey> scriptValueToIDBKey(ExecState& exec, const JSValue& scriptValue)
+Ref<IDBKey> scriptValueToIDBKey(ExecState& exec, const JSValue& scriptValue)
 {
-    return createIDBKeyFromValue(&exec, scriptValue);
+    return createIDBKeyFromValue(exec, scriptValue);
 }
 
-RefPtr<IDBKey> scriptValueToIDBKey(ScriptExecutionContext& context, const JSValue& scriptValue)
-{
-    auto* execState = context.execState();
-    return execState ? scriptValueToIDBKey(*execState, scriptValue) : nullptr;
-}
-
 JSC::JSValue idbKeyDataToScriptValue(ScriptExecutionContext& context, const IDBKeyData& keyData)
 {
     RefPtr<IDBKey> key = keyData.maybeCreateIDBKey();
@@ -369,14 +368,14 @@
     switch (info.keyPath().type()) {
     case IDBKeyPath::Type::Array:
         for (auto& entry : info.keyPath().array()) {
-            auto key = internalCreateIDBKeyFromScriptValueAndKeyPath(&exec, value, entry);
+            auto key = internalCreateIDBKeyFromScriptValueAndKeyPath(exec, value, entry);
             if (!key)
                 return { };
             keys.append(key.get());
         }
         break;
     case IDBKeyPath::Type::String: {
-        auto idbKey = internalCreateIDBKeyFromScriptValueAndKeyPath(&exec, value, info.keyPath().string());
+        auto idbKey = internalCreateIDBKeyFromScriptValueAndKeyPath(exec, value, info.keyPath().string());
         if (!idbKey)
             return { };
 

Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h (201659 => 201660)


--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h	2016-06-03 21:36:51 UTC (rev 201659)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h	2016-06-03 21:42:03 UTC (rev 201660)
@@ -62,8 +62,7 @@
 JSC::JSValue deserializeIDBValueToJSValue(ScriptExecutionContext&, const IDBValue&);
 JSC::JSValue deserializeIDBValueDataToJSValue(JSC::ExecState&, const ThreadSafeDataBuffer& valueData);
 
-RefPtr<IDBKey> scriptValueToIDBKey(ScriptExecutionContext&, const JSC::JSValue&);
-RefPtr<IDBKey> scriptValueToIDBKey(JSC::ExecState&, const JSC::JSValue&);
+Ref<IDBKey> scriptValueToIDBKey(JSC::ExecState&, const JSC::JSValue&);
 
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to