

JavaScript's Promises and new async/await syntax help programmers to deal with the "call-back-hell" of asynchronous JavaScript code. At least on a lexical level while editing source code. Understanding the dynamic behavior of asynchronous code can still be hard, since context information such as a call stack are lost and developing practices such as nesting log statements are not applicable. When the programmer has full control, the needed context information can usually be forwarded and remembered in domain specific ways, but sometimes framework or system code is in the way. An example for this is the dynamic loading of JavaScript modules in SystemJS, where log messages and side effects of dependent modules can be hard to trace back to the requesting module. Making Context-oriented Programming (COP) aware of such new scopes, makes it easier to maintain and make use of the lexical structure in the execution asynchronous code. We extended ContextJS, our Context-oriented language extension for JavaScript, so that Promises capture and keep layer activations. This new dynamic scope  allows us to better understand and debug the behavior of systems with complex asynchronous dependencies. 




