Collecting Type Information Using Unit Tests for Customizing JavaScript Virtual Machines

To use JavaScript for Internet of Things (IoT), it is essential to reduce the size of the virtual machine (VM). Although operators in JavaScript are polymorphic, many applications apply operators to only a limited set of datatypes. Thus, customizing a VM to include only implementations of operators of datatypes used can reduce the size of the VM. In this research, we determine the set of operand datatypes that are possibly given to each operator for individual applications. Because JavaScript is a dynamically typed programming language, it is difficult to infer types accurately. Instead, as a practical approach, we obtain type information from executions of unit tests of the application. We implemented a prototype system to record datatypes that are given to each operator in executions of unit tests for Jasmine. The system does not record operands of operators executed by the Jasmine's code but only those by the application's code. We applied this system to two small applications and found that it determined type information with high accuracy.