skip to main content
research-article
Open Access

A model for reasoning about JavaScript promises

Published:12 October 2017Publication History
Skip Abstract Section

Abstract

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 from problems such as lost events and event races, and results in code that is hard to understand and debug. Recently, ECMAScript 6 has added support for promises, an alternative mechanism for managing asynchrony that enables programmers to chain asynchronous computations while supporting proper error handling. However, promises are complex and error-prone in their own right, so programmers would benefit from techniques that can reason about the correctness of promise-based code.

Since the ECMAScript 6 specification is informal and intended for implementers of JavaScript engines, it does not provide a suitable basis for formal reasoning. This paper presents λp, a core calculus that captures the essence of ECMAScript 6 promises. Based on λp, we introduce the promise graph, a program representation that can assist programmers with debugging of promise-based code. We then report on a case study in which we investigate how the promise graph can be helpful for debugging errors related to promises in code fragments posted to the StackOverflow website.

References

  1. Christoffer Quist Adamsen, Anders Møller, Rezwana Karim, Manu Sridharan, Frank Tip, and Koushik Sen. 2017. Repairing Event Race Errors by Controlling Nondeterminism. In Proc. 39th International Conference on Software Engineering (ICSE). Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Esben Andreasen and Anders Møller. 2014. Determinacy in static analysis for jQuery. In Proc. 29th ACM SIGPLAN International Conference on Object Oriented Programming Systems Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Petka Antonov. 2013. bluebird. https://github.com/petkaantonov/bluebird . (2013). Accessed: 2016-10-27.Google ScholarGoogle Scholar
  4. ECMA. 2015. 262: ECMAScript Language Specification. European Association for Standardizing Information and Communication Systems (ECMA) (2015).Google ScholarGoogle Scholar
  5. Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. 2009. Semantics Engineering with PLT Redex. The MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Cormac Flanagan and Matthias Felleisen. 1995. The Semantics of Future and its use in Program Optimization. In Proc. 22nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Cormac Flanagan and Matthias Felleisen. 1999. The Semantics of Future and an Application. Journal of Functional Programming (1999).Google ScholarGoogle Scholar
  8. Daniel Friedman and David Wise. 1976. The Impact of Applicative Programming on Multiprocessing. In International Conference on Parallel Processing.Google ScholarGoogle Scholar
  9. Salvatore Guarnieri and Benjamin Livshits. 2009. GATEKEEPER: Mostly Static Enforcement of Security and Reliability Policies for JavaScript Code. In Proc. 18th Usenix Security Symposium.Google ScholarGoogle Scholar
  10. Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. 2010. The Essence of JavaScript. In Proc. 24th European Conference on Object-oriented Programming (ECOOP). Google ScholarGoogle ScholarCross RefCross Ref
  11. Shin Hong, Yongbae Park, and Moonzoo Kim. 2014. Detecting Concurrency Errors in Client-Side Java Script Web Applications. In Proc. 7th IEEE International Conference on Software Testing, Verification and Validation (ICST). Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. David Van Horn and Matthew Might. 2010. Abstracting Abstract Machines. In Proc. 15th ACM International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Casper Svenning Jensen, Anders Møller, Veselin Raychev, Dimitar Dimitrov, and Martin T. Vechev. 2015. Stateless Model Checking of Event-Driven Applications. In Proc. 30th ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Simon Holm Jensen, Peter Jonsson, and Anders Møller. 2012. Remedying the Eval That Men Do. In Proc. International Symposium on Software Testing and Analysis (ISSTA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Simon Holm Jensen, Magnus Madsen, and Anders Møller. 2011. Modeling the HTML DOM and Browser API in Static Analysis of JavaScript Web Applications. In Proc. 8th joint meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on the Foundations of Software Engineering (ESEC/FSE). Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Simon Holm Jensen, Anders Møller, and Peter Thiemann. 2009. Type Analysis for JavaScript. In Proc. 16th International Static Analysis Symposium (SAS). Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Vineeth Kashyap, Kyle Dewey, Ethan Kuefner, John Wagner, Kevin Gibbons, John Sarracino, Ben Wiedermann, and Ben Hardekopf. 2014. JSAI: A Static Analysis Platform for JavaScript. In Proc. 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE).Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Kris Kowal. 2010. Q. https://github.com/kriskowal/q . (2010). Accessed: 2016-10-27.Google ScholarGoogle Scholar
  19. Magnus Madsen and Esben Andreasen. 2014. String Analysis for Dynamic Field Access. In Proc. 23rd International Conference on Compiler Construction (CC). Google ScholarGoogle ScholarCross RefCross Ref
  20. Magnus Madsen, Benjamin Livshits, and Michael Fanning. 2013. Practical Static Analysis of JavaScript Applications in the Presence of Frameworks and Libraries. In Proc. European Software Engineering Conference and the Symposium on the Foundations of Software Engineering (ESEC/FSE). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Magnus Madsen and Anders Møller. 2014. Sparse Dataflow Analysis with Pointers and Reachability. In Proc. 21st International Static Analysis Symposium (SAS). Google ScholarGoogle ScholarCross RefCross Ref
  22. Magnus Madsen, Frank Tip, and Ondřej Lhoták. 2015. Static Analysis of Event-driven Node.Js JavaScript Applications. In Proc. ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA).Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Sergio Maffeis, John C. Mitchell, and Ankur Taly. 2008. An Operational Semantics for JavaScript. In Asian Symposium on Programming Languages and Systems. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Erdal Mutlu, Serdar Tasiran, and Benjamin Livshits. 2015. Detecting JavaScript Races that Matter. In Proc. 10th Joint Meeting on Foundations of Software Engineering (ESEC/FSE). Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Boris Petrov, Martin T. Vechev, Manu Sridharan, and Julian Dolby. 2012. Race Detection for Web Applications. In Proc. 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Veselin Raychev, Martin T. Vechev, and Manu Sridharan. 2013. Effective Race Detection for Event-Driven Programs. In Proc. 28th ACM SIGPLAN International Conference on Object Oriented Programming Systems Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Adam Welc, Suresh Jagannathan, and Antony Hosking. 2005. Safe Futures for Java. Proc. 20th ACM SIGPLAN International Conference on Object Oriented Programming Systems Languages, and Applications (OOPSLA) (2005). Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. Yunhui Zheng, Tao Bao, and Xiangyu Zhang. 2011. Statically Locating Web Application Bugs Caused by Asynchronous Calls. In Proc. 20th International Conference on World Wide Web (WWW). Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A model for reasoning about JavaScript promises

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!