Commit 2e6d209
authored
Improve TypeError diagnostics in WeakMap, WeakSet and Object builtins and update tests (#4863)
<!---
Thank you for contributing to Boa! Please fill out the template below,
and remove or add any
information as you feel necessary.
--->
Improve TypeError diagnostics in WeakMap, WeakSet and Object builtins
and update tests
This Pull Request fixes/closes #.
It changes the following:
* Improve TypeError messages in `WeakMap`, `WeakSet`, and `Object`
builtins to provide clearer diagnostics.
* Replace generic error messages such as `"called with non-object
value"` and `"Expected an object"` with explicit messages indicating the
expected receiver type.
* Standardize error message format to:
`<Builtin>.<method>: expected 'this' to be a <Type> object`
* Update unit tests to match the improved error messages.
### Before
Some errors used generic messages that did not clearly indicate which
builtin method failed or what type was expected.
Examples:
```
WeakMap.get: called with non-object value
WeakMap.getOrInsertComputed: called with non-object value
Object prototype may only be an Object or null: undefined
Expected an object
```
These messages lacked clear context about the failing method or the
expected `this` value.
### After
Error messages now explicitly describe the expected receiver type and
the builtin method where the error occurred.
Examples:
```
WeakMap.prototype.get: expected 'this' to be a WeakMap object
WeakMap.prototype.getOrInsert: expected 'this' to be a WeakMap object
WeakMap.prototype.getOrInsertComputed: expected 'this' to be a WeakMap object
Object.create: expected 'proto' to be an Object or null, got `undefined`
Object.defineProperty: expected 'this' to be an Object
Object.defineProperties: expected 'this' to be an Object
```
### Files Modified
**Engine changes**
* `core/engine/src/builtins/weak_map/mod.rs`
* `core/engine/src/builtins/weak_set/mod.rs`
* `core/engine/src/builtins/object/mod.rs`
These files were updated to replace generic `TypeError` messages with
more descriptive diagnostics.
**Test updates**
To keep the test suite consistent with the improved diagnostics,
expected error strings were updated in:
* `core/engine/src/builtins/weak_map/tests.rs`
* `core/engine/src/builtins/object/tests.rs`
No behavioral changes were introduced; only error message diagnostics
were improved and tests updated accordingly.
---------
Signed-off-by: mrhapile <allinonegaming3456@gmail.com>1 parent 92b7565 commit 2e6d209
5 files changed
+86
-111
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
255 | 254 | | |
256 | 255 | | |
257 | 256 | | |
258 | | - | |
259 | | - | |
260 | | - | |
| 257 | + | |
261 | 258 | | |
262 | 259 | | |
263 | 260 | | |
| |||
286 | 283 | | |
287 | 284 | | |
288 | 285 | | |
289 | | - | |
290 | | - | |
291 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
292 | 289 | | |
293 | 290 | | |
294 | 291 | | |
| |||
329 | 326 | | |
330 | 327 | | |
331 | 328 | | |
332 | | - | |
333 | | - | |
334 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
335 | 332 | | |
336 | 333 | | |
337 | 334 | | |
| |||
467 | 464 | | |
468 | 465 | | |
469 | 466 | | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
476 | 471 | | |
477 | 472 | | |
478 | 473 | | |
| |||
645 | 640 | | |
646 | 641 | | |
647 | 642 | | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
653 | 646 | | |
654 | 647 | | |
655 | 648 | | |
| |||
672 | 665 | | |
673 | 666 | | |
674 | 667 | | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
681 | 672 | | |
682 | 673 | | |
683 | 674 | | |
| |||
693 | 684 | | |
694 | 685 | | |
695 | 686 | | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
702 | 691 | | |
703 | 692 | | |
704 | 693 | | |
| |||
711 | 700 | | |
712 | 701 | | |
713 | 702 | | |
714 | | - | |
715 | 703 | | |
716 | | - | |
717 | | - | |
718 | | - | |
| 704 | + | |
719 | 705 | | |
720 | 706 | | |
721 | 707 | | |
| |||
774 | 760 | | |
775 | 761 | | |
776 | 762 | | |
777 | | - | |
778 | | - | |
779 | | - | |
| 763 | + | |
780 | 764 | | |
781 | 765 | | |
782 | 766 | | |
| |||
801 | 785 | | |
802 | 786 | | |
803 | 787 | | |
804 | | - | |
805 | | - | |
806 | | - | |
| 788 | + | |
807 | 789 | | |
808 | 790 | | |
809 | 791 | | |
| |||
1122 | 1104 | | |
1123 | 1105 | | |
1124 | 1106 | | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
| 1107 | + | |
1128 | 1108 | | |
1129 | 1109 | | |
1130 | 1110 | | |
| |||
1169 | 1149 | | |
1170 | 1150 | | |
1171 | 1151 | | |
1172 | | - | |
1173 | | - | |
1174 | | - | |
| 1152 | + | |
1175 | 1153 | | |
1176 | 1154 | | |
1177 | 1155 | | |
| |||
1221 | 1199 | | |
1222 | 1200 | | |
1223 | 1201 | | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
| 1202 | + | |
1227 | 1203 | | |
1228 | 1204 | | |
1229 | 1205 | | |
| |||
1381 | 1357 | | |
1382 | 1358 | | |
1383 | 1359 | | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
1387 | 1363 | | |
1388 | 1364 | | |
1389 | 1365 | | |
| |||
1400 | 1376 | | |
1401 | 1377 | | |
1402 | 1378 | | |
1403 | | - | |
1404 | | - | |
1405 | | - | |
| 1379 | + | |
1406 | 1380 | | |
1407 | 1381 | | |
1408 | 1382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 90 | + | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
| |||
114 | 112 | | |
115 | 113 | | |
116 | 114 | | |
117 | | - | |
| 115 | + | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
| |||
142 | 140 | | |
143 | 141 | | |
144 | 142 | | |
145 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
| 184 | + | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
218 | | - | |
| 219 | + | |
| 220 | + | |
219 | 221 | | |
220 | 222 | | |
221 | 223 | | |
| |||
250 | 252 | | |
251 | 253 | | |
252 | 254 | | |
253 | | - | |
| 255 | + | |
| 256 | + | |
254 | 257 | | |
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
258 | 261 | | |
259 | 262 | | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
265 | 267 | | |
266 | 268 | | |
267 | 269 | | |
| |||
298 | 300 | | |
299 | 301 | | |
300 | 302 | | |
301 | | - | |
302 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
303 | 306 | | |
304 | 307 | | |
305 | 308 | | |
| |||
308 | 311 | | |
309 | 312 | | |
310 | 313 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
317 | 318 | | |
318 | 319 | | |
319 | 320 | | |
| |||
352 | 353 | | |
353 | 354 | | |
354 | 355 | | |
355 | | - | |
356 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
357 | 359 | | |
358 | 360 | | |
359 | 361 | | |
| |||
362 | 364 | | |
363 | 365 | | |
364 | 366 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
376 | | - | |
377 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
0 commit comments