{"id":15368065,"url":"https://github.com/anonrig/proposal-arraybuffer-detach","last_synced_at":"2026-04-29T01:08:03.179Z","repository":{"id":65992639,"uuid":"568246024","full_name":"anonrig/proposal-arraybuffer-detach","owner":"anonrig","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-28T19:32:29.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-02T07:11:26.519Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anonrig.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-19T22:43:31.000Z","updated_at":"2023-08-20T16:39:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"b48f4ab4-7651-42c5-b21f-a8a8ac4c7d57","html_url":"https://github.com/anonrig/proposal-arraybuffer-detach","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"85730ddb861e1add003b05ff395e3787f3775a34"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"tc39/template-for-proposals","purl":"pkg:github/anonrig/proposal-arraybuffer-detach","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fproposal-arraybuffer-detach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fproposal-arraybuffer-detach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fproposal-arraybuffer-detach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fproposal-arraybuffer-detach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anonrig","download_url":"https://codeload.github.com/anonrig/proposal-arraybuffer-detach/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fproposal-arraybuffer-detach/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32405949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:28:07.296Z","updated_at":"2026-04-29T01:08:03.151Z","avatar_url":"https://github.com/anonrig.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Performant \u0026 Safe ArrayBuffer validations\n\n## [Status](https://tc39.github.io/process-document/)\n\n**Stage**: -1\n\n**Authors/Champions**: (in alphabetical order)\n\n- Yagiz Nizipli (node.js / OpenJS Foundation, [@yagiznizipli](https://twitter.com/yagiznizipli)\n- Jordan Harband ([@ljharb](https://twitter.com/ljharb))\n\n## The problems\n\n### Detaching array buffers\n\nEfficiently and safely validating and reusing array buffers requires `detaching` and `transfering` of the underlying backing store.\n\nCurrent JavaScript features requires the use of `.slice()` in order to copy the underlying data of an `ArrayBuffer` to a new variable, which eventually doubles the memory usage (referencing the variable and the copied variable). The requirement of copying the arrayBuffer through a `slice` operation creates performance issues.\n\n### Check if array buffer is detached\n\nCurrently there isn't any performant way of detecting whether an ArrayBuffer is detached or not. Following JavaScript implementation is the only possible implementation in the JavaScript userland.\n\n```js\nconst assert = require('node:assert')\n\nfunction isBufferDetached(buffer) {\n  if (buffer.byteLength === 0) {\n    try {\n      new Uint8Array(buffer);\n    } catch (error) {\n      assert(error.name === 'TypeError');\n      return true;\n    }\n  }\n  return false\n}\n```\n\n## FAQ\n\n- What does `detach()` do?\n\nDetaches this ArrayBuffer and all its views (typed arrays). Detaching sets the byte length of the buffer and all typed arrays to zero, preventing JavaScript from ever accessing underlying backing store. ArrayBuffer should have been externalized and must be detachable.\n\n- What is the current usage for `detach()` in Node?\n\nNode.js uses it's own implementation of `detachArrayBuffer` in [`webstreams`](https://github.com/nodejs/node/blob/main/lib/internal/webstreams/util.js#L134) and readable streams.\n\n- What are the alternatives for `detach()`?\n\n Referencing [`ArrayBuffer.prototype.transfer()`](https://github.com/domenic/proposal-arraybuffer-transfer/tree/d4e00037420b87d0b5662c82b74d56b4ba1562ad#detaching-and-transferring) proposal:\n\n\u003e Some web platform APIs, notably the various postMessage() methods and the BYOB reader mode for ReadableStream, have a solution for this dillema. When you pass an ArrayBuffer (or wrapper around one, such as a typed array) to one of these APIs, they take ownership of the data block encapsulated in the ArrayBuffer.\n\n- Does any of the engines support a similar functionality?\n\nv8 \u0026 Webkit already supports similar functionality.\n\n## References\n\n- `detach()`\n    - [v8 API](https://v8docs.nodesource.com/node-18.2/d5/d6e/classv8_1_1_array_buffer.html#abb7a2b60240651d16e17d02eb6f636cf)\n    - [Webkit Implementation](https://github.com/WebKit/WebKit/blob/6545977030f491dd87b3ae9fd666f6b949ae8a74/Source/JavaScriptCore/runtime/ArrayBuffer.h#L307)\n    - [Node.js alternative Public API](https://github.com/nodejs/node/pull/45512)\n- `isDetached`\n    - [Node.js Internal Implementation](https://github.com/nodejs/node/pull/45568)\n    - [v8 implementation](https://github.com/v8/v8/commit/9df5ef70ff18977b157028fc55ced5af4bcee535)\n    - [Webkit implementation](https://github.com/WebKit/WebKit/blob/6545977030f491dd87b3ae9fd666f6b949ae8a74/Source/JavaScriptCore/runtime/ArrayBuffer.h#L308)\n    - [Node.js alternative Public API](https://github.com/nodejs/node/pull/45512)\n    - [v8 optimization issue on Node.js](https://github.com/nodejs/node/blob/main/lib/querystring.js#L472)\n\n## Possible Solutions\n\n### `ArrayBuffer.prototype.detach()`\n\nThis is a proposal to add a new method, `detach()`, to JavaScript's `ArrayBuffer` class. \n\n### `ArrayBuffer.prototype.isDetached`\n\nThis is a proposal to add a new instance variable, `isDetached`, to JavaScript's `ArrayBuffer` class.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanonrig%2Fproposal-arraybuffer-detach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanonrig%2Fproposal-arraybuffer-detach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanonrig%2Fproposal-arraybuffer-detach/lists"}