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

Unified Diff: third_party/WebKit/Source/core/dom/URLSearchParams.cpp

Issue 2725593003: Construct URLSearchParams from sequence initializer. (Closed)
Patch Set: style update Created 3 years, 10 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
Index: third_party/WebKit/Source/core/dom/URLSearchParams.cpp
diff --git a/third_party/WebKit/Source/core/dom/URLSearchParams.cpp b/third_party/WebKit/Source/core/dom/URLSearchParams.cpp
index 30ba1da486351f1baf909e7e40e874f864b3404d..8de28baf4f0cd8efad462c74fe61993109e34f73 100644
--- a/third_party/WebKit/Source/core/dom/URLSearchParams.cpp
+++ b/third_party/WebKit/Source/core/dom/URLSearchParams.cpp
@@ -4,6 +4,7 @@
#include "core/dom/URLSearchParams.h"
+#include <utility>
#include "core/dom/DOMURL.h"
#include "platform/network/FormDataEncoder.h"
#include "platform/weborigin/KURL.h"
@@ -39,20 +40,47 @@ class URLSearchParamsIterationSource final
} // namespace
-URLSearchParams* URLSearchParams::create(const URLSearchParamsInit& init) {
+URLSearchParams* URLSearchParams::create(const URLSearchParamsInit& init,
+ ExceptionState& exceptionState) {
if (init.isUSVString()) {
const String& queryString = init.getAsUSVString();
if (queryString.startsWith('?'))
return new URLSearchParams(queryString.substring(1));
return new URLSearchParams(queryString);
}
+ // TODO(sof): copy constructor no longer in the spec,
+ // consider removing.
tyoshino (SeeGerritForStatus) 2017/03/01 09:37:39 Filed 697378 for this!
if (init.isURLSearchParams())
return new URLSearchParams(init.getAsURLSearchParams());
+ if (init.isUSVStringSequenceSequence()) {
+ return URLSearchParams::create(init.getAsUSVStringSequenceSequence(),
+ exceptionState);
+ }
+
DCHECK(init.isNull());
return new URLSearchParams(String());
}
+URLSearchParams* URLSearchParams::create(const Vector<Vector<String>>& init,
+ ExceptionState& exceptionState) {
+ URLSearchParams* instance = new URLSearchParams(String());
+ if (!init.size())
+ return instance;
+ for (unsigned i = 0; i < init.size(); ++i) {
+ const Vector<String>& pair = init[i];
+ if (pair.size() != 2) {
+ exceptionState.throwTypeError(ExceptionMessages::failedToConstruct(
+ "URLSearchParams",
+ "Sequence initializer must only contain pair elements"));
+ return nullptr;
+ }
+ instance->appendWithoutUpdate(pair[0], pair[1]);
+ }
+ instance->runUpdateSteps();
+ return instance;
+}
+
URLSearchParams::URLSearchParams(const String& queryString, DOMURL* urlObject)
: m_urlObject(urlObject) {
if (!queryString.isEmpty())
@@ -112,7 +140,7 @@ void URLSearchParams::setInput(const String& queryString) {
queryString.substring(endOfName + 1, nameValueEnd - endOfName - 1));
if (value.isNull())
value = "";
- m_params.push_back(std::make_pair(name, value));
+ appendWithoutUpdate(name, value);
}
start = nameValueEnd + 1;
}
@@ -125,8 +153,13 @@ String URLSearchParams::toString() const {
return String(encodedData.data(), encodedData.size());
}
-void URLSearchParams::append(const String& name, const String& value) {
+void URLSearchParams::appendWithoutUpdate(const String& name,
+ const String& value) {
m_params.push_back(std::make_pair(name, value));
+}
+
+void URLSearchParams::append(const String& name, const String& value) {
+ appendWithoutUpdate(name, value);
runUpdateSteps();
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/URLSearchParams.h ('k') | third_party/WebKit/Source/core/dom/URLSearchParams.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698