Skip to content

Commit 9204314

Browse files
committed
fix URLSearchParams.entries and add iterator
Signed-off-by: karthik Ganeshram <[email protected]>
1 parent 7e83d1d commit 9204314

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

crates/spin-js-engine/src/js_sdk/modules/url.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,25 @@ class URLSearchParams {
8181
delete this.queryParams[key]
8282
}
8383
entries() {
84-
return Object.entries(this.queryParams)
84+
let arr: Array<[string, string]> = []
85+
Object.entries(this.queryParams).map(o => {
86+
if (Array.isArray(o[1])) {
87+
o[1].map(k => {
88+
arr.push([o[0], k])
89+
})
90+
} else {
91+
arr.push([o[0], o[1]])
92+
}
93+
})
94+
let iterLength = arr.length
95+
let iterIndex = 0
96+
return {
97+
next: function() {
98+
return iterIndex < iterLength ?
99+
{value: arr[iterIndex++], done: false} :
100+
{done: true};
101+
}
102+
}
85103
}
86104
get(key: string) {
87105
let val = this.queryParams[key]
@@ -115,6 +133,9 @@ class URLSearchParams {
115133
values() {
116134
return Object.keys(this.queryParams).map(k => this.queryParams[k])
117135
}
136+
[Symbol.iterator]() {
137+
return this.entries()
138+
}
118139
}
119140

120141
/** @internal */

types/lib/modules/overrides.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare global {
2828
constructor(queryParamsString: string);
2929
append(key: string, val: string | Array<string>): void
3030
delete(key: string): void
31-
entries(): Array<[string, string | Array<string>]>
31+
entries(): Iterable<[string, string]>
3232
get(key: string): string
3333
getAll(key: string): string[]
3434
has(key: string): boolean

0 commit comments

Comments
 (0)