Learning How to Listen: Automatically Finding Bug Patterns in Event-Driven JavaScript APIs

Learning How to Listen: Automatically Finding Bug Patterns in Event-Driven JavaScript APIs
复制标题

DOI:
10.1109/tse.2022.3147975
复制
发表时间:
2021-07
影响因子:
7.4
通讯作者:
Ellen Arteca;M. Schäfer;F. Tip
Ellen Arteca;M. Schäfer;F. Tip
中科院分区:
计算机科学1区
文献类型:
--
作者:
Ellen Arteca;M. Schäfer;F. Tip

文献摘要

被引文献

相似文献

事件驱动的编程在JavaScript社区中广泛实践,无论是在客户端处理UI事件和AJAX请求,以及服务器端,以适应长期运行的操作,例如文件或网络I/O。许多受欢迎的基于事件的API允许事件名称指定为无验证的自由形式字符串,这可能导致丢失的事件,没有侦听器被注册,并且对从未发出的事件进行了死去的听众。在以前的工作中,Madsen等人。提出了用于检测此类问题的精确静态分析,但是它们的分析没有扩展,因为它可能需要许多在程序大小上指数的上下文。专注于检测死去的听众的问题,我们提出了一种方法,通过首先使用简单的静态分析挖掘大量的JavaScript代码来了解如何使用基于事件的API,以识别注册事件侦听器的代码段,然后应用统计建模以识别异常模式,这通常表明API使用不正确。在对127,531个开源JavaScript代码库的大规模评估中,我们的技术能够检测75种异常的听众注册模式,同时保持90.9%的精度为90.9%,并在验证集中召回了7.5%检测事件处理错误模式的方法是可行的。在另一个实验中,我们在25个开源项目中调查了这些模式的实例,并向项目维护者报告了30个问题,其中7个已被确认为错误。
Event-driven programming is widely practiced in the JavaScript community, both on the client side to handle UI events and AJAX requests, and on the server side to accommodate long-running operations such as file or network I/O. Many popular event-based APIs allow event names to be specified as free-form strings without any validation, potentially leading to lost events for which no listener has been registered and dead listeners for events that are never emitted. In previous work, Madsen et al. presented a precise static analysis for detecting such problems, but their analysis does not scale because it may require a number of contexts that is exponential in the size of the program. Concentrating on the problem of detecting dead listeners, we present an approach to learn how to use event-based APIs by first mining a large corpus of JavaScript code using a simple static analysis to identify code snippets that register an event listener, and then applying statistical modeling to identify anomalous patterns, which often indicate incorrect API usage. In a large-scale evaluation on 127,531 open-source JavaScript code bases, our technique was able to detect 75 anomalous listener-registration patterns, while maintaining a precision of 90.9% and recall of 7.5% over a validation set, demonstrating that a learning-based approach to detecting event-handling bug patterns is feasible. In an additional experiment, we investigated instances of these patterns in 25 open-source projects, and reported 30 issues to the project maintainers, of which 7 have been confirmed as bugs.