(view, info, offset, arg, index)
| 120 | // Validation and error messages must mirror `ToFFIArgument` in |
| 121 | // `src/ffi/types.cc`. |
| 122 | function writeNumericArg(view, info, offset, arg, index) { |
| 123 | const kind = info.kind; |
| 124 | if (kind === 'int') { |
| 125 | if (typeof arg !== 'number' || !NumberIsInteger(arg) || |
| 126 | arg < info.min || arg > info.max) { |
| 127 | throwFFIArgError(`Argument ${index} must be ${info.label}`); |
| 128 | } |
| 129 | info.set(view, offset, arg, true); |
| 130 | return; |
| 131 | } |
| 132 | if (kind === 'i64') { |
| 133 | if (typeof arg !== 'bigint' || arg < I64_MIN || arg > I64_MAX) { |
| 134 | throwFFIArgError(`Argument ${index} must be ${info.label}`); |
| 135 | } |
| 136 | sI64(view, offset, arg, true); |
| 137 | return; |
| 138 | } |
| 139 | if (kind === 'u64') { |
| 140 | if (typeof arg !== 'bigint' || arg < 0n || arg > U64_MAX) { |
| 141 | throwFFIArgError(`Argument ${index} must be ${info.label}`); |
| 142 | } |
| 143 | sU64(view, offset, arg, true); |
| 144 | return; |
| 145 | } |
| 146 | if (kind === 'float') { |
| 147 | if (typeof arg !== 'number') { |
| 148 | throwFFIArgError(`Argument ${index} must be ${info.label}`); |
| 149 | } |
| 150 | info.set(view, offset, arg, true); |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | // Unreachable: caller filters out non-numeric kinds. |
| 155 | /* c8 ignore next */ |
| 156 | assert.fail(`FFI: writeNumericArg reached with unexpected kind="${kind}"`); |
| 157 | } |
| 158 | |
| 159 | // Returns true on fast-path success, false when the caller must fall back |
| 160 | // to the slow path (strings, Buffers, ArrayBuffers, ArrayBufferViews). |
no test coverage detected
searching dependent graphs…