Determining dynamic coupling in JavaScript using object type inference
by
J. Nicolay; C Noguera; C. De Roover; W De Meuter
04/05/2016
1
CSC 868 Presentation by Jens Vanderhaeghe
04/05/2016
2
Overview
What is Abstract Coupling
04/05/2016
3
// pure function
function sum (a, b) {
return a + b;
}
JavaScript
04/05/2016
4
The Problem
04/05/2016
5
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;
Employee.prototype.greet = function() {
if (this.canTalk) {
console.log('Hi, I am ' + this.name + ', the ' + this.title);
}
};
This Paper
04/05/2016
6
Overview
04/05/2016
7
Approach
04/05/2016
8
04/05/2016
9
Overview
Abstract Interpretation
04/05/2016
10
Interpreter Stores Access information
04/05/2016
11
04/05/2016
12
Overview
Object Type inference
04/05/2016
13
Prototype based Inference
04/05/2016
14
function Circle(){
this.prototype = Shape.prototype;
}
// instance data
var c = new Circle();
// literal
var point = {
x: 1,
y:2
}
//non instance based
Math.sqrt(point.x);
Object Based inference
04/05/2016
15
Math.sqrt
// Inference of
{Math}
Optimizing IOF
04/05/2016
16
04/05/2016
17
Overview
Computing Coupling
04/05/2016
18
var point = {
x:1;
y:2;
}
function Circle() {
this.point2 = {
x:2,
y:2
}
// internal coupling
var x = this.point2.x;
// external coupling
var y = point.y;
}
04/05/2016
19
Overview
Enhancing Object Type information
04/05/2016
20
Flow of Types
04/05/2016
21
function Circle(x, y, r) { . . . }
Circle.prototype.circumference = function () {
return 2 * Matha.PI * thisa.r;
}
function area(c) {
return Mathb.PI * ca.r * cb.r;
}
var c1 = {x:10, y:20, r:30};
Interface Types
04/05/2016
22
var a = {
x: 5,
y: 3,
z: 10
}
var b = {
z: 5,
x: 3,
y: 10
}
Writing Properties
04/05/2016
23
var point = {
x: 5,
y: 6
}
// update existing property
point.x = 6;
// create new property
point.z = 15
Optimizing how we handle Arrays
04/05/2016
24
var arr = [1,2,3]
// property access
arr[1]
var obj {
'1': 'one'
'two: 'two'
}
// Array access
obj['1']
// Property access
obj['two']
04/05/2016
25
Overview
Technical Implementation
04/05/2016
26
04/05/2016
27
Overview
Applications of this research
04/05/2016
28
Detecting Feature Envy
04/05/2016
29
Metrics
04/05/2016
30
04/05/2016
31
Overview
Summary
04/05/2016
32
Conclusion
04/05/2016
33
04/05/2016
34