# @exodus/patch-broken-hermes-typed-arrays 中文文档

规范地址：https://npmcn.com/package/%40exodus/patch-broken-hermes-typed-arrays/

版本：1\.0\.0-alpha\.1
npm 元数据更新时间：2026-10-06T21:01:57.242Z
中文译文更新时间：2026-11-14T03:54:26.499Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40exodus/patch-broken-hermes-typed-arrays
原文对照：https://npmcn.com/package/%40exodus/patch-broken-hermes-typed-arrays/?lang=original
项目主页：https://github.com/ExodusMovement/patch-broken-hermes-typed-arrays
源码仓库：https://github.com/ExodusMovement/patch-broken-hermes-typed-arrays

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：13.4 kB，5 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2024-08-15T07:37:34.488Z
- 最新版本发布：2024-08-17T19:11:15.670Z
- 近 30 天下载量：42203（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

修复损坏的 Hermes 引擎 Typed Array 执行

## 安装

```sh
npm install @exodus/patch-broken-hermes-typed-arrays
```

也可以使用：`pnpm add @exodus/patch-broken-hermes-typed-arrays`、`yarn add @exodus/patch-broken-hermes-typed-arrays`、`bun add @exodus/patch-broken-hermes-typed-arrays`

## README

# `@exodus/patch-broken-hermes-typed-arrays`

修复损坏的 Hermes 引擎 Typed Array 执行

简而言之:

```js
import '@exodus/patch-broken-hermes-typed-arrays'
```

## 这是什么?

这一问题背后的问题:

```js
> Buffer.alloc(10).subarray(0).toString('hex')
'0,0,0,0,0,0,0,0,0,0'
// What?
```

你可能倾向于固定投出物的具体位置(例如: `Buffer.from`但这是个错误.

最重要的是: **很难追踪到这些**。 。 。 .

_还有.., `Buffer.from(arg)` 是一份副本,是无效的, `Buffer.from(x.buffer, x.byteOffset, x.byteLength)` 尴尬,容易犯人类错误,而且可以 启动安全检查 `buffer.buffer` 手动( 这是不安全的) 实践,例如错误类型 `x.byteLegnth` 可以通过曝光向其他用户泄露密码/秘密 无关的应用程序内存). 你不想在你的密码库里复制一吨的图案._

把这个修好 `Buffer` (例如用猴子来打它)也是不够的——你的密码库可以 包括捆绑的多个依赖关系 [缓冲](https://www.npmjs.com/package/buffer),还有所有 那些事件不会那样解决的!

此外,这影响到的不仅仅是 `Buffer` 超过 `subarray` - Hermes引擎没有执行 [已键入阵列](https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object) 对.

即赫尔姆斯 `TypedArray` 不遵循这些规格:

-   [ECMAScript 语言规格, `%TypedArray%.prototype.subarray`](https://tc39.es/ecma262/#sec-%typedarray%.prototype.subarray)
-   [ECMAScript 语言规格, `%TypedArray%.prototype.map`](https://tc39.es/ecma262/#sec-%typedarray%.prototype.map)
-   [ECMAScript 语言规格, `%TypedArray%.prototype.filter`](https://tc39.es/ecma262/#sec-%typedarray%.prototype.filter)
-   [ECMAScript 语言规格, `%TypedArray%.prototype.slice`](https://tc39.es/ecma262/#sec-%typedarray%.prototype.slice)

## 修补

总的来说,这个模块仅仅是以下片段的被颂扬的版本(但带有 `.map`编号 :`.filter` 对Hermes的更新提供支持和保障,以发现情况是否发生变化.

```js
TypedArray.prototype.subarray = function (...args) {
  var arr = subarray.apply(this, args)
  if (!this.constructor || arr.constructor === this.constructor) return arr
  return new this.constructor(arr.buffer, arr.byteOffset, arr.length)
}
```

注:如果赫尔墨斯执行可调整范围,上述版本可能不符合规格 `TypedArray`编号 从ECMAScript 2024, 或例如开始支持 `Symbol.Species`

上面的片段也没有赫尔墨斯的检查,所以如果选中的话,它也会盲目补丁阵列 切换到 JavaScript Core

_这就是为什么这个模块的存在——它处理所有_

## 问题的细节

例如与 [缓冲](https://www.npmjs.com/package/buffer)数字 :

```js
// ... import Buffer polyfill from https://npmjs.com/package/buffer
// ... and a console.log polyfill
console.log(Buffer.alloc(2).subarray(0, 1).constructor.name)
console.log(Buffer.alloc(2).map(() => 1).constructor.name)
console.log(Buffer.alloc(2).filter(() => true).constructor.name)
```

```console
% node buftest.0.js                                         
Buffer
Buffer
Buffer
% jsc buftest.0.js 
Buffer
Buffer
Buffer
% hermes buftest.0.js
Uint8Array
Uint8Array
Uint8Array
```

### 这不限于 `buffer`

```js
// Let's assume this will get transpiled for a demo, Hermes has no `class` support

class TestArray extends Uint16Array {
  static instances = 0
  constructor(...args) {
    super(...args)
    // console.log('We can do something here!')
    TestArray.instances++ // count constructor calls
    return this
  }

  hello() {
    return 'hi there'
  }
}

var arr = new TestArray(10)
// TestArray.instances: 1

var mapped = arr.map((_, i) => i * 10)
// TestArray.instances: 2

console.log(TestArray.instances) // 2 everywhere, but 1 in Hermes
console.log(mapped.constructor.name) // 'TestArray' everywhere, but 'Uint16Array' in Hermes
console.log(mapped.hello()) // throws in Hermes
```

## 许可证

[麻省理工学院](https://npmcn.com/package/%40exodus/patch-broken-hermes-typed-arrays/LICENSE)

## 常见问题

### @exodus/patch-broken-hermes-typed-arrays 是什么？

修复损坏的 Hermes 引擎 Typed Array 执行

### 如何安装 @exodus/patch-broken-hermes-typed-arrays？

在项目目录运行 npm install @exodus/patch-broken-hermes-typed-arrays，或使用 pnpm add / yarn add / bun add。

### @exodus/patch-broken-hermes-typed-arrays 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/exodus\_\_patch-broken-hermes-typed-arrays 是否存在。

### @exodus/patch-broken-hermes-typed-arrays 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @exodus/patch-broken-hermes-typed-arrays 可以商用吗？

@exodus/patch-broken-hermes-typed-arrays 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @exodus/patch-broken-hermes-typed-arrays 的下载量有多少？

根据 npm 官方下载统计，@exodus/patch-broken-hermes-typed-arrays 在 2026/10/14 – 2026/11/12 这 30 天内被下载 42,203 次，日均约 1,407 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @exodus/patch-broken-hermes-typed-arrays 还在维护吗？

最新版本 1\.0\.0-alpha\.1 发布于 2024/08/18（2 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2024/08/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

