Skip to content

ffi: function .pointer is lost when Function.prototype.pointer is non-writable #67169

Open

Description

@trivikr

Version

main

Platform

macOS

Subsystem

ffi

What steps will reproduce the bug?

import { DynamicLibrary } from 'node:ffi';

Object.defineProperty(Function.prototype, 'pointer', {
  value: 1, writable: false, configurable: true,
});

const lib = new DynamicLibrary(null);
const abs = lib.getFunction('abs', { arguments: ['i32'], return: 'i32' });
console.log(abs.pointer);
console.log(abs(-5));

How often does it reproduce? Is there a required condition?

Always, as long as Function.prototype.pointer is non-writable before the function is created.
Functions returned by ffi.dlopen() and library.getFunctions() are affected the same way.

What is the expected behavior? Why is that the expected behavior?

6669613580n
5

The docs say the returned function "has a .pointer property containing the native function address as a bigint".
https://github.com/nodejs/node/blob/main/doc/api/ffi.md#librarygetfunctionname-signature

What do you see instead?

1
5

On the returned function, pointer is an own, writable data property with the value 1. The real address is never stored on it.

Additional information

No response

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added
    ffiIssues and PRs related to experimental Foreign Function Interface support.
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ffiIssues and PRs related to experimental Foreign Function Interface support.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions