-5

According to the web worker MDN docs(https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers), Promise is not in the available list. But when I try to debug in worker file, and console log the self object, it has Promise inside. The Promise screenshot

I try to run new Promise() in web worker, and it works.I am confused why I can call Promise in web worker

3
  • 1
    "In addition to the standard JavaScript set of functions [...]" Promises are part of core JS Commented May 8, 2024 at 3:09
  • Promises are documented as being "Standard built-in objects" here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… - safe to say anything in that page is part of the aforementioned "core JS" in the first comment Commented May 8, 2024 at 5:40
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented May 8, 2024 at 7:46

1 Answer 1

0

The article you made reference to (Functions and classes available to Web Workers) starts with the definition of its scope:

...there are a variety of functions available from the DOM to workers. This article provides a list of those.

In other words, it covers the features from the Web API which are available to Web Workers.

Promise is not part of the Web API, but part of the ECMAScript language specification.

Although workers run in another global context, the ECMAScript language specification (since ES 2015) requires that the global context defines Promise.

In a related article, Using Web Workers, Mozilla Contributors write:

The worker context is represented by a DedicatedWorkerGlobalScope object...

The linked article on DedicatedWorkerGlobalScope has:

Some additional global functions, namespaces objects, and constructors, not typically associated with the worker global scope, but available on it, are listed in the JavaScript Reference.

The linked JavaScript Reference article finally lists all built-is, including Promise.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.