napi backend: class-cluster return values lose their concrete API surface — NSURLSessionWebSocketTask arrives bridged as NSURLSessionTask

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

メンテナーはふだん 1 日以内に返信

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
22/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cpp, objective-c
領域
desktop-dev

調査の方向性

The problem is in how the napi backend picks a JS wrapper for a returned Objective-C object: the isa-chain walk stops at the first metadata-registered class, which lands above the declared return type. Start from that resolution step and reproduce with NSURLSession.sharedSession.webSocketTaskWithURL, checking whether sendMessageCompletionHandler is present on the returned wrapper. Done means the wrapper exposes the NSURLSessionWebSocketTask members without the setPrototypeOf workaround; the fix design needs maintainer input first.

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

説明

Summary

When a bridged API returns a private class-cluster subclass, the JS wrapper is resolved by walking the real isa chain to the first metadata-registered class — so it lands below the declared return type and the concrete API surface is unreachable from JS.

NSURLSession.sharedSession.webSocketTaskWithURL(...) returns __NSURLSessionWebSocketTask (isa chain: __NSURLSessionWebSocketTask → __NSCFLocalSessionTask → NSURLSessionTask → NSObject). NSURLSessionWebSocketTask is metadata-registered and fully bridged — its prototype has every member — and task.isKindOfClass(NSURLSessionWebSocketTask) is true, but the returned wrapper exposes only NSURLSessionTask members: sendMessageCompletionHandler and receiveMessageWithCompletionHandler are undefined, so calls throw TypeError. Private cluster classes can't enter public-header metadata, so the ws level is never reached by the isa walk.

Expected

When isa-walk resolution lands on an ancestor of the metadata-declared return type, the wrapper could be built from the declared type; alternatively, an opt-in way to repoint a wrapper to a registered subclass the object isKindOfClass:es would cover the same ground.

Workaround we run today: Object.setPrototypeOf(task, NSURLSessionWebSocketTask.prototype) when the ws members are missing — every member then dispatches correctly, including closeCode/closeReason. A minimal regression check for a fix is that the returned task exposes sendMessageCompletionHandler without the repoint.

Environment

  • NativeScript/runtimes 5b697b39, generic napi backend, TARGET_PLATFORM=macos, arm64
  • NSURLSessionWebSocketTask requires macOS 10.15+; runtime-verified — this is wrapper resolution, not a metadata absence.
主要言語
C++
スター
27
フォーク
4
平均マージ
5日 11時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

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

NativeScript/runtimes のほかの issue

NativeScript/runtimes の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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