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 correctly 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. From 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 our validation set, demonstrating that a learning-based approach to detecting event-handling bugs 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.
翻译:在JavaScript社区,事件驱动程序被广泛采用,既在客户方面处理UI事件和AJAX请求,在服务器方面,处理UI事件和AJAX请求,又在服务器方面,满足诸如文件或网络 I/O 等长期运作模式。许多以事件为基础的API允许将事件名称指定为自由形式字符串,而不经过任何验证,可能导致一些事件丢失,没有听众登记,而且没有听众对从未发出事件进行死亡。在以往的工作中,Madsen et al. 提供了准确的静态分析,以发现这类问题,但其分析并不规模,因为它可能需要一些在程序规模上指数化的环境。在发现死听者或网络 I/O等时,我们集中了对基于事件的信息名称的问题,我们首先挖掘了一大堆的 JavaScript 代码,通过简单的静态分析,找出没有登记事件听众的代码片断,然后应用统计模型来识别异常模式,这往往表明对API的使用情况。从大规模评估到127,53.1的开放源、开源、开源访问Scarsliplical9 维护了25的实验代码基础,我们能够在测试中进行30次的测试中,我们测试的30次的校正的校正的校正的校正的校路路标定的校路标定的校正。