From 31ddc5bd0c4ca1b6d837029c926ec87bc472c168 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 12 Jan 2017 17:13:59 +0100 Subject: [PATCH] Simplify constructing URLSearchParams Tests: https://github.com/w3c/web-platform-tests/pull/4523. Fixes #27. --- url.bs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/url.bs b/url.bs index 2121a333..b0d7fc4e 100644 --- a/url.bs +++ b/url.bs @@ -2756,7 +2756,7 @@ steps:

Interface {{URLSearchParams}}

-[Constructor(optional (USVString or URLSearchParams) init = ""),
+[Constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = ""),
  Exposed=(Window,Worker)]
 interface URLSearchParams {
   void append(USVString name, USVString value);
@@ -2770,6 +2770,14 @@ interface URLSearchParams {
 };
 
+
+

Constructing and stringifying a {{URLSearchParams}} object is fairly straightforward: + +


+let params = new URLSearchParams({key: 730d67})
+params.toString() // key=730d67
+
+

A {{URLSearchParams}} object has an associated list of name-value pairs, which is initially empty. @@ -2784,14 +2792,25 @@ initially null.

  1. Let query be a new {{URLSearchParams}} object. -

  2. If init is a string, set query's - list to the result of - parsing init. +

  3. +

    If init is a sequence, then for each pair in init: -

  4. If init is a {{URLSearchParams}} object, set query's - list to a copy of init's +

      +
    1. If pair does not contain exactly two items, then throw a {{TypeError}}. + +

    2. Append a new name-value pair whose name is pair's first item, and value is + pair's second item, to query's list. +

    + +
  5. Otherwise, if init is a record, then for each mapping + (name, value) in init, append a new name-value pair whose name is + name and value is value, to query's list. +

  6. Otherwise, init is a string, then set query's + list to the result of + parsing init. +

  7. Return query.

@@ -2939,6 +2958,7 @@ Joe Duarte, Joshua Bell, Jxck, Kevin Grandon, +Kornel LesiƄski, Larry Masinter, Leif Halvard Silli, Mark Davis,