Skip to content

Instantly share code, notes, and snippets.

@alice
Last active June 5, 2020 21:55
Show Gist options
  • Save alice/36b7e6166fc8c4c8ded87b5f47313fe8 to your computer and use it in GitHub Desktop.
Save alice/36b7e6166fc8c4c8ded87b5f47313fe8 to your computer and use it in GitHub Desktop.

Data accessed from JavaScript APIs must not be modified while a JavaScript event loop is running.

A JavaScript Web API is generally a wrapper around a feature implemented in a lower-level language, such as C++ or Rust. Unlike those languages, JavaScript guarantees that once a piece of code begins executing, it will continue executing until it has completed.

Because of that, JavaScript developers take for granted that the data available to a function won’t change (unless that function changes that data itself).

So if a JavaScript Web API exposes some piece of data, such as an object property, the user agent must not update that data while a JavaScript task is running. Instead, if the underlying data changes, queue a task to modify the exposed version of the data.

For example: If a JavaScript task is has accessed the navigator.onLine property, and browser's online status changes, the property will not be updated until the next task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment