Skip to content

Commit 8e67277

Browse files
Raphael Kubo da CostaCommit Bot
authored andcommitted
url: Update URLSearchParams' constructor arguments.
Adapt to whatwg/url#175, which dropped URLSearchParams itself from the union accepted by the constructor. The constructor now takes an optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) instead. Existing uses of `new URLSearchParams(<existing URLSearchParam>)` continue to work, as per WebIDL these objects are converted to sequences because URLSearchParams is iterable. Intent to ship/implement thread: https://groups.google.com/a/chromium.org/d/msg/blink-dev/AGyufsf5XU4/CBeVLmT7BgAJ Bug: 680531, 697378 Change-Id: Ie82d1151acc4334628be0cc258bc20e5a0dc1d15 Reviewed-on: https://chromium-review.googlesource.com/544919 Commit-Queue: Raphael Kubo da Costa (rakuco) <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Reviewed-by: Mike West <[email protected]> Cr-Commit-Position: refs/heads/master@{#482588}
1 parent 6b4ec7b commit 8e67277

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

third_party/WebKit/LayoutTests/external/wpt/url/urlsearchparams-constructor-expected.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PASS Basic URLSearchParams construction
33
PASS URLSearchParams constructor, no arguments
44
FAIL URLSearchParams constructor, DOMException.prototype as argument Illegal invocation
55
PASS URLSearchParams constructor, empty string as argument
6-
FAIL URLSearchParams constructor, {} as argument assert_equals: expected "" but got "%5Bobject+Object%5D="
6+
PASS URLSearchParams constructor, {} as argument
77
PASS URLSearchParams constructor, string.
88
PASS URLSearchParams constructor, object.
99
PASS Parse +
@@ -17,10 +17,10 @@ PASS Parse %e2%8e%84
1717
PASS Parse 💩
1818
PASS Parse %f0%9f%92%a9
1919
PASS Constructor with sequence of sequences of strings
20-
FAIL Construct with object with + assert_array_equals: property 0, expected "+" but got "[object Object]"
21-
FAIL Construct with object with two keys assert_array_equals: property 0, expected "c" but got "[object Object]"
20+
PASS Construct with object with +
21+
PASS Construct with object with two keys
2222
PASS Construct with array with two keys
23-
FAIL Construct with object with NULL, non-ASCII, and surrogate keys assert_array_equals: property 0, expected "a\0b" but got "[object Object]"
24-
FAIL Custom [Symbol.iterator] assert_equals: expected (string) "b" but got (object) null
23+
PASS Construct with object with NULL, non-ASCII, and surrogate keys
24+
PASS Custom [Symbol.iterator]
2525
Harness: the test ran to completion.
2626

third_party/WebKit/LayoutTests/fast/domurl/urlsearchparams-constructor.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
var params = new URLSearchParams('');
5656
assert_not_equals(params, null, 'constructor returned non-null value.');
5757
assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSearchParams.prototype as prototype.');
58-
params = new URLSearchParams({});
59-
assert_equals(params + '', '%5Bobject+Object%5D=');
6058
}, 'URLSearchParams constructor, empty.');
6159

6260
test(function() {
@@ -91,7 +89,7 @@
9189
assert_false(params.has('e'));
9290
params.append('g', 'h');
9391
assert_false(seed.has('g'));
94-
}, 'URLSearchParams constructor, object.');
92+
}, 'sequence initializer, object coerced to iterable');
9593

9694
test(function() {
9795
var params = new URLSearchParams('a=b+c');
@@ -180,6 +178,18 @@
180178
"Sequence elements must be pairs");
181179
}, 'sequence initializer');
182180

181+
test(function() {
182+
let params = new URLSearchParams({});
183+
assert_true(params !== null, 'Empty record');
184+
assert_equals(params.toString(), '');
185+
186+
params = new URLSearchParams({1: 2, 'a': 'b'});
187+
assert_equals(params.toString(), '1=2&a=b');
188+
189+
params = new URLSearchParams({false: true, 0: 'foo'});
190+
assert_equals(params.toString(), '0=foo&false=true');
191+
}, 'record initializer');
192+
183193
</script>
184194
</head>
185195
</html>

third_party/WebKit/Source/bindings/core/v8/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ bindings_core_generated_union_type_files = [
7373
"$bindings_core_v8_output_dir/StringOrFloat.h",
7474
"$bindings_core_v8_output_dir/StringOrUnrestrictedDoubleSequence.cpp",
7575
"$bindings_core_v8_output_dir/StringOrUnrestrictedDoubleSequence.h",
76-
"$bindings_core_v8_output_dir/USVStringSequenceSequenceOrUSVStringOrURLSearchParams.cpp",
77-
"$bindings_core_v8_output_dir/USVStringSequenceSequenceOrUSVStringOrURLSearchParams.h",
76+
"$bindings_core_v8_output_dir/USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString.cpp",
77+
"$bindings_core_v8_output_dir/USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString.h",
7878
"$bindings_core_v8_output_dir/UnrestrictedDoubleOrKeyframeAnimationOptions.cpp",
7979
"$bindings_core_v8_output_dir/UnrestrictedDoubleOrKeyframeAnimationOptions.h",
8080
"$bindings_core_v8_output_dir/UnrestrictedDoubleOrKeyframeEffectOptions.cpp",

third_party/WebKit/Source/core/dom/URLSearchParams.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ URLSearchParams* URLSearchParams::Create(const URLSearchParamsInit& init,
4848
return new URLSearchParams(query_string.Substring(1));
4949
return new URLSearchParams(query_string);
5050
}
51-
// TODO(sof): copy constructor no longer in the spec,
52-
// consider removing.
53-
if (init.isURLSearchParams())
54-
return new URLSearchParams(init.getAsURLSearchParams());
55-
51+
if (init.isUSVStringUSVStringRecord()) {
52+
return URLSearchParams::Create(init.getAsUSVStringUSVStringRecord(),
53+
exception_state);
54+
}
5655
if (init.isUSVStringSequenceSequence()) {
5756
return URLSearchParams::Create(init.getAsUSVStringSequenceSequence(),
5857
exception_state);
@@ -87,9 +86,16 @@ URLSearchParams::URLSearchParams(const String& query_string, DOMURL* url_object)
8786
SetInput(query_string);
8887
}
8988

90-
URLSearchParams::URLSearchParams(URLSearchParams* search_params) {
91-
DCHECK(search_params);
92-
params_ = search_params->params_;
89+
URLSearchParams* URLSearchParams::Create(
90+
const Vector<std::pair<String, String>>& init,
91+
ExceptionState& exception_state) {
92+
URLSearchParams* instance = new URLSearchParams(String());
93+
if (init.IsEmpty())
94+
return instance;
95+
for (const auto& item : init)
96+
instance->AppendWithoutUpdate(item.first, item.second);
97+
instance->RunUpdateSteps();
98+
return instance;
9399
}
94100

95101
URLSearchParams::~URLSearchParams() {}

third_party/WebKit/Source/core/dom/URLSearchParams.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <base/gtest_prod_util.h>
99
#include <utility>
1010
#include "bindings/core/v8/Iterable.h"
11-
#include "bindings/core/v8/USVStringSequenceSequenceOrUSVStringOrURLSearchParams.h"
11+
#include "bindings/core/v8/USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString.h"
1212
#include "platform/bindings/ScriptWrappable.h"
1313
#include "platform/heap/Handle.h"
1414
#include "platform/network/EncodedFormData.h"
@@ -20,7 +20,7 @@ namespace blink {
2020
class ExceptionState;
2121
class DOMURL;
2222

23-
typedef USVStringSequenceSequenceOrUSVStringOrURLSearchParams
23+
typedef USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString
2424
URLSearchParamsInit;
2525

2626
class CORE_EXPORT URLSearchParams final
@@ -31,6 +31,8 @@ class CORE_EXPORT URLSearchParams final
3131

3232
public:
3333
static URLSearchParams* Create(const URLSearchParamsInit&, ExceptionState&);
34+
static URLSearchParams* Create(const Vector<std::pair<String, String>>&,
35+
ExceptionState&);
3436
static URLSearchParams* Create(const Vector<Vector<String>>&,
3537
ExceptionState&);
3638

@@ -65,7 +67,6 @@ class CORE_EXPORT URLSearchParams final
6567
FRIEND_TEST_ALL_PREFIXES(URLSearchParamsTest, EncodedFormData);
6668

6769
explicit URLSearchParams(const String&, DOMURL* = nullptr);
68-
explicit URLSearchParams(URLSearchParams*);
6970

7071
void RunUpdateSteps();
7172
IterationSource* StartIteration(ScriptState*, ExceptionState&) override;

third_party/WebKit/Source/core/dom/URLSearchParams.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// https://url.spec.whatwg.org/#interface-urlsearchparams
66

77
[
8-
Constructor(optional (sequence<sequence<USVString>> or USVString or URLSearchParams) init = ""),
8+
Constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = ""),
99
Exposed=(Window,Worker),
1010
RaisesException=Constructor
1111
] interface URLSearchParams {

0 commit comments

Comments
 (0)