mdn / sprints

Archived: MDN Web Docs issues are tracked in the content repository.
https://github.com/mdn/content
Creative Commons Zero v1.0 Universal
150 stars 142 forks source link

Exact content of JavaScript stack frames #3932

Closed roninbar closed 3 years ago

roninbar commented 3 years ago

Request type

Details

The article says

When calling bar, a first frame is created containing bar's arguments and local variables. When bar calls foo, a second frame is created and pushed on top of the first one containing foo's arguments and local variables.

Conceptually, at least, the arguments and local variables in JS don't sit directly on the stack as they do in C, for example, but in an execution context which is referenced by a pointer in the stack frame, but which is actually allocated on the heap. That's how they can be accessed by nested functions long after the outer function has returned.

I suppose that some runtimes may optimize this behavior by first allocating the variables directly on the stack and then copying only the ones that are used by nested functions to a new execution context, but since this is a very high-level overview of the subject, wouldn't it be better not to give readers the false impression that the JS stack works exactly like the stack in C?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop

chrisdavidmills commented 3 years ago

Issue moved to mdn/content #1451 via ZenHub