Skip to content

v0.1.0-alpha.11

Choose a tag to compare

@Calcium-Ion Calcium-Ion released this 27 Oct 13:59
· 13 commits to main since this release
ffea310
  • The module path is now github.com/MoeForge/moejs, where the repository moved. To upgrade, change the import path and run go get github.com/MoeForge/moejs@v0.1.0-alpha.11. v0.1.0-alpha.10 and earlier keep github.com/Calcium-Ion/moejs.
  • The node package adds node:fs, node:fs/promises and node:buffer to a runtime with an event loop. Every path stays inside one directory the host picks, files are read-only unless the host allows writes, and an allow hook sees each access.
  • An await no longer allocates, and an async call allocates only its promise until its first await.
  • With the Web APIs installed, reading globals is as fast as in a bare runtime: a loop that reads three of them takes 29 ns an iteration instead of 390 ns. webapi.Install takes 1.2 µs instead of 12.6 µs.
  • default.pgo is recorded again under the new path. The profile in earlier releases named moejs's functions under an older path, so it never optimized moejs's own code.
  • DecodeOptions.MaxBytes counts invalid UTF-8 in a Go string the way json.Marshal writes it. (#7, thanks @yuluo-yx)

Apart from the module path, every API change is an addition. The full list is in ffea310.


  • 模块路径改为 github.com/MoeForge/moejs,也就是仓库的新地址。升级时把 import 路径改成新的,再执行 go get github.com/MoeForge/moejs@v0.1.0-alpha.11。v0.1.0-alpha.10 及以前的版本仍然在 github.com/Calcium-Ion/moejs。
  • 新增 node 包,在带事件循环的运行时上提供 node:fs、node:fs/promises 和 node:buffer。所有路径都限制在宿主指定的目录里,文件默认只读,宿主允许后才能写入,每次访问都要经过放行钩子。
  • await 不再分配内存,async 函数调用在第一次 await 之前只分配它的 promise。
  • 装了 Web API 后,读全局变量和没装时一样快:读三个全局变量的循环每次迭代从 390 ns 降到 29 ns,webapi.Install 从 12.6 µs 降到 1.2 µs。
  • default.pgo 按新路径重新录制。之前版本的样本里,moejs 的函数用的是更早的路径,所以 moejs 自己的代码一直没被优化到。
  • DecodeOptions.MaxBytes 对 Go 字符串里的非法 UTF-8,按 json.Marshal 实际写出的字节数计算。(#7,感谢 @yuluo-yx)

除了模块路径,所有 API 变化都是新增。完整改动见 ffea310。

moejs node:fs against Node.js