{"record":{"id":"2a2c15a799a39dbc","repo":"denoland/deno","slug":"cannot-access-pointer-expected-arraybuffer-sh","errorCode":null,"errorMessage":"Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}","messagePattern":"Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/ffi/00_ffi.js","lineNumber":258,"sourceCode":"    let pointer;\n    if (ArrayBufferIsView(value)) {\n      if (value.length === 0) {\n        pointer = op_ffi_ptr_of_exact(value);\n      } else {\n        pointer = op_ffi_ptr_of(value);\n      }\n    } else if (isAnyArrayBuffer(value)) {\n      // `ArrayBuffer`/`SharedArrayBuffer` expose `byteLength`, not `length`, so\n      // wrap in a `Uint8Array` and measure that to detect the empty case (the\n      // `op`s require a view anyway).\n      const view = new Uint8Array(value);\n      if (TypedArrayPrototypeGetByteLength(view) === 0) {\n        pointer = op_ffi_ptr_of_exact(view);\n      } else {\n        pointer = op_ffi_ptr_of(view);\n      }\n    } else {\n      throw new TypeError(\n        `Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}`,\n      );\n    }\n    if (pointer) {\n      POINTER_TO_BUFFER_WEAK_MAP.set(pointer, value);\n    }\n    return pointer;\n  }\n\n  static offset(value, offset) {\n    return op_ffi_ptr_offset(value, offset);\n  }\n\n  static value(value) {\n    if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {\n      value = value.pointer;\n    }\n    return op_ffi_ptr_value(value);","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/ffi/00_ffi.js#L240-L276","documentation":"Deno.UnsafePointer.of(value) converts a JS value to a raw FFI pointer. It accepts UnsafeCallback instances (using their registered pointer), ArrayBuffer views (TypedArray/DataView), and ArrayBuffer/SharedArrayBuffer. Any other value — number, bigint, string, plain object, null — throws this TypeError, with the received typeof interpolated.","triggerScenarios":"Deno.UnsafePointer.of(0x1000) or UnsafePointer.of(123n) (numeric addresses are not accepted here); passing a plain object, string, or null where FFI expects a buffer; passing a Web object like Blob instead of a Uint8Array; passing a plain Array instead of a typed array.","commonSituations":"Wrapping C functions that take void* + length; holding a numeric address from previous FFI calls and passing it where a buffer is required; interop code that sometimes receives arrays or objects; passing an UnsafePointerView instance instead of the underlying buffer.","solutions":["Pass memory as a Uint8Array/DataView (ArrayBufferView) or the ArrayBuffer itself","For numeric addresses use Deno.UnsafePointer.create(value) (bigint) to obtain a pointer object instead of passing the number to of()","For callbacks, pass the Deno.UnsafeCallback instance; its .pointer is used automatically","Convert plain arrays: new Uint8Array([...]) before the call"],"exampleFix":"// before\nconst ptr = Deno.UnsafePointer.of(0x1000); // TypeError: received number\n\n// after\nconst ptr = Deno.UnsafePointer.create(0x1000n); // wrap a numeric address\nconst bufPtr = Deno.UnsafePointer.of(new Uint8Array([1, 2, 3])); // memory pointer","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isPointerSource(value) {\n  return value instanceof Deno.UnsafeCallback ||\n    ArrayBuffer.isView(value) ||\n    value instanceof ArrayBuffer ||\n    value instanceof SharedArrayBuffer;\n}\n\nconst ptr = isPointerSource(v)\n  ? Deno.UnsafePointer.of(v)\n  : Deno.UnsafePointer.create(BigInt(v)); // numeric addresses","tryCatchPattern":"try {\n  ptr = Deno.UnsafePointer.of(value);\n} catch (err) {\n  if (err instanceof TypeError && err.message.startsWith(\"Cannot access pointer\")) {\n    value = new Uint8Array(value); // coerce and retry once\n    ptr = Deno.UnsafePointer.of(value);\n  } else throw err;\n}","preventionTips":["Always pass typed arrays or buffers across the FFI boundary, never numbers or plain objects","Keep the two pointer APIs straight: of(memory) for buffers, create(bigint) for numeric addresses","Validate with ArrayBuffer.isView() at wrapper boundaries"],"tags":["ffi","unsafe-pointer","native","typeerror"],"backgroundTag":"invalid-argument-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}