Index: Source/WebCore/bindings/v8/IDBBindingUtilities.cpp |
=================================================================== |
--- Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (revision 132819) |
+++ Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (working copy) |
@@ -35,7 +35,6 @@ |
#include "SerializedScriptValue.h" |
#include "V8Binding.h" |
#include "V8IDBKey.h" |
-#include "WorldContextHandle.h" |
#include <wtf/MathExtras.h> |
#include <wtf/Vector.h> |
@@ -86,8 +85,10 @@ |
return IDBKey::createInvalid(); |
} |
+namespace { |
+ |
template<typename T> |
-static bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value) |
+bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value) |
{ |
v8::Local<v8::Object> object = v8Value->ToObject(); |
if (!object->Has(indexOrName)) |
@@ -97,72 +98,49 @@ |
} |
template<typename T> |
-static bool setValue(v8::Handle<v8::Value>& v8Object, T indexOrName, const v8::Handle<v8::Value>& v8Value) |
+bool setValue(v8::Handle<v8::Value>& v8Object, T indexOrName, const v8::Handle<v8::Value>& v8Value) |
{ |
v8::Local<v8::Object> object = v8Object->ToObject(); |
return object->Set(indexOrName, v8Value); |
} |
-static bool get(v8::Handle<v8::Value>& object, const String& keyPathElement, v8::Handle<v8::Value>& result) |
+bool get(v8::Handle<v8::Value>& object, const String& keyPathElement) |
{ |
if (object->IsString() && keyPathElement == "length") { |
int32_t length = v8::Handle<v8::String>::Cast(object)->Length(); |
- result = v8::Number::New(length); |
+ object = v8::Number::New(length); |
return true; |
} |
- return object->IsObject() && getValueFrom(v8String(keyPathElement), result); |
+ return object->IsObject() && getValueFrom(v8String(keyPathElement), object); |
} |
-static bool canSet(v8::Handle<v8::Value>& object, const String& keyPathElement) |
+bool set(v8::Handle<v8::Value>& object, const String& keyPathElement, const v8::Handle<v8::Value>& v8Value) |
{ |
- return object->IsObject(); |
+ return object->IsObject() && setValue(object, v8String(keyPathElement), v8Value); |
} |
-static bool set(v8::Handle<v8::Value>& object, const String& keyPathElement, const v8::Handle<v8::Value>& v8Value) |
+v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index) |
{ |
- return canSet(object, keyPathElement) && setValue(object, v8String(keyPathElement), v8Value); |
-} |
- |
-static v8::Handle<v8::Value> getNthValueOnKeyPath(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)) |
+ if (!get(currentValue, keyPathElements[i])) |
return v8Undefined(); |
} |
return currentValue; |
} |
-static bool canInjectNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index) |
+v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index) |
{ |
- if (!rootValue->IsObject()) |
- return false; |
- |
v8::Handle<v8::Value> currentValue(rootValue); |
ASSERT(index <= keyPathElements.size()); |
for (size_t i = 0; i < index; ++i) { |
v8::Handle<v8::Value> parentValue(currentValue); |
const String& keyPathElement = keyPathElements[i]; |
- if (!get(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::Handle<v8::Value> currentValue(rootValue); |
- |
- ASSERT(index <= keyPathElements.size()); |
- for (size_t i = 0; i < index; ++i) { |
- v8::Handle<v8::Value> parentValue(currentValue); |
- const String& keyPathElement = keyPathElements[i]; |
- if (!get(parentValue, keyPathElement, currentValue)) { |
+ if (!get(currentValue, keyPathElement)) { |
v8::Handle<v8::Object> object = v8::Object::New(); |
if (!set(parentValue, keyPathElement, object)) |
return v8Undefined(); |
@@ -173,42 +151,8 @@ |
return currentValue; |
} |
-static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& value, const String& keyPath) |
-{ |
- Vector<String> keyPathElements; |
- IDBKeyPathParseError error; |
- IDBParseKeyPath(keyPath, keyPathElements, error); |
- ASSERT(error == IDBKeyPathParseErrorNone); |
+} // anonymous namespace |
- v8::Handle<v8::Value> v8Value(value.v8Value()); |
- v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size())); |
- if (v8Key.IsEmpty()) |
- return 0; |
- return createIDBKeyFromValue(v8Key); |
-} |
- |
-PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& value, const IDBKeyPath& keyPath) |
-{ |
- IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); |
- ASSERT(!keyPath.isNull()); |
- |
- v8::HandleScope scope; |
- if (keyPath.type() == IDBKeyPath::ArrayType) { |
- 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]); |
- if (!key) |
- return 0; |
- result.append(key); |
- } |
- return IDBKey::createArray(result); |
- } |
- |
- ASSERT(keyPath.type() == IDBKeyPath::StringType); |
- return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string()); |
-} |
- |
static PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> prpValue, const String& keyPath) |
{ |
Vector<String> keyPathElements; |
@@ -228,13 +172,6 @@ |
return createIDBKeyFromValue(v8Key); |
} |
-// FIXME: The only reason this exists is because we need a v8::Context and scope inside a timer. Is there a better / more general way to do this? |
-ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPtr<SerializedScriptValue> prpValue) |
-{ |
- v8::HandleScope handleScope; |
- v8::Context::Scope contextScope(toV8Context(scriptContext, UseCurrentWorld)); |
- return ScriptValue(prpValue->deserialize()); |
-} |
PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> prpValue, const IDBKeyPath& keyPath) |
{ |
@@ -286,22 +223,6 @@ |
return SerializedScriptValue::create(v8Value); |
} |
-bool canInjectIDBKeyIntoScriptValue(const ScriptValue& scriptValue, const IDBKeyPath& keyPath) |
-{ |
- IDB_TRACE("canInjectIDBKeyIntoScriptValue"); |
- ASSERT(keyPath.type() == IDBKeyPath::StringType); |
- Vector<String> keyPathElements; |
- IDBKeyPathParseError error; |
- IDBParseKeyPath(keyPath.string(), keyPathElements, error); |
- ASSERT(error == IDBKeyPathParseErrorNone); |
- |
- if (!keyPathElements.size()) |
- return false; |
- |
- v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); |
- return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1); |
-} |
- |
} // namespace WebCore |
#endif |
Property changes on: Source/WebCore/bindings/v8/IDBBindingUtilities.cpp |
___________________________________________________________________ |
Added: svn:mergeinfo |
Merged /trunk/WebCore/bindings/v8/IDBBindingUtilities.cpp:r53455 |