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

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

Issue 2725593003: Construct URLSearchParams from sequence initializer. (Closed)
Patch Set: 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..fac8afdfeed40681ab37a4d71f38eb1145d06b3d 100644
--- a/third_party/WebKit/Source/core/dom/URLSearchParams.cpp
+++ b/third_party/WebKit/Source/core/dom/URLSearchParams.cpp
@@ -39,20 +39,44 @@ 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.
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());
+ 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->append(pair[0], pair[1]);
tyoshino (SeeGerritForStatus) 2017/03/01 08:07:26 can we populate m_params first and then runUpdateS
sof 2017/03/01 08:40:59 Done, runUpdateSteps() would be near no-op in this
+ }
+ return instance;
+}
+
URLSearchParams::URLSearchParams(const String& queryString, DOMURL* urlObject)
: m_urlObject(urlObject) {
if (!queryString.isEmpty())

Powered by Google App Engine
This is Rietveld 408576698