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

Function wrapWithRawPointerConversions

lib/internal/ffi/fast-api.js:184–268  ·  view source on GitHub ↗
(rawFn, argumentTypes, owner)

Source from the content-addressed store, hash-verified

182}
183
184function wrapWithRawPointerConversions(rawFn, argumentTypes, owner) {
185 if (rawFn === undefined || rawFn === null) {
186 return rawFn;
187 }
188 if (argumentTypes === undefined) {
189 argumentTypes = rawFn[kFastArguments];
190 }
191 if (argumentTypes === undefined) {
192 return rawFn;
193 }
194
195 const indexes = getPointerConversionIndexes(argumentTypes, rawFn);
196 if (indexes === null) {
197 return rawFn;
198 }
199
200 const nargs = argumentTypes.length;
201 let wrapper;
202 if (nargs === 1 && indexes.length === 1 && indexes[0] === 0) {
203 const t0 = argumentTypes[0];
204 const string0 = needsStringPointerConversion(t0);
205 const memory0 = needsRawPointerConversion(t0) || string0;
206 const fastBufferInvoke = needsPointerLikeConversion(t0) ?
207 rawFn[kFastBufferInvoke] : undefined;
208 wrapper = function(a0) {
209 if (arguments.length !== 1) {
210 throwFFIArgCountError(1, arguments.length);
211 }
212 let arg = a0;
213 if (needsNullPointerConversion(t0) &&
214 (arg === null || arg === undefined)) {
215 arg = 0n;
216 } else if (string0 && typeof arg === 'string') {
217 arg = getStringConversionPointer(owner, arg, 0);
218 } else if (memory0 && (isArrayBufferView(arg) || isAnyArrayBuffer(arg))) {
219 if (fastBufferInvoke !== undefined) {
220 return fastBufferInvoke(arg);
221 }
222 arg = getRawPointer(arg);
223 }
224 return rawFn(arg);
225 };
226 } else if (nargs === 2) {
227 const c0 = ArrayPrototypeIncludes(indexes, 0);
228 const c1 = ArrayPrototypeIncludes(indexes, 1);
229 const t0 = argumentTypes[0];
230 const t1 = argumentTypes[1];
231 wrapper = function(a0, a1) {
232 if (arguments.length !== 2) {
233 throwFFIArgCountError(2, arguments.length);
234 }
235 return rawFn(c0 ? convertPointerArg(t0, a0, owner, 0) : a0,
236 c1 ? convertPointerArg(t1, a1, owner, 1) : a1);
237 };
238 } else if (nargs === 3) {
239 const c0 = ArrayPrototypeIncludes(indexes, 0);
240 const c1 = ArrayPrototypeIncludes(indexes, 1);
241 const c2 = ArrayPrototypeIncludes(indexes, 2);

Callers 1

wrapFFIFunctionFunction · 0.85

Calls 9

convertPointerArgFunction · 0.85
throwFFIArgCountErrorFunction · 0.70
inheritMetadataFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…