MCPcopy Index your code
hub / github.com/nodejs/node / writeNumericArg

Function writeNumericArg

lib/internal/ffi-shared-buffer.js:122–157  ·  view source on GitHub ↗
(view, info, offset, arg, index)

Source from the content-addressed store, hash-verified

120// Validation and error messages must mirror `ToFFIArgument` in
121// `src/ffi/types.cc`.
122function 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).

Callers 2

wrapWithSharedBufferFunction · 0.85
buildNumericWrapperFunction · 0.85

Calls 3

throwFFIArgErrorFunction · 0.70
setMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…