Skip to content

feat(buffer): support C++20 std::span overloads - #1760

Open
dave-365 wants to merge 1 commit into
nodejs:mainfrom
dave-365:feat/cpp20-std-span
Open

dave-365 wants to merge 1 commit into
nodejs:mainfrom
dave-365:feat/cpp20-std-span

Conversation

@dave-365

@dave-365 dave-365 commented Nov 4, 2026

Copy link
Copy Markdown

Fixes #1747

Description

This PR introduces C++20 std::span overloads for buffer-like types (Buffer<T>, ArrayBuffer, and TypedArrayOf<T>), allowing developers to pass bounds-carrying handles directly without manually managing separate raw pointers and length parameters:

  • Added Buffer<T>::New, Buffer<T>::NewOrCopy, and Buffer<T>::Copy overloads accepting std::span.
  • Added ArrayBuffer::New overloads accepting std::span.
  • Added .Span() accessors to Buffer<T>, ArrayBuffer, and TypedArrayOf<T>.
  • All std::span APIs are conditionally compiled under #if defined(__cpp_lib_span).
  • Completely preserves ABI compatibility and backward compatibility for C++ < 20.
  • Added comprehensive unit tests in test/buffer.cc and test/array_buffer.cc.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.75%. Comparing base (25c6b21) to head (1803c34).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1760      +/-   ##
==========================================
+ Coverage   63.68%   63.75%   +0.07%     
==========================================
  Files           3        3              
  Lines        2065     2072       +7     
  Branches      731      733       +2     
==========================================
+ Hits         1315     1321       +6     
  Misses        162      162              
- Partials      588      589       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Need Triage

Development

Successfully merging this pull request may close these issues.

Support C++20 span types

2 participants