Index: Source/core/html/DOMFormData.cpp |
diff --git a/Source/core/html/DOMFormData.cpp b/Source/core/html/DOMFormData.cpp |
index 9379f8cc520a2d0bc7fc233515ef6b550811c903..c53fd0430a29089ea15083c2a6058a8873851bfb 100644 |
--- a/Source/core/html/DOMFormData.cpp |
+++ b/Source/core/html/DOMFormData.cpp |
@@ -31,13 +31,58 @@ |
#include "config.h" |
#include "core/html/DOMFormData.h" |
+#include "bindings/core/v8/V8Binding.h" |
+#include "bindings/core/v8/V8File.h" |
+#include "core/dom/Iterator.h" |
Jens Widell
2015/01/15 07:35:06
You don't need to include this now, I think?
jsbell
2015/01/15 18:57:13
Done.
|
#include "core/fileapi/Blob.h" |
+#include "core/fileapi/File.h" |
#include "core/html/HTMLFormElement.h" |
#include "wtf/text/TextEncoding.h" |
#include "wtf/text/WTFString.h" |
namespace blink { |
+namespace { |
+ |
+ScriptValue entryValueToScriptValue(ScriptState* scriptState, const FormDataList::Entry& entry) |
+{ |
+ if (entry.isString()) |
+ return ScriptValue(scriptState, v8String(scriptState->isolate(), entry.string())); |
+ if (entry.isFile()) |
+ return ScriptValue(scriptState, toV8(entry.file(), scriptState->context()->Global(), scriptState->isolate())); |
+ ASSERT(entry.isNone()); |
+ return ScriptValue(scriptState, v8::Null(scriptState->isolate())); |
+} |
+ |
+class DOMFormDataIterationSource final : public PairIterable<String, ScriptValue>::IterationSource { |
+public: |
+ DOMFormDataIterationSource(DOMFormData* formData) : m_formData(formData), m_current(0) { } |
+ |
+ virtual bool next(ScriptState* scriptState, String& key, ScriptValue& value, ExceptionState& exceptionState) override |
+ { |
+ if (m_current >= m_formData->size()) |
+ return false; |
+ |
+ const FormDataList::Entry entry = m_formData->getEntry(m_current++); |
+ ASSERT(!entry.isNone()); |
+ key = entry.name(); |
+ value = entryValueToScriptValue(scriptState, entry); |
+ return true; |
+ } |
+ |
+ virtual void trace(Visitor* visitor) |
+ { |
+ PairIterable<String, ScriptValue>::IterationSource::trace(visitor); |
Jens Widell
2015/01/15 07:35:06
The convention is to make this a tail call, said h
jsbell
2015/01/15 18:57:13
Done.
|
+ visitor->trace(m_formData); |
+ } |
+ |
+private: |
+ const RefPtrWillBeMember<DOMFormData> m_formData; |
+ size_t m_current; |
+}; |
+ |
+} // namespace |
+ |
DOMFormData::DOMFormData(const WTF::TextEncoding& encoding) |
: FormDataList(encoding) |
{ |
@@ -66,4 +111,38 @@ void DOMFormData::append(const String& name, Blob* blob, const String& filename) |
appendBlob(name, blob, filename); |
} |
+ScriptValue DOMFormData::get(ScriptState* scriptState, const String& name) |
+{ |
+ return entryValueToScriptValue(scriptState, getEntry(name)); |
+} |
+ |
+Vector<ScriptValue> DOMFormData::getAll(ScriptState* scriptState, const String& name) |
+{ |
+ Vector<ScriptValue> results; |
+ WillBeHeapVector<FormDataList::Entry> entries = FormDataList::getAll(name); |
+ for (size_t i = 0; i < entries.size(); ++i) { |
+ const FormDataList::Entry& entry = entries[i]; |
+ ASSERT(!entry.isNone()); |
+ ASSERT(entry.name() == name); |
+ results.append(entryValueToScriptValue(scriptState, entry)); |
+ } |
+ ASSERT(results.size() == entries.size()); |
+ return results; |
+} |
+ |
+void DOMFormData::set(const String& name, const String& value) |
+{ |
+ setData(name, value); |
+} |
+ |
+void DOMFormData::set(const String& name, Blob* blob, const String& filename) |
+{ |
+ setBlob(name, blob, filename); |
+} |
+ |
+PairIterable<String, ScriptValue>::IterationSource* DOMFormData::startIteration(ScriptState*, ExceptionState&) |
+{ |
+ return new DOMFormDataIterationSource(this); |
+} |
+ |
} // namespace blink |