【24h】

Refactoring Asynchrony in JavaScript

机译:在JavaScript中重构Asynchrony

获取原文

摘要

JavaScript is a widely used programming language that makes extensive use of asynchronous computation, particularly in the form of asynchronous callbacks. These callbacks are used to handle tasks, from GUI events to network messages, in a non-blocking fashion. Asynchronous callbacks present developers with two challenges. First, JavaScript's try/catch error-handling mechanism is not sufficient for proper error handling in asynchronous contexts. In response, the JavaScript community has come to rely on the error-first protocol, an informal programming idiom that is not enforced or checked by the runtime. Second, JavaScript callbacks are frequently nested, making them difficult to handle (also known as callback hell). Fortunately, a recent language extension called promises provides an alternative to asynchronous callbacks. The adoption of promises, however, has been slow as refactoring existing code to use promises is a complex task. We present a set of program analysis techniques to detect instances of asynchronous callbacks and to refactor such callbacks, including callbacks with the error-first protocol, into promises. We implement our techniques in a tool called PROMISESLAND. We perform a manual analysis of four JavaScript applications to evaluate the tool's precision and recall, which are, on average, 100% and 83%, respectively. We evaluate PROMISESLAND on 21 large JavaScript applications, and find that PROMISESLAND (1) correctly refactors callbacks to promises, (2) outperforms a recent related refactoring technique, and (3) runs in under three seconds on all of our evaluation targets.
机译:JavaScript是一种广泛使用的编程语言,可以广泛使用异步计算,特别是以异步回调的形式。这些回调用于以非阻塞方式处理从GUI事件到网络消息的任务。异步回调目前有两个挑战的开发人员。首先,JavaScript的尝试/捕获错误处理机制不足以在异步上下文中处理正确的错误处理。作为响应,JavaScript社区已经依赖于错误的第一协议,这是一个非正式的编程成语,其不强制或检查运行时检查。其次,JavaScript回调经常嵌套,使它们难以处理(也称为回调地狱)。幸运的是,最近称为承诺的语言扩展为异步回调提供了替代方案。然而,承诺的采用缓慢,因为重构现有代码使用承诺是一个复杂的任务。我们展示了一组程序分析技术来检测异步回调的实例,并重构这些回调,包括带有错误第一协议的回调,进入承诺。我们在一个名为Promisesland的工具中实施我们的技术。我们对四个JavaScript应用程序进行了手动分析,以评估工具的精度和召回,分别平均为100 %和83 %。我们在21个大型JavaScript应用程序中评估ProMinesland,并发现Promisesland(1)正确地重构回调对承诺,(2)优于最近的相关重构技术,并且(3)在所有评估目标上三秒钟内运行。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号