Title: ffi: JavaScript wrappers make non-constructible native functions constructible · Issue #65183 · nodejs/node · GitHub
Open Graph Title: ffi: JavaScript wrappers make non-constructible native functions constructible · Issue #65183 · nodejs/node
X Title: ffi: JavaScript wrappers make non-constructible native functions constructible · Issue #65183 · nodejs/node
Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include
Open Graph Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include
X Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include <stdint.h> #include <stdio.h> int32_t add_i32(int32_t a, int32_t b) { fprintf(stderr...
Opengraph URL: https://github.com/nodejs/node/issues/65183
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: JavaScript wrappers make non-constructible native functions constructible","articleBody":"### Version\n\nmain\n\n### Platform\n\n```text\nmacOS 26.6.0\n```\n\n### Subsystem\n\nffi\n\n### What steps will reproduce the bug?\n\n`repro.c`\n```c\n#include \u003cstdint.h>\n#include \u003cstdio.h>\n\nint32_t add_i32(int32_t a, int32_t b) {\n fprintf(stderr, \"native add_i32 invoked: %d + %d\\n\", a, b);\n return a + b;\n}\n\ndouble multiply_f64(double a, double b) {\n return a * b;\n}\n```\n\n`repro.js`\n```js\nimport { dlopen, suffix } from 'node:ffi';\n\nconst { functions } = dlopen(`./repro.${suffix}`, {\n add_i32: {\n arguments: ['i32', 'i32'],\n return: 'i32',\n },\n multiply_f64: {\n arguments: ['f64', 'f64'],\n return: 'f64',\n },\n});\n\nconst { add_i32, multiply_f64 } = functions;\n\nconsole.log(\n 'add_i32 has own prototype:',\n Object.hasOwn(add_i32, 'prototype'),\n);\n\ntry {\n Reflect.construct(add_i32, [20, 22]);\n console.log('Reflect.construct(add_i32): succeeded');\n} catch (error) {\n console.log(\n 'Reflect.construct(add_i32):',\n `${error.name}: ${error.message}`,\n );\n}\n\nconsole.log(\n 'multiply_f64 has own prototype:',\n Object.hasOwn(multiply_f64, 'prototype'),\n);\n\ntry {\n Reflect.construct(multiply_f64, [6, 7]);\n console.log('Reflect.construct(multiply_f64): succeeded');\n} catch (error) {\n console.log(\n 'Reflect.construct(multiply_f64):',\n `${error.name}: ${error.message}`,\n );\n}\n```\n\nCommands to run:\n```sh\n$ cc -dynamiclib -o repro.dylib repro.c\n\n$ node --no-warnings --experimental-ffi repro.js\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\nWrapped functions should preserve the native function’s non-constructible behavior: no own `.prototype`, and `Reflect.construct()` should throw a `TypeError` without invoking native code.\n\n### What do you see instead?\n\n```console\nadd_i32 has own prototype: true\nnative add_i32 invoked: 20 + 22\nReflect.construct(add_i32): succeeded\nmultiply_f64 has own prototype: false\nReflect.construct(multiply_f64): TypeError: function multiply_f64() { [native code] } is not a constructor\n```\n\nWrapped native functions such as `add_i32` gain an own `.prototype`, and `Reflect.construct(add_i32, [20, 22])` succeeds and invokes native code.\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-08-10T05:41:53Z","url":"https://github.com/nodejs/node/issues/65183"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:92ba760d-2b09-c297-953f-14b83a3cd40f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC3C:2F339D:882CD4:B553B0:6AED2A08 |
| html-safe-nonce | d792d72d0324f1d619d9a11c416966f02b6fe3870a8c577102c1510cda401b05 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzNDOjJGMzM5RDo4ODJDRDQ6QjU1M0IwOjZBRUQyQTA4IiwidmlzaXRvcl9pZCI6Ijc2OTQ3MjEyNTAxODQ5OTczODQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8d0b2f0f322dcc640fc8b3eadd08b9079cf9f08857ef7a1a4167aaaed0e0f0c6 |
| hovercard-subject-tag | issue:5107017479 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/65183/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2b2d52ee431fedf2d2c6fd771fc4b2433b47654b67360a8acf7ff2e3e1bca96a/nodejs/node/issues/65183 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2b2d52ee431fedf2d2c6fd771fc4b2433b47654b67360a8acf7ff2e3e1bca96a/nodejs/node/issues/65183 |
| og:image:alt | Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trivikr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 98b41fa4b5635ceb45a4c54320fced73817ff290 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width