Identifying Classes in Legacy JavaScript Code

JavaScript is the most popular programming language for the Web. Although the language is prototype‐based, developers can emulate class‐based abstractions in JavaScript to master the increasing complexity of their applications. Identifying classes in legacy JavaScript code can support these developers at least in the following activities: (1) program comprehension; (2) migration to the new JavaScript syntax that supports classes; and (3) implementation of supporting tools, including IDEs with class‐based views and reverse engineering tools. In this paper, we propose a strategy to detect class‐based abstractions in the source code of legacy JavaScript systems. We report on a large and in‐depth study to understand how class emulation is employed, using a dataset of 918 JavaScript applications available on GitHub. We found that almost 70% of the JavaScript systems we study make some usage of classes. We also performed a field study with the main developers of 60 popular JavaScript systems to validate our findings. The overall results range from 97% to 100% for precision, from 70% to 89% for recall, and from 82% to 94% for F‐score.

[1]  Gerald W. Both,et al.  Object-oriented analysis and design with applications , 1994 .

[2]  Jan Vitek,et al.  An analysis of the dynamic behavior of JavaScript programs , 2010, PLDI '10.

[3]  Christopher Krügel,et al.  Cross Site Scripting Prevention with Dynamic Data Tainting and Static Analysis , 2007, NDSS.

[4]  Yvonne Koch,et al.  Javascript The Good Parts , 2016 .

[5]  Frank Tip,et al.  Tool-supported refactoring for JavaScript , 2011, OOPSLA '11.

[6]  Steve Counsell,et al.  Power law distributions in class relationships , 2003, Proceedings Third IEEE International Workshop on Source Code Analysis and Manipulation.

[7]  Marco Tulio Valente,et al.  JSClassFinder: A Tool to Detect Class-like Structures in JavaScript , 2016, ArXiv.

[8]  Arie van Deursen,et al.  Understanding Ajax applications by connecting client and server-side execution traces , 2012, Empirical Software Engineering.

[9]  Ali Mesbah,et al.  Understanding JavaScript event-based interactions , 2014, ICSE.

[10]  Sophia Drossopoulou,et al.  Towards Type Inference for JavaScript , 2005, ECOOP.

[11]  Ewan D. Tempero,et al.  Understanding the shape of Java software , 2006, OOPSLA '06.

[12]  Oscar Nierstrasz,et al.  The story of moose: an agile reengineering environment , 2005, ESEC/FSE-13.

[13]  Ricardo Terra,et al.  Qualitas.class corpus: a compiled version of the qualitas corpus , 2013, SOEN.

[14]  Diomidis Spinellis,et al.  Power laws in software , 2008, TSEM.

[15]  Jan Vitek,et al.  The Eval That Men Do - A Large-Scale Study of the Use of Eval in JavaScript Applications , 2011, ECOOP.

[16]  Ivan Beschastnikh,et al.  Don't Call Us, We'll Call You: Characterizing Callbacks in Javascript , 2015, 2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM).

[17]  Kristin Decker,et al.  Uml Distilled A Brief Guide To The Standard Object Modeling Language , 2016 .

[18]  Marco Tulio Valente,et al.  Extracting relative thresholds for source code metrics , 2014, 2014 Software Evolution Week - IEEE Conference on Software Maintenance, Reengineering, and Reverse Engineering (CSMR-WCRE).

[19]  Jan Vitek,et al.  Eval begone!: semi-automated removal of eval from javascript programs , 2012, OOPSLA '12.

[20]  Michele Lanza,et al.  Object-Oriented Metrics in Practice - Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-Oriented Systems , 2006 .

[21]  Ajay Chander,et al.  JavaScript instrumentation for browser security , 2007, POPL '07.

[22]  Mauricio A. Saca Refactoring improving the design of existing code , 2017, 2017 IEEE 37th Central America and Panama Convention (CONCAPAN XXXVII).

[23]  Alex MacCaw The Little Book on CoffeeScript , 2012 .

[24]  Coen De Roover,et al.  Detecting function purity in JavaScript , 2015, 2015 IEEE 15th International Working Conference on Source Code Analysis and Manipulation (SCAM).

[25]  Holger M. Kienle It's About Time to Take JavaScript (More) Seriously , 2010, IEEE Software.

[26]  D. Flannanghan JavaScript: The definitive guide , 1999 .

[27]  Shriram Krishnamurthi,et al.  Using static analysis for Ajax intrusion detection , 2009, WWW '09.

[28]  Frank Tip,et al.  Refactoring towards the good parts of javascript , 2011, OOPSLA Companion.

[29]  Stéphane Ducasse,et al.  Distribution Map , 2006, 2006 22nd IEEE International Conference on Software Maintenance.

[30]  James R. Cordy,et al.  Normalizing object-oriented class styles in JavaScript , 2012, 2012 14th IEEE International Symposium on Web Systems Evolution (WSE).

[31]  Grady Booch,et al.  Object Oriented Analysis And Design With Applications 3Rd Edition , 2009 .

[32]  Chris F. Kemerer,et al.  A Metrics Suite for Object Oriented Design , 2015, IEEE Trans. Software Eng..

[33]  Amin Milani Fard,et al.  JSNOSE: Detecting JavaScript Code Smells , 2013, 2013 IEEE 13th International Working Conference on Source Code Analysis and Manipulation (SCAM).

[34]  Hung Viet Nguyen,et al.  Mining interprocedural, data-oriented usage patterns in JavaScript web applications , 2014, ICSE.

[35]  Shriram Krishnamurthi,et al.  The Essence of JavaScript , 2010, ECOOP.

[36]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[37]  Karthik Pattabiraman,et al.  JavaScript Errors in the Wild: An Empirical Study , 2011, 2011 IEEE 22nd International Symposium on Software Reliability Engineering.

[38]  Arie van Deursen,et al.  Software engineering for the web: the state of the practice , 2014, ICSE Companion.

[39]  Randall B. Smith,et al.  SELF: The power of simplicity , 1987, OOPSLA '87.

[40]  Marco Tulio Valente,et al.  Does JavaScript software embrace classes? , 2015, 2015 IEEE 22nd International Conference on Software Analysis, Evolution, and Reengineering (SANER).

[41]  Alan Borning,et al.  Classes versus Prototypes in Object-Oriented Languages , 1986, FJCC.

[42]  Claes Wohlin,et al.  Experimentation in Software Engineering , 2000, The Kluwer International Series in Software Engineering.

[43]  Ali Mesbah,et al.  Hybrid DOM-Sensitive Change Impact Analysis for JavaScript , 2015, ECOOP.