Abstract
Recently, promises were added to ECMAScript 6, the JavaScript standard, in order to provide better support for the asynchrony that arises in user interfaces, network communication, and non-blocking I/O. Using promises, programmers can avoid common pitfalls of event-driven programming such as event races and the deeply nested counterintuitive control ow referred to as “callback hell”. Unfortunately, promises have complex semantics and the intricate control– and data- ow present in promise-based code hinders program comprehension and can easily lead to bugs. The promise graph was proposed as a graphical aid for understanding and debugging promise-based code. However, it did not cover all promise-related features in ECMAScript 6, and did not present or evaluate any technique for constructing the promise graphs. In this paper, we extend the notion of promise graphs to include all promise-related features in ECMAScript 6, including default reactions, exceptions, and the synchronization operations race and all. Furthermore, we report on the construction and evaluation of PromiseKeeper, which performs a dynamic analysis to create promise graphs and infer common promise anti-patterns. We evaluate PromiseKeeper by applying it to 12 open source promise-based Node.js applications. Our results suggest that the promise graphs constructed by PromiseKeeper can provide developers with valuable information about occurrences of common anti-patterns in their promise-based code, and that promise graphs can be constructed with acceptable run-time overhead.
Supplemental Material
- Christoffer Quist Adamsen, Anders Møller, Rezwana Karim, Manu Sridharan, Frank Tip, and Koushik Sen. 2017b. Repairing Event Race Errors by Controlling Nondeterminism. In Proc. 39th International Conference on Software Engineering (ICSE). Google Scholar
Digital Library
- Christoffer Quist Adamsen, Anders Møller, and Frank Tip. 2017a. Practical Initialization Race Detection for JavaScript Web Applications. In Proc. ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) .Google Scholar
Digital Library
- Saba Alimadadi, Ali Mesbah, and Karthik Pattabiraman. 2015. Hybrid DOM-Sensitive Change Impact Analysis for JavaScript. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP). LIPIcs, 321–345.Google Scholar
- Saba Alimadadi, Ali Mesbah, and Karthik Pattabiraman. 2016a. Understanding Asynchronous Interactions in Full-Stack JavaScript. In Proceedings of the ACM/IEEE International Conference on Software Engineering (ICSE). ACM, 1169–1180. Google Scholar
Digital Library
- Saba Alimadadi, Ali Mesbah, and Karthik Pattabiraman. 2018. Inferring Hierarchical Motifs from Execution Traces. In Proceedings of the ACM/IEEE International Conference on Software Engineering (ICSE) . ACM, 12 pages. Google Scholar
Digital Library
- Saba Alimadadi, Sheldon Sequeira, Ali Mesbah, and Karthik Pattabiraman. 2016b. Understanding JavaScript Event-Based Interactions with Clematis. ACM Transactions on Software Engineering and Methodology (TOSEM) 25, 2 (2016), 38. Google Scholar
Digital Library
- Domenico Amalfitano, AnnaRita Fasolino, Armando Polcaro, and Porfirio Tramontana. 2014. The DynaRIA tool for the comprehension of Ajax web applications by dynamic analysis. Innovations in Systems and Software Engineering 10, 1 (2014), 41–57. Google Scholar
Digital Library
- Esben Andreasen, Liang Gong, Anders Møller, Michael Pradel, Marija Selakovic, Koushik Sen, and Cristian-Alexandru Staicu. 2017. A Survey of Dynamic Analysis and Test Generation for JavaScript. ACM Computing Surveys (CSUR) 50, 5 (2017), 66. Google Scholar
Digital Library
- Earl T. Barr, Mark Marron, Ed Maurer, Dan Moseley, and Gaurav Seth. 2016. Time-travel Debugging for JavaScript/Node.Js. In Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2016). ACM, 1003–1007. Google Scholar
Digital Library
- Giuseppe Di Battista, Peter Eades, Roberto Tamassia, and Ioannis G Tollis. 1998. Graph drawing: algorithms for the visualization of graphs . Prentice Hall PTR. Google Scholar
Digital Library
- Etienne Brodu, Stéphane Frénot, and Frédéric Oblé. 2015. Toward automatic update from callbacks to Promises. In Proceedings of the 1st Workshop on All-Web Real-Time Systems . ACM, 1. Google Scholar
Digital Library
- ECMA Ecmascript. 2015. Language Specification. (2015).Google Scholar
- Keheliya Gallaba, Quinn Hanam, Ali Mesbah, and Ivan Beschastnikh. 2017. Refactoring Asynchrony in JavaScript. In Proceedings of the International Conference on Software Maintenance and Evolution (ICSME) . IEEE Computer Society, 11 pages.Google Scholar
Cross Ref
- Erich Gamma. 1995. Design patterns: elements of reusable object-oriented software. Pearson Education India. Google Scholar
Digital Library
- Liang Gong, Michael Pradel, Manu Sridharan, and Koushik Sen. 2015. DLint: dynamically checking bad coding practices in JavaScript. In Proceedings of the 2015 International Symposium on Software Testing and Analysis. ACM, 94–105. Google Scholar
Digital Library
- Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. 2010. The essence of JavaScript. In European conference on Object-oriented programming . Springer, 126–150. Google Scholar
Digital Library
- Joshua Hibschman and Haoqi Zhang. 2015. Unravel: Rapid Web Application Reverse Engineering via Interaction Recording, Source Tracing, and Library Detection. In Proceedings of ACM User Interface Software and Technology Symposium (UIST). ACM, 270–279. Google Scholar
Digital Library
- Simon Holm Jensen, Manu Sridharan, Koushik Sen, and Satish Chandra. 2015. MemInsight: platform-independent memory debugging for JavaScript. In Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering. ACM, 345–356. Google Scholar
Digital Library
- Kennedy Kambona, Elisa Gonzalez Boix, and Wolfgang De Meuter. 2013. An evaluation of reactive programming and promises for structuring collaborative web applications. In Proceedings of the 7th Workshop on Dynamic Languages and Applications . ACM, 3. Google Scholar
Digital Library
- Yit Phang Khoo, Michael Hicks, Jeffrey S Foster, and Vibha Sazawal. 2009. Directing JavaScript with arrows. ACM SIGPLAN Notices 44, 12 (2009), 49–58. Google Scholar
Digital Library
- Matthew C Loring, Mark Marron, and Daan Leijen. 2017. Semantics of asynchronous JavaScript. In ACM SIGPLAN Notices, Vol. 52. ACM, 51–62. Google Scholar
Digital Library
- Magnus Madsen, Ondřej Lhoták, and Frank Tip. 2017. A Model for Reasoning About JavaScript Promises. In Object-Oriented Programming, Systems, Languages & Applications (OOPSLA) . Google Scholar
Digital Library
- Magnus Madsen, Frank Tip, Esben Andreasen, Koushik Sen, and Anders Møller. 2016. Feedback-directed instrumentation for deployed JavaScript applications. In Software Engineering (ICSE), 2016 IEEE/ACM 38th International Conference on. IEEE, 899–910. Google Scholar
Digital Library
- Magnus Madsen, Frank Tip, and Ondřej Lhoták. 2015. Static Analysis of Event-Driven Node.js JavaScript Applications. In Object-Oriented Programming, Systems, Languages & Applications (OOPSLA) . Google Scholar
Digital Library
- Josip Maras, Maja Stula, and Jan Carlson. 2013. Generating Feature Usage Scenarios in Client-side Web Applications. In Proceeding of the International Conference on Web Engineering (ICWE) . Springer, 186–200. Google Scholar
Digital Library
- Boris Petrov, Martin Vechev, Manu Sridharan, and Julian Dolby. 2012. Race detection for web applications. In ACM SIGPLAN Notices , Vol. 47. ACM, 251–262. Google Scholar
Digital Library
- PromiseKeeper 2018. PromiseKeeper. https://github.com/nuprl/PromiseKeeper . (2018).Google Scholar
- Veselin Raychev, Martin Vechev, and Manu Sridharan. 2013. Effective race detection for event-driven programs. In ACM SIGPLAN Notices , Vol. 48. ACM, 151–166. Google Scholar
Digital Library
- Koushik Sen, Swaroop Kalasapur, Tasneem Brutch, and Simon Gibbs. 2013. Jalangi: a selective record-replay and dynamic analysis framework for JavaScript. In Proceedings of the 2013 9th Joint Meeting on Foundations of Software Engineering. ACM, 488–498. Google Scholar
Digital Library
- Andy Zaidman, Nick Matthijssen, Margaret-Anne Storey, and Arie van Deursen. 2013. Understanding Ajax applications by connecting client and server-side execution traces. Empirical Software Engineering 18, 2 (2013), 181–218. Google Scholar
Digital Library
- Lu Zhang and Chao Wang. 2017. RClassify: Classifying Race Conditions in Web Applications via Deterministic Replay. In Proc. 39th International Conference on Software Engineering (ICSE) . Google Scholar
Digital Library
- Yunhui Zheng, Tao Bao, and Xiangyu Zhang. 2011. Statically locating web application bugs caused by asynchronous calls. In Proceedings of the 20th international conference on World wide web. ACM, 805–814. Google Scholar
Digital Library
Index Terms
Finding broken promises in asynchronous JavaScript programs
Recommendations
A model for reasoning about JavaScript promises
In JavaScript programs, asynchrony arises in situations such as web-based user-interfaces, communicating with servers through HTTP requests, and non-blocking I/O. Event-based programming is the most popular approach for managing asynchrony, but suffers ...
Discovering bug patterns in JavaScript
FSE 2016: Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software EngineeringJavaScript has become the most popular language used by developers for client and server side programming. The language, however, still lacks proper support in the form of warnings about potential bugs in the code. Most bug finding tools in use today ...






Comments