A model for reasoning about JavaScript promises

被引:16
|
作者
Madsen M. [1 ]
Lhoták O. [1 ]
Tip F. [2 ]
机构
[1] Madsen, Magnus
[2] Lhoták, Ondrej
[3] Tip, Frank
关键词
EcmaScript; 6; Formal semantics; !text type='Java']Java[!/text]Script; Promise graph; Promises;
D O I
10.1145/3133910
中图分类号
学科分类号
摘要
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. © 2017 Association for Computing Machinery.
引用
收藏
相关论文
共 50 条
  • [1] Reasoning About Promises in Weak Memory Models with Event Structures
    Wehrheim, Heike
    Bargmann, Lara
    Dongol, Brijesh
    FORMAL METHODS, FM 2023, 2023, 14000 : 282 - 300
  • [2] REASONING ABOUT MODEL ACCURACY
    WELD, DS
    ARTIFICIAL INTELLIGENCE, 1992, 56 (2-3) : 255 - 300
  • [3] A model of reasoning about knowledge
    Lu, RQ
    Ying, MS
    SCIENCE IN CHINA SERIES E-TECHNOLOGICAL SCIENCES, 1998, 41 (05): : 527 - 534
  • [4] A model of reasoning about knowledge
    陆汝钤
    应明生
    Science in China(Series E:Technological Sciences), 1998, (05) : 527 - 534
  • [5] A model of reasoning about knowledge
    Ruqian Lu
    Mingsheng Ying
    Science in China Series E: Technological Sciences, 1998, 41 : 527 - 534
  • [6] A model of reasoning about knowledge
    Institute of Mathematics, Chinese Academy of Sciences, Beijing 100080, China
    不详
    Sci China Ser E Technol Sci, 5 (x11-534):
  • [7] Finding Broken Promises in Asynchronous Java']JavaScript Programs
    Alimadadi, Saba
    Zhong, Di
    Madsen, Magnus
    Tip, Frank
    PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2018, 2
  • [8] A Model for Approximate Reasoning about Knowledge
    Li, Jun
    Lan, Qian
    2012 2ND INTERNATIONAL CONFERENCE ON APPLIED ROBOTICS FOR THE POWER INDUSTRY (CARPI), 2012, : 609 - 612
  • [9] All about the with statement in javascript: Removing with statements in javascript applications
    Park, Changhee
    Lee, Hongki
    Ryu, Sukyoung
    1600, Association for Computing Machinery, 2 Penn Plaza, Suite 701, New York, NY 10121-0701, United States (49): : 73 - 84
  • [10] All about the with statement in javascript: Removing with statements in javascript applications
    Park, Changhee
    Lee, Hongki
    Ryu, Sukyoung
    2013, Association for Computing Machinery, 2 Penn Plaza, Suite 701, New York, NY 10121-0701, United States : 73 - 84