tc39 / tc39/proposal-immutable-arraybuffer
Expose whether an `ArrayBuffer` is detachable
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 38
- Forks
- 7
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
There is a pre-existing problem with ArrayBuffers in that it is not always possible to determine up-front whether or not a particular instance will succeed in being detached when asked to be transferred. Prior to this proposal, the notable case of an undetectable non-detachable buffer was the buffer exposed by WebAssembly.Memory. (This is as opposed to SharedArrayBuffer, which can be detected via instanceof.)
This proposal adds a new reason that an ArrayBuffer might not be detachable, and it requires a kind-specific check (.immutable) to make the detachability determination. And it seems likely that this won't be the last kind of buffer that won't be detachable.
I'd like to suggest that the fact of detachability be directly represented as a detachable: boolean property. It would be true exactly when a request to transfer() would succeed based on the detachability criterion. The choice of polarity here is intentional, in that an implementation without the property would fail-safe in terms of client code trying to decide between copy or transfer.
To be clear, it is currently possible to recover from a failed transfer with try-catch if one is trying to implement copy-or-transfer. However, that means that a correct case would have to accept the inefficiency of generating and catching an exception. And beyond that inefficiency, it does not make for particularly ergonomic code. And, in general, it's just plain useful to be able to make the determination without actually trying.
I actually ran into exactly this case (wrt WebAssembly.Memory) and during my search for a resolution ended up finding this proposal. So I figured it'd be worth raising the suggestion here. In my case, it was preferable to accept that my code will throw rather than silently degrade performance (punting the performance problem to the caller), but I'd really rather not be in the position to have to make that tradeoff.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner les règles actuelles de détachabilité de ArrayBuffer et le comportement de transfer() décrit dans cette issue. Évaluez si une propriété booléenne de détachabilité s’intègre à la proposition, y compris la polarité indiquée et le cas de WebAssembly.Memory ; le travail est terminé lorsqu’une décision de spécification a été prise et documentée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100