Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 86 additions & 6 deletions src/jsc/modules/lib/URLSearchParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@

exports.implementation = class URLSearchParamsImpl {
constructor(globalObject, constructorArgs = [""], options = {}) {
const { doNotStripQMark = false } = options || {};
let init = constructorArgs[0];
let doNotStripQMark = false;
let init = "";

if (arguments.length === 1) {
init = globalObject;
} else {
const resolvedOptions = options || {};
doNotStripQMark = !!resolvedOptions.doNotStripQMark;
if (Array.isArray(constructorArgs)) {
init = constructorArgs[0];
} else {

Check failure on line 16 in src/jsc/modules/lib/URLSearchParams.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with 'MIT' component license found (128 lines) Location: https://github.com/jsdom/whatwg-url/blob/v12.0.0/lib/URLSearchParams-impl.js#L7 Component license file: https://github.com/jsdom/whatwg-url/blob/v12.0.0/LICENSE.txt Component: pkg:github/jsdom/whatwg-url@v12.0.0 Download: https://github.com/jsdom/whatwg-url/archive/refs/tags/v12.0.0.tar.gz
init = constructorArgs;
}
}

this._list = [];
this._url = null;

Expand All @@ -20,10 +33,26 @@
}
this._list.push([pair[0], pair[1]]);
}
} else if (typeof init === "object" && Object.getPrototypeOf(init) === null) {
for (const name of Object.keys(init)) {
const value = init[name];
this._list.push([name, value]);
} else if (typeof init === "object" && init !== null && !Array.isArray(init)) {
// Handle URLSearchParams-like objects that expose an internal _list.
if (Array.isArray(init._list)) {
for (const pair of init._list) {
if (Array.isArray(pair) && pair.length >= 2) {
this._list.push([pair[0], pair[1]]);
}
}
} else if (typeof init.entries === "function") {
// Handle iterable URLSearchParams-compatible objects.
for (const pair of init.entries()) {
if (Array.isArray(pair) && pair.length >= 2) {
this._list.push([pair[0], pair[1]]);
}
}
} else {
for (const name of Object.keys(init)) {
const value = init[name];
this._list.push([name, value]);
}
}
} else {
this._list = urlencoded.parseUrlencodedString(init);
Expand All @@ -42,6 +71,7 @@
if (serializedQuery === null) {
this._url._potentiallyStripTrailingSpacesFromAnOpaquePath();
}

}
}

Expand Down Expand Up @@ -126,6 +156,56 @@
this._updateSteps();
}

forEach(callback, thisArg) {
if (typeof callback !== "function") {
throw new TypeError("Failed to execute 'forEach' on 'URLSearchParams': parameter 1 is not a function.");
}

for (const tuple of this._list) {
callback.call(thisArg, tuple[1], tuple[0], this);
}
}

entries() {
return this._list[Symbol.iterator]();
}

keys() {
const list = this._list;
let index = 0;
return {
next() {
if (index >= list.length) {
return { value: undefined, done: true };
}
const value = list[index][0];
index++;
return { value: value, done: false };
},
[Symbol.iterator]() {
return this;
}
};
}

values() {
const list = this._list;
let index = 0;
return {
next() {
if (index >= list.length) {
return { value: undefined, done: true };
}
const value = list[index][1];
index++;
return { value: value, done: false };
},
[Symbol.iterator]() {
return this;
}
};
}

[Symbol.iterator]() {
return this._list[Symbol.iterator]();
}
Expand Down
Loading
Loading