Commit 9febd38
authored
fix(ext/url): URLSearchParams Node-compat error messages on invalid this and missing args (#34017)
## Summary
Make the failing Node-compat test
`test/parallel/test-whatwg-url-custom-searchparams-append.js` pass
end-to-end by aligning Deno's `URLSearchParams` and the underlying
`webidl` helpers with Node's error contract.
The PR landed in two commits — together they cover all six assertions in
that test file.
### 1. Branding-check message (initial commit)
`webidl.assertBranded` gains an optional `interfaceName` argument. When
supplied, the error becomes `Value of "this" must be of type <Iface>`
with `code = "ERR_INVALID_THIS"`; otherwise it falls back to `Illegal
invocation` (unchanged for non-URLSearchParams interfaces).
`URLSearchParams` methods and the pair-iterable mixin
(`entries`/`keys`/`values`/`forEach`) pass `"URLSearchParams"` through.
### 2. `ERR_MISSING_ARGS` + symbol message (follow-up commit)
- `webidl.requiredArguments` gains an optional `argNames` array. When
supplied, it throws a Node-compatible `TypeError` with `code =
"ERR_MISSING_ARGS"` and a message of the form `The "name" and "value"
arguments must be specified` (Oxford-comma for 3+). Default path
unchanged.
- `URLSearchParams.{append,delete,get,getAll,has,set}` thread their
argument names.
- `webidl.converters.DOMString` now throws `TypeError: Cannot convert a
Symbol value to a string` (V8's native phrasing — Node uses it too)
instead of Deno's previous `"is a symbol, which cannot be converted to a
string"`. `String(sym)` does not throw on its own, so the explicit
symbol branch is kept; only the message changes. No Deno or WPT test
depends on the old phrasing.
- `tests/node_compat/config.jsonc` enables
`parallel/test-whatwg-url-custom-searchparams-append.js`.
All six assertions in the Node test now pass:
| # | Call | Expected |
|---|------|----------|
| 1 | `params.append.call(undefined)` | `TypeError [ERR_INVALID_THIS]:
Value of "this" must be of type URLSearchParams` |
| 2 | `params.append('a')` | `TypeError [ERR_MISSING_ARGS]: The "name"
and "value" arguments must be specified` |
| 3-4 | `params.set(obj, ...)` / `params.set(..., obj)` where
`obj.toString` throws | `Error: toString` propagates |
| 5-6 | `params.set(sym, ...)` / `params.set(..., sym)` | `TypeError:
Cannot convert a Symbol value to a string` |
## Test plan
- [x] `cargo build --bin deno`
- [x] `NODE_TEST_KNOWN_GLOBALS=0 deno run -A
test-whatwg-url-custom-searchparams-append.js` exits 0
- [x] `tests/unit/url_search_params_test.ts` — 33 passed
- [x] `tests/unit/url_test.ts` — 35 passed
- [x] `tests/unit/headers_test.ts` — 28 passed (re-checks DOMString and
webidl converters via Headers)
- [x] `tools/format.js` clean
- [x] `tools/lint.js --js` clean
Closes denoland/orchid#52
---------
Co-authored-by: divybot <divybot@users.noreply.github.com>1 parent 46c1566 commit 9febd38
4 files changed
Lines changed: 62 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
173 | | - | |
| 178 | + | |
174 | 179 | | |
175 | | - | |
| 180 | + | |
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
| |||
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
187 | | - | |
| 192 | + | |
188 | 193 | | |
189 | | - | |
| 194 | + | |
190 | 195 | | |
191 | 196 | | |
192 | 197 | | |
| |||
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
219 | | - | |
| 224 | + | |
220 | 225 | | |
221 | | - | |
| 226 | + | |
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
| |||
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
239 | | - | |
| 244 | + | |
240 | 245 | | |
241 | | - | |
| 246 | + | |
242 | 247 | | |
243 | 248 | | |
244 | 249 | | |
| |||
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
259 | | - | |
| 264 | + | |
260 | 265 | | |
261 | | - | |
| 266 | + | |
262 | 267 | | |
263 | 268 | | |
264 | 269 | | |
| |||
275 | 280 | | |
276 | 281 | | |
277 | 282 | | |
278 | | - | |
| 283 | + | |
279 | 284 | | |
280 | | - | |
| 285 | + | |
281 | 286 | | |
282 | 287 | | |
283 | 288 | | |
| |||
313 | 318 | | |
314 | 319 | | |
315 | 320 | | |
316 | | - | |
| 321 | + | |
317 | 322 | | |
318 | 323 | | |
319 | 324 | | |
| |||
325 | 330 | | |
326 | 331 | | |
327 | 332 | | |
328 | | - | |
| 333 | + | |
329 | 334 | | |
330 | 335 | | |
331 | 336 | | |
332 | 337 | | |
333 | | - | |
| 338 | + | |
334 | 339 | | |
335 | 340 | | |
336 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
422 | 421 | | |
423 | 422 | | |
424 | 423 | | |
| |||
717 | 716 | | |
718 | 717 | | |
719 | 718 | | |
720 | | - | |
| 719 | + | |
721 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
722 | 744 | | |
723 | 745 | | |
724 | 746 | | |
| |||
1167 | 1189 | | |
1168 | 1190 | | |
1169 | 1191 | | |
1170 | | - | |
| 1192 | + | |
1171 | 1193 | | |
1172 | 1194 | | |
1173 | 1195 | | |
1174 | | - | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
1175 | 1200 | | |
1176 | 1201 | | |
1177 | 1202 | | |
| |||
1248 | 1273 | | |
1249 | 1274 | | |
1250 | 1275 | | |
1251 | | - | |
| 1276 | + | |
1252 | 1277 | | |
1253 | 1278 | | |
1254 | 1279 | | |
| |||
1267 | 1292 | | |
1268 | 1293 | | |
1269 | 1294 | | |
1270 | | - | |
| 1295 | + | |
1271 | 1296 | | |
1272 | 1297 | | |
1273 | 1298 | | |
| |||
1276 | 1301 | | |
1277 | 1302 | | |
1278 | 1303 | | |
1279 | | - | |
| 1304 | + | |
1280 | 1305 | | |
1281 | 1306 | | |
1282 | 1307 | | |
| |||
1285 | 1310 | | |
1286 | 1311 | | |
1287 | 1312 | | |
1288 | | - | |
| 1313 | + | |
1289 | 1314 | | |
1290 | 1315 | | |
1291 | 1316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
| |||
517 | 518 | | |
518 | 519 | | |
519 | 520 | | |
520 | | - | |
| 521 | + | |
521 | 522 | | |
522 | 523 | | |
523 | 524 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3752 | 3752 | | |
3753 | 3753 | | |
3754 | 3754 | | |
| 3755 | + | |
3755 | 3756 | | |
3756 | 3757 | | |
3757 | 3758 | | |
| |||
0 commit comments