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

Unified Diff: Source/bindings/v8/IDBBindingUtilities.cpp

Issue 236773003: Completely remove DOMRequestState from IndexedDB code (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/IDBBindingUtilities.h ('k') | Source/bindings/v8/IDBBindingUtilitiesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/IDBBindingUtilities.cpp
diff --git a/Source/bindings/v8/IDBBindingUtilities.cpp b/Source/bindings/v8/IDBBindingUtilities.cpp
index 34e8bbe2375a13d3c10df3c15c23299618748d02..b2edd07dc0bc2560ce03abb51a18b2fca0953cce 100644
--- a/Source/bindings/v8/IDBBindingUtilities.cpp
+++ b/Source/bindings/v8/IDBBindingUtilities.cpp
@@ -36,7 +36,6 @@
#include "V8IDBObjectStore.h"
#include "V8IDBRequest.h"
#include "V8IDBTransaction.h"
-#include "bindings/v8/DOMRequestState.h"
#include "bindings/v8/SerializedScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8HiddenValue.h"
@@ -54,7 +53,7 @@
namespace WebCore {
-static v8::Handle<v8::Value> deserializeIDBValueBuffer(SharedBuffer*, v8::Isolate*);
+static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffer*);
static v8::Handle<v8::Value> toV8(const IDBKeyPath& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
@@ -144,7 +143,7 @@ static v8::Handle<v8::Value> toV8(const IDBAny* impl, v8::Handle<v8::Object> cre
case IDBAny::IDBTransactionType:
return toV8(impl->idbTransaction(), creationContext, isolate);
case IDBAny::BufferType:
- return deserializeIDBValueBuffer(impl->buffer(), isolate);
+ return deserializeIDBValueBuffer(isolate, impl->buffer());
case IDBAny::StringType:
return v8String(isolate, impl->string());
case IDBAny::IntegerType:
@@ -154,9 +153,9 @@ static v8::Handle<v8::Value> toV8(const IDBAny* impl, v8::Handle<v8::Object> cre
case IDBAny::KeyPathType:
return toV8(impl->keyPath(), creationContext, isolate);
case IDBAny::BufferKeyAndKeyPathType: {
- v8::Handle<v8::Value> value = deserializeIDBValueBuffer(impl->buffer(), isolate);
+ v8::Handle<v8::Value> value = deserializeIDBValueBuffer(isolate, impl->buffer());
v8::Handle<v8::Value> key = toV8(impl->key(), creationContext, isolate);
- bool injected = injectV8KeyIntoV8Value(key, value, impl->keyPath(), isolate);
+ bool injected = injectV8KeyIntoV8Value(isolate, key, value, impl->keyPath());
ASSERT_UNUSED(injected, injected);
return value;
}
@@ -168,7 +167,7 @@ static v8::Handle<v8::Value> toV8(const IDBAny* impl, v8::Handle<v8::Object> cre
static const size_t maximumDepth = 2000;
-static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vector<v8::Handle<v8::Array> >& stack, v8::Isolate* isolate, bool allowExperimentalTypes = false)
+static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Isolate* isolate, v8::Handle<v8::Value> value, Vector<v8::Handle<v8::Array> >& stack, bool allowExperimentalTypes = false)
{
if (value->IsNumber() && !std::isnan(value->NumberValue()))
return IDBKey::createNumber(value->NumberValue());
@@ -197,7 +196,7 @@ static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vec
uint32_t length = array->Length();
for (uint32_t i = 0; i < length; ++i) {
v8::Local<v8::Value> item = array->Get(v8::Int32::New(isolate, i));
- RefPtr<IDBKey> subkey = createIDBKeyFromValue(item, stack, isolate, allowExperimentalTypes);
+ RefPtr<IDBKey> subkey = createIDBKeyFromValue(isolate, item, stack, allowExperimentalTypes);
if (!subkey)
subkeys.append(IDBKey::createInvalid());
else
@@ -210,10 +209,10 @@ static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vec
return nullptr;
}
-static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, v8::Isolate* isolate, bool allowExperimentalTypes = false)
+static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Isolate* isolate, v8::Handle<v8::Value> value, bool allowExperimentalTypes = false)
{
Vector<v8::Handle<v8::Array> > stack;
- RefPtr<IDBKey> key = createIDBKeyFromValue(value, stack, isolate, allowExperimentalTypes);
+ RefPtr<IDBKey> key = createIDBKeyFromValue(isolate, value, stack, allowExperimentalTypes);
if (key)
return key;
return IDBKey::createInvalid();
@@ -236,7 +235,7 @@ static bool setValue(v8::Handle<v8::Value>& v8Object, T indexOrName, const v8::H
return object->Set(indexOrName, v8Value);
}
-static bool get(v8::Handle<v8::Value>& object, const String& keyPathElement, v8::Handle<v8::Value>& result, v8::Isolate* isolate)
+static bool get(v8::Isolate* isolate, v8::Handle<v8::Value>& object, const String& keyPathElement, v8::Handle<v8::Value>& result)
{
if (object->IsString() && keyPathElement == "length") {
int32_t length = v8::Handle<v8::String>::Cast(object)->Length();
@@ -251,25 +250,25 @@ static bool canSet(v8::Handle<v8::Value>& object, const String& keyPathElement)
return object->IsObject();
}
-static bool set(v8::Handle<v8::Value>& object, const String& keyPathElement, const v8::Handle<v8::Value>& v8Value, v8::Isolate* isolate)
+static bool set(v8::Isolate* isolate, v8::Handle<v8::Value>& object, const String& keyPathElement, const v8::Handle<v8::Value>& v8Value)
{
return canSet(object, keyPathElement) && setValue(object, v8String(isolate, keyPathElement), v8Value);
}
-static v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index, v8::Isolate* isolate)
+static v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Isolate* isolate, v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index)
{
v8::Handle<v8::Value> currentValue(rootValue);
ASSERT(index <= keyPathElements.size());
for (size_t i = 0; i < index; ++i) {
v8::Handle<v8::Value> parentValue(currentValue);
- if (!get(parentValue, keyPathElements[i], currentValue, isolate))
+ if (!get(isolate, parentValue, keyPathElements[i], currentValue))
return v8Undefined();
}
return currentValue;
}
-static bool canInjectNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index, v8::Isolate* isolate)
+static bool canInjectNthValueOnKeyPath(v8::Isolate* isolate, v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index)
{
if (!rootValue->IsObject())
return false;
@@ -280,14 +279,14 @@ static bool canInjectNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const V
for (size_t i = 0; i < index; ++i) {
v8::Handle<v8::Value> parentValue(currentValue);
const String& keyPathElement = keyPathElements[i];
- if (!get(parentValue, keyPathElement, currentValue, isolate))
+ if (!get(isolate, parentValue, keyPathElement, currentValue))
return canSet(parentValue, keyPathElement);
}
return true;
}
-static v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index, v8::Isolate* isolate)
+static v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Isolate* isolate, v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index)
{
v8::Handle<v8::Value> currentValue(rootValue);
@@ -295,9 +294,9 @@ static v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Handle<v8::Value>& root
for (size_t i = 0; i < index; ++i) {
v8::Handle<v8::Value> parentValue(currentValue);
const String& keyPathElement = keyPathElements[i];
- if (!get(parentValue, keyPathElement, currentValue, isolate)) {
+ if (!get(isolate, parentValue, keyPathElement, currentValue)) {
v8::Handle<v8::Object> object = v8::Object::New(isolate);
- if (!set(parentValue, keyPathElement, object, isolate))
+ if (!set(isolate, parentValue, keyPathElement, object))
return v8Undefined();
currentValue = object;
}
@@ -306,7 +305,7 @@ static v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Handle<v8::Value>& root
return currentValue;
}
-static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& value, const String& keyPath, v8::Isolate* isolate, bool allowExperimentalTypes)
+static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolate, const ScriptValue& value, const String& keyPath, bool allowExperimentalTypes)
{
Vector<String> keyPathElements;
IDBKeyPathParseError error;
@@ -316,13 +315,13 @@ static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValu
v8::HandleScope handleScope(isolate);
v8::Handle<v8::Value> v8Value(value.v8Value());
- v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size(), isolate));
+ v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPathElements.size()));
if (v8Key.IsEmpty())
return nullptr;
- return createIDBKeyFromValue(v8Key, isolate, allowExperimentalTypes);
+ return createIDBKeyFromValue(isolate, v8Key, allowExperimentalTypes);
}
-static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& value, const IDBKeyPath& keyPath, v8::Isolate* isolate, bool allowExperimentalTypes = false)
+static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolate, const ScriptValue& value, const IDBKeyPath& keyPath, bool allowExperimentalTypes = false)
{
ASSERT(!keyPath.isNull());
v8::HandleScope handleScope(isolate);
@@ -330,7 +329,7 @@ static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValu
IDBKey::KeyArray result;
const Vector<String>& array = keyPath.array();
for (size_t i = 0; i < array.size(); ++i) {
- RefPtr<IDBKey> key = createIDBKeyFromScriptValueAndKeyPath(value, array[i], isolate, allowExperimentalTypes);
+ RefPtr<IDBKey> key = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, array[i], allowExperimentalTypes);
if (!key)
return nullptr;
result.append(key);
@@ -339,17 +338,16 @@ static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValu
}
ASSERT(keyPath.type() == IDBKeyPath::StringType);
- return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string(), isolate, allowExperimentalTypes);
+ return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath.string(), allowExperimentalTypes);
}
-PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(DOMRequestState* state, const ScriptValue& value, const IDBKeyPath& keyPath)
+PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(v8::Isolate* isolate, const ScriptValue& value, const IDBKeyPath& keyPath)
{
IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath");
- v8::Isolate* isolate = state ? state->isolate() : v8::Isolate::GetCurrent();
- return createIDBKeyFromScriptValueAndKeyPath(value, keyPath, isolate);
+ return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath);
}
-static v8::Handle<v8::Value> deserializeIDBValueBuffer(SharedBuffer* buffer, v8::Isolate* isolate)
+static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, SharedBuffer* buffer)
{
ASSERT(isolate->InContext());
if (!buffer)
@@ -362,7 +360,7 @@ static v8::Handle<v8::Value> deserializeIDBValueBuffer(SharedBuffer* buffer, v8:
return serializedValue->deserialize(isolate, 0, 0);
}
-bool injectV8KeyIntoV8Value(v8::Handle<v8::Value> key, v8::Handle<v8::Value> value, const IDBKeyPath& keyPath, v8::Isolate* isolate)
+bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Handle<v8::Value> key, v8::Handle<v8::Value> value, const IDBKeyPath& keyPath)
{
IDB_TRACE("injectIDBV8KeyIntoV8Value");
ASSERT(isolate->InContext());
@@ -377,17 +375,17 @@ bool injectV8KeyIntoV8Value(v8::Handle<v8::Value> key, v8::Handle<v8::Value> val
return false;
v8::HandleScope handleScope(isolate);
- v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(value, keyPathElements, keyPathElements.size() - 1, isolate));
+ v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(isolate, value, keyPathElements, keyPathElements.size() - 1));
if (parent.IsEmpty())
return false;
- if (!set(parent, keyPathElements.last(), key, isolate))
+ if (!set(isolate, parent, keyPathElements.last(), key))
return false;
return true;
}
-bool canInjectIDBKeyIntoScriptValue(DOMRequestState* state, const ScriptValue& scriptValue, const IDBKeyPath& keyPath)
+bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scriptValue, const IDBKeyPath& keyPath)
{
IDB_TRACE("canInjectIDBKeyIntoScriptValue");
ASSERT(keyPath.type() == IDBKeyPath::StringType);
@@ -400,7 +398,7 @@ bool canInjectIDBKeyIntoScriptValue(DOMRequestState* state, const ScriptValue& s
return false;
v8::Handle<v8::Value> v8Value(scriptValue.v8Value());
- return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1, state->context()->GetIsolate());
+ return canInjectNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPathElements.size() - 1);
}
ScriptValue idbAnyToScriptValue(NewScriptState* scriptState, PassRefPtr<IDBAny> any)
@@ -419,40 +417,37 @@ ScriptValue idbKeyToScriptValue(NewScriptState* scriptState, PassRefPtr<IDBKey>
return ScriptValue(v8Value, isolate);
}
-PassRefPtr<IDBKey> scriptValueToIDBKey(DOMRequestState* state, const ScriptValue& scriptValue)
+PassRefPtr<IDBKey> scriptValueToIDBKey(v8::Isolate* isolate, const ScriptValue& scriptValue)
{
- v8::Isolate* isolate = state ? state->isolate() : v8::Isolate::GetCurrent();
ASSERT(isolate->InContext());
v8::HandleScope handleScope(isolate);
v8::Handle<v8::Value> v8Value(scriptValue.v8Value());
- return createIDBKeyFromValue(v8Value, isolate);
+ return createIDBKeyFromValue(isolate, v8Value);
}
-PassRefPtr<IDBKeyRange> scriptValueToIDBKeyRange(DOMRequestState* state, const ScriptValue& scriptValue)
+PassRefPtr<IDBKeyRange> scriptValueToIDBKeyRange(v8::Isolate* isolate, const ScriptValue& scriptValue)
{
- v8::Isolate* isolate = state ? state->isolate() : v8::Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
v8::Handle<v8::Value> value(scriptValue.v8Value());
return V8IDBKeyRange::toNativeWithTypeCheck(isolate, value);
}
#ifndef NDEBUG
-void assertPrimaryKeyValidOrInjectable(DOMRequestState* state, PassRefPtr<SharedBuffer> buffer, PassRefPtr<IDBKey> prpKey, const IDBKeyPath& keyPath)
+void assertPrimaryKeyValidOrInjectable(NewScriptState* scriptState, PassRefPtr<SharedBuffer> buffer, PassRefPtr<IDBKey> prpKey, const IDBKeyPath& keyPath)
{
RefPtr<IDBKey> key(prpKey);
- DOMRequestState::Scope scope(*state);
- v8::Isolate* isolate = state ? state->isolate() : v8::Isolate::GetCurrent();
-
- ScriptValue keyValue = idbKeyToScriptValue(state->scriptState(), key);
- ScriptValue scriptValue(deserializeIDBValueBuffer(buffer.get(), isolate), isolate);
+ NewScriptState::Scope scope(scriptState);
+ v8::Isolate* isolate = scriptState->isolate();
+ ScriptValue keyValue = idbKeyToScriptValue(scriptState, key);
+ ScriptValue scriptValue(deserializeIDBValueBuffer(isolate, buffer.get()), isolate);
// This assertion is about already persisted data, so allow experimental types.
const bool allowExperimentalTypes = true;
- RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPath(scriptValue, keyPath, isolate, allowExperimentalTypes);
+ RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, scriptValue, keyPath, allowExperimentalTypes);
ASSERT(!expectedKey || expectedKey->isEqual(key.get()));
- bool injected = injectV8KeyIntoV8Value(keyValue.v8Value(), scriptValue.v8Value(), keyPath, isolate);
+ bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptValue.v8Value(), keyPath);
ASSERT_UNUSED(injected, injected);
}
#endif
« no previous file with comments | « Source/bindings/v8/IDBBindingUtilities.h ('k') | Source/bindings/v8/IDBBindingUtilitiesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698