UWSpace is currently experiencing technical difficulties resulting from its recent migration to a new version of its software. These technical issues are not affecting the submission and browse features of the site. UWaterloo community members may continue submitting items to UWSpace. We apologize for the inconvenience, and are actively working to resolve these technical issues.
 

A study of object creators in JavaScript

Loading...
Thumbnail Image

Date

2017-08-23

Authors

Yuning, Yu

Journal Title

Journal ISSN

Volume Title

Publisher

University of Waterloo

Abstract

Traditional object-oriented languages use typed classes to specify the shape and behaviour of objects. In JavaScript, object behaviour is less constrained. Learning how JavaScript programmers create objects can help us understand whether the programmers employ the notion of ``classes'', like those in Java, in JavaScript. In other words, we are trying to compare the creation of objects in JavaScript with Java classes, which create objects and describe the state and behaviour that the type of the object support. Our results have the potential to improve the performance of JavaScript and generality of typed extensions to JavaScript. An access site is the JavaScript code that accesses the properties of objects. We studied the access site to determine whether objects at the access site arise from different ``creators'', which are functions creating the objects, and to discover how prevalent multiple-creator access sites are. Moreover, whether the types of properties ever change is noteworthy: in classes, types of properties may not change. To answer the questions, we executed, recorded, and analyzed many JavaScript applications to obtain real-world data. We collected and analyzed logs from 7,753 web sites. The logs consist of nearly 390 GB of JSON strings. We collected these data through dynamically running modern JavaScript applications, or web sites, in our tool with the browser Firefox. Our results show that for half of selected web sites, there exists only one creator at every access site. And in fewer than 50\% of web sites, there exists more than one creator, though the total number of access sites with multiple creators is extremely small. Although creators with distinct names are considered as different by our definition, different creators may create same objects. Therefore, most object accesses in JavaScript do not come from different creators. As a result, we could employ type annotations for objects. However, our results show that the types of the properties in objects do sometimes change, especially in objects generated from user-defined functions. Thus, even if objects are mostly from one creator, that creator may not correspond neatly to a type. This may limit the advantages of using types for better performance. Combining these results, we conclude that while we can apply Java-like types to JavaScript, these types are far more fluid in JavaScript applications, and so there may be limited benefit.

Description

Keywords

LC Keywords

Citation