Commit 07fcf1e
ffi: throw ERR_INVALID_ARG_TYPE for wrong-typed pointer and size
GetValidatedPointerAddress() and GetValidatedSize() throw
ERR_INVALID_ARG_VALUE when the argument is not a bigint or not a
number. doc/api/errors.md reserves that code for a value of the right
type that is invalid or unsupported; a wrong type is
ERR_INVALID_ARG_TYPE. That is what the JavaScript validators behind
exportString() and exportBuffer() throw, and what the inline IsBigInt()
checks in toString(), toBuffer() and toArrayBuffer() throw for their
first argument. So ffi.exportBuffer(buf, ptr, 'x') reports a type error
while ffi.toBuffer(ptr, 'x') reports a value error for the same mistake.
Switch the two type-check branches to ERR_INVALID_ARG_TYPE. The branches
that reject a negative or non-integer value, or a value outside the
platform range, keep ERR_INVALID_ARG_VALUE and ERR_OUT_OF_RANGE.
This changes the code thrown for a non-bigint pointer by the getters,
the setters, exportBuffer(), exportArrayBuffer() and
exportArrayBufferView(), and for a non-number offset or length by the
getters, the setters, toBuffer() and toArrayBuffer(). The messages are
unchanged. No existing test asserted ERR_INVALID_ARG_VALUE on any of
these paths.
Refs: #65500
Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: #65842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>1 parent a914909 commit 07fcf1e
2 files changed
Lines changed: 36 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
332 | | - | |
| 331 | + | |
| 332 | + | |
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
340 | 368 | | |
0 commit comments