11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { URL, URLSearchParams, format } = require('url');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci[
71cb0ef41Sopenharmony_ci  { name: 'toString' },
81cb0ef41Sopenharmony_ci  { name: 'toJSON' },
91cb0ef41Sopenharmony_ci  { name: Symbol.for('nodejs.util.inspect.custom') },
101cb0ef41Sopenharmony_ci].forEach(({ name }) => {
111cb0ef41Sopenharmony_ci  testMethod(URL.prototype, name);
121cb0ef41Sopenharmony_ci});
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci[
151cb0ef41Sopenharmony_ci  'http://www.google.com',
161cb0ef41Sopenharmony_ci  'https://www.domain.com:443',
171cb0ef41Sopenharmony_ci  'file:///Users/yagiz/Developer/node',
181cb0ef41Sopenharmony_ci].forEach((url) => {
191cb0ef41Sopenharmony_ci  const u = new URL(url);
201cb0ef41Sopenharmony_ci  assert.strictEqual(JSON.stringify(u), `"${u.href}"`);
211cb0ef41Sopenharmony_ci  assert.strictEqual(u.toString(), u.href);
221cb0ef41Sopenharmony_ci  assert.strictEqual(format(u), u.href);
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci[
261cb0ef41Sopenharmony_ci  { name: 'href' },
271cb0ef41Sopenharmony_ci  { name: 'protocol' },
281cb0ef41Sopenharmony_ci  { name: 'username' },
291cb0ef41Sopenharmony_ci  { name: 'password' },
301cb0ef41Sopenharmony_ci  { name: 'host' },
311cb0ef41Sopenharmony_ci  { name: 'hostname' },
321cb0ef41Sopenharmony_ci  { name: 'port' },
331cb0ef41Sopenharmony_ci  { name: 'pathname' },
341cb0ef41Sopenharmony_ci  { name: 'search' },
351cb0ef41Sopenharmony_ci  { name: 'hash' },
361cb0ef41Sopenharmony_ci  { name: 'origin', readonly: true },
371cb0ef41Sopenharmony_ci  { name: 'searchParams', readonly: true },
381cb0ef41Sopenharmony_ci].forEach(({ name, readonly = false }) => {
391cb0ef41Sopenharmony_ci  testAccessor(URL.prototype, name, readonly);
401cb0ef41Sopenharmony_ci});
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci[
431cb0ef41Sopenharmony_ci  { name: 'createObjectURL' },
441cb0ef41Sopenharmony_ci  { name: 'revokeObjectURL' },
451cb0ef41Sopenharmony_ci].forEach(({ name }) => {
461cb0ef41Sopenharmony_ci  testStaticAccessor(URL, name);
471cb0ef41Sopenharmony_ci});
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci[
501cb0ef41Sopenharmony_ci  { name: 'append' },
511cb0ef41Sopenharmony_ci  { name: 'delete' },
521cb0ef41Sopenharmony_ci  { name: 'get' },
531cb0ef41Sopenharmony_ci  { name: 'getAll' },
541cb0ef41Sopenharmony_ci  { name: 'has' },
551cb0ef41Sopenharmony_ci  { name: 'set' },
561cb0ef41Sopenharmony_ci  { name: 'sort' },
571cb0ef41Sopenharmony_ci  { name: 'entries' },
581cb0ef41Sopenharmony_ci  { name: 'forEach' },
591cb0ef41Sopenharmony_ci  { name: 'keys' },
601cb0ef41Sopenharmony_ci  { name: 'values' },
611cb0ef41Sopenharmony_ci  { name: 'toString' },
621cb0ef41Sopenharmony_ci  { name: Symbol.iterator, methodName: 'entries' },
631cb0ef41Sopenharmony_ci  { name: Symbol.for('nodejs.util.inspect.custom') },
641cb0ef41Sopenharmony_ci].forEach(({ name, methodName }) => {
651cb0ef41Sopenharmony_ci  testMethod(URLSearchParams.prototype, name, methodName);
661cb0ef41Sopenharmony_ci});
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci{
691cb0ef41Sopenharmony_ci  const params = new URLSearchParams();
701cb0ef41Sopenharmony_ci  params.append('a', 'b');
711cb0ef41Sopenharmony_ci  params.append('a', 'c');
721cb0ef41Sopenharmony_ci  params.append('b', 'c');
731cb0ef41Sopenharmony_ci  assert.strictEqual(params.size, 3);
741cb0ef41Sopenharmony_ci}
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci{
771cb0ef41Sopenharmony_ci  const u = new URL('https://abc.com/?q=old');
781cb0ef41Sopenharmony_ci  const s = u.searchParams;
791cb0ef41Sopenharmony_ci  u.href = 'http://abc.com/?q=new';
801cb0ef41Sopenharmony_ci  assert.strictEqual(s.get('q'), 'new');
811cb0ef41Sopenharmony_ci}
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_cifunction stringifyName(name) {
841cb0ef41Sopenharmony_ci  if (typeof name === 'symbol') {
851cb0ef41Sopenharmony_ci    const { description } = name;
861cb0ef41Sopenharmony_ci    if (description === undefined) {
871cb0ef41Sopenharmony_ci      return '';
881cb0ef41Sopenharmony_ci    }
891cb0ef41Sopenharmony_ci    return `[${description}]`;
901cb0ef41Sopenharmony_ci  }
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci  return name;
931cb0ef41Sopenharmony_ci}
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_cifunction testMethod(target, name, methodName = stringifyName(name)) {
961cb0ef41Sopenharmony_ci  const desc = Object.getOwnPropertyDescriptor(target, name);
971cb0ef41Sopenharmony_ci  assert.notStrictEqual(desc, undefined);
981cb0ef41Sopenharmony_ci  assert.strictEqual(desc.enumerable, typeof name === 'string');
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  const { value } = desc;
1011cb0ef41Sopenharmony_ci  assert.strictEqual(typeof value, 'function');
1021cb0ef41Sopenharmony_ci  assert.strictEqual(value.name, methodName);
1031cb0ef41Sopenharmony_ci  assert.strictEqual(
1041cb0ef41Sopenharmony_ci    Object.hasOwn(value, 'prototype'),
1051cb0ef41Sopenharmony_ci    false,
1061cb0ef41Sopenharmony_ci  );
1071cb0ef41Sopenharmony_ci}
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_cifunction testAccessor(target, name, readonly = false) {
1101cb0ef41Sopenharmony_ci  const desc = Object.getOwnPropertyDescriptor(target, name);
1111cb0ef41Sopenharmony_ci  assert.notStrictEqual(desc, undefined);
1121cb0ef41Sopenharmony_ci  assert.strictEqual(desc.enumerable, typeof name === 'string');
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ci  const methodName = stringifyName(name);
1151cb0ef41Sopenharmony_ci  const { get, set } = desc;
1161cb0ef41Sopenharmony_ci  assert.strictEqual(typeof get, 'function');
1171cb0ef41Sopenharmony_ci  assert.strictEqual(get.name, `get ${methodName}`);
1181cb0ef41Sopenharmony_ci  assert.strictEqual(
1191cb0ef41Sopenharmony_ci    Object.hasOwn(get, 'prototype'),
1201cb0ef41Sopenharmony_ci    false,
1211cb0ef41Sopenharmony_ci  );
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci  if (readonly) {
1241cb0ef41Sopenharmony_ci    assert.strictEqual(set, undefined);
1251cb0ef41Sopenharmony_ci  } else {
1261cb0ef41Sopenharmony_ci    assert.strictEqual(typeof set, 'function');
1271cb0ef41Sopenharmony_ci    assert.strictEqual(set.name, `set ${methodName}`);
1281cb0ef41Sopenharmony_ci    assert.strictEqual(
1291cb0ef41Sopenharmony_ci      Object.hasOwn(set, 'prototype'),
1301cb0ef41Sopenharmony_ci      false,
1311cb0ef41Sopenharmony_ci    );
1321cb0ef41Sopenharmony_ci  }
1331cb0ef41Sopenharmony_ci}
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_cifunction testStaticAccessor(target, name) {
1361cb0ef41Sopenharmony_ci  const desc = Object.getOwnPropertyDescriptor(target, name);
1371cb0ef41Sopenharmony_ci  assert.notStrictEqual(desc, undefined);
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci  assert.strictEqual(desc.configurable, true);
1401cb0ef41Sopenharmony_ci  assert.strictEqual(desc.enumerable, true);
1411cb0ef41Sopenharmony_ci  assert.strictEqual(desc.writable, true);
1421cb0ef41Sopenharmony_ci}
143