---
title: "Fixing Top-Level Await in Safari"
description: "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."
url: "https://swe.quest/articles/fixing-top-level-await-in-safari-4919b25f6b19644e"
canonical: "https://webkit.org/blog/18227/fixing-top-level-await-in-safari/"
source: "WebKit"
published: "2026-09-02"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 7
tags: ["javascript","runtimes","browsers","testing"]
---

# Fixing Top-Level Await in Safari

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2026-09-02, 7 min read, Deep dive. Original: [https://webkit.org/blog/18227/fixing-top-level-await-in-safari/](https://webkit.org/blog/18227/fixing-top-level-await-in-safari/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)

## Prerequisites

- ES modules
- JavaScript async/await and Promises ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- dynamic import()

## Keywords

Safari 27, WebKit, JavaScriptCore, top-level await, ECMAScript, Bun, test262, WHATWG Loader

## Related posts

- [Bun v1.0.12](https://swe.quest/articles/bun-v1-0-12-7e77f90bbca6622e.md): Bun · 2023-11-16 · Medium · 12 min read · JavaScript, Runtimes & VMs, Testing, Developer tools
  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.
- [Bun v0.7.1](https://swe.quest/articles/bun-v0-7-1-5c9040e5c49cc1d7.md): Bun · 2023-07-29 · Medium · 8 min read · JavaScript, Runtimes & VMs, Performance engineering
  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.
- [Bun v1.3.7](https://swe.quest/articles/bun-v1-3-7-c2527b00781a4168.md): Bun · 2026-01-27 · Medium · 20 min read · JavaScript, Runtimes & VMs, Performance engineering, Developer tools
  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.
- [Bun v0.6.12](https://swe.quest/articles/bun-v0-6-12-dcf44324c9c4f6f2.md): Bun · 2023-06-30 · Medium · 4 min read · JavaScript, Runtimes & VMs, Debugging, Build systems
  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.
- [Bun v1.0.8](https://swe.quest/articles/bun-v1-0-8-561e5f115e18943c.md): Bun · 2023-11-02 · Medium · 7 min read · JavaScript, Runtimes & VMs, Testing
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
