Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 7 min read Deep dive mediumAdept

Fixing Top-Level Await in Safari

Safari 27 fixes long-standing top-level await bugs, such as spurious "accessed before initialization" errors and wrong import completion order, by rewriting WebKit's ES module loader from scratch. The old loader was a self-hosted JavaScript builtin based on the abandoned 2016 WHATWG Loader proposal, so it resolved concurrent dynamic imports of a still-evaluating async module too early. The new loader is native C++ translated directly from the ECMAScript spec's module algorithms, chosen for faster startup and more predictable performance. It was validated with Bun's collected test cases, a differential fuzzer comparing module-graph output against other engines, test262 and WPT.

Assumes: ES modulesJavaScript async/await and Promisesdynamic import()

Related posts

  • Bun v1.0.12

    Bun mediumAdept

    Bun v1.0.12 fixes 24 bugs and adds `bun -e` for evaluating inline scripts (with TypeScript, JSX and top-level await), `--env-file` for choosing which .env files to load, `server.url`, `import.meta.env`, and `expect.unreachable()` in bun:test. Macros can now import builtin modules like node:fs and node:child_process at bundle time, and `mock.module` now handles default exports and re-exports. Two fixes include root-cause explanations: a bun:sqlite `.get()` hang came from a wrong JavaScriptCore JSType tag that misled the DFG JIT, and a `require()` crash came from source code being garbage collected before an exception was thrown. As a result, Bun's debug builds now run JavaScriptCore with assertions enabled.

  • Bun v0.7.1

    Bun mediumAdept

    Bun v0.7.1 makes ES Module loading 30%–250% faster by running its transpiler concurrently for import statements and dynamic imports, though CommonJS require is still sequential. Module resolution now happens only once, at runtime. The release also cuts vite dev startup on Linux by 90%, speeds up bun:sqlite row returns by 10%, and fixes getaddrinfo handling so private registries like Verdaccio work. Node.js compatibility fixes cover fs.watch thread usage, fs.stat truncation on large files, a GC bug in fs.readdir, and making the event loop wait for WebAssembly, Atomics and Web Crypto work, alongside new MessageChannel, fetch file: URLs and Promise.withResolvers support.

  • Bun v1.3.7

    Bun mediumAdept

    Bun v1.3.7 upgrades JavaScriptCore, which brings faster async/await (35%), Array.from, padStart/padEnd, array.flat and better ARM64 codegen using ccmp/ccmn chains. It also speeds up Buffer.from() with arrays by up to 50% and Buffer.swap16/swap64 by 1.8x and 3.6x through CPU intrinsics. New APIs include Bun.wrapAnsi (33–88x faster than the wrap-ansi npm package), native JSON5 parsing and imports, and Bun.JSONL with streaming parseChunk. For diagnostics there is Markdown CPU and heap profile output, --heap-prof heap snapshots and the node:inspector Profiler API. Compatibility fixes cover header case preservation in fetch, S3 presign options, bun pm pack lifecycle scripts, Indic grapheme clustering and Next.js 16 timer internals.

  • Bun v0.6.12

    Bun mediumAdept

    Bun v0.6.12 makes runtime errors more readable by patching JavaScriptCore to format Error.prototype.stack like V8, hiding internal builtin frames, and automatically sourcemapping stacks back to original (pre-transpile) source. It also improves CommonJS/ESM interop by inserting the __esModule annotation on require of ES modules and stops using package.json's "module" field at runtime to match Node.js resolution. Other changes include SQLite FTS5 full-text search, a new Bun.file(path).exists() method, node:http and node:stream fixes that unblock Google Maps and ytdl-core packages, a minifier rewrite of obj["a"] to obj.a, and several bundler bugfixes.

  • Bun v1.0.8

    Bun mediumAdept

    Bun v1.0.8 fixes 138 bugs, fixes a require() memory leak (introduced when built-in modules moved from ESM to CommonJS) that cuts memory up to 30%, and adds runtime module mocking to bun test via mock.module, which updates existing ESM and CJS imports in place. bun install no longer duplicates peer dependencies and now orders pre-release tags by semver precedence. Notable runtime fixes include a waitpid-thread fallback for Bun.spawn where pidfd_open is unavailable (gVisor, older kernels), a kqueue process-exit race on macOS, Node-aligned setTimeout(0) and setImmediate semantics, and fetch() silently accepting untrusted TLS certificates due to BoringSSL error handling.

The quest for software engineering knowledge.

Look:
Layout: