nodejs / nodejs/node-addon-api

Unify handling of string-like arguments across the API

オープン
#1,745 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

SemVer-major
主要言語
C++
スター
2.4k
フォーク
499
平均マージ
2日 11時間
マージ済み PR(30日)
2

説明

Follow-up to #1741 / #1742.

Several APIs still carry multiple overloads for different string types. Now that the library requires C++17, we can modernize by preferring std::string_view and removing the redundant UTF-8 overloads, replacing them with a single constrained template, as a semver-major change.

For String::New, Symbol::New, and Symbol::For, collapse the const std::string& + std::string_view pair into:

template <typename T,
          std::enable_if_t<
              std::is_convertible_v<const T&, std::string_view> &&
              !std::is_convertible_v<const T&, const char*>, int> = 0>
static String New(napi_env env, const T& t);

This matches the C++17 standard-library idiom (std::string's find/append/compare/… members). The !is_convertible_v<const T&, const char*> clause keeps const char* and literals on the dedicated overload and filters nullptr (avoiding a UB string_view(nullptr)).

The enable_if alias is shareable across APIs e.g. enable_if_string_view_like_t<T>.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず String::New、Symbol::New、Symbol::For の宣言と実装を見つけ、次にそれらに既存する std::string および std::string_view のオーバーロードを比較します。冗長なオーバーロードが制約付きの string_view 風テンプレートによって統合され、const char* とリテラルは専用の処理を維持し、nullptr は引き続き除外されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
api
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。