private static function createNewURLSearchParamsObject($query, $init)
    {
        if (!$query) {
            $query = new static();
        }
        if ($init instanceof URLSearchParams) {
            $query->list = $init->list;
        } elseif (is_array($init)) {
            foreach ($init as $pair) {
                if (count($pair) !== 2) {
                    throw new TypeError(
                        'URLSearchParams require name/value tuples when being initialized by a sequence.'
                    );
                }
            }
            $query->list = $init;
        } elseif ($init instanceof \esperecyan\webidl\Record) {
            foreach ($init as $name => $value) {
                $query->list[] = [$name, $value];
            }
        } else {
            $query->list = lib\URLencoding::parseURLencodedString($init);
        }
        return $query;
    }