SlideShare a Scribd company logo
Liang Gong1, Michael Pradel2, Manu Sridharan3 and Koushik Sen1
1 UC Berkeley 2 TU Darmstadt 3 Samsung Research America
DLint: Dynamically Checking
Bad Coding Practices in JavaScript
Why JavaScript?
…2
• The RedMonk Programming Language Ranking (1st)
– Based on GitHub and StackOverflow
• Assembly language for the web
• Web applications, DSL, Desktop apps, Mobile apps
3
• Designed and Implemented in 10 days
• Not all decisions were well-thought
• Problematic language features
– Error prone
– Poor performance
– Prone to security vulnerabilities
• Problematic features are still around
– Backward compatibility
Problematic JavaScript
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
4
Problematic JavaScript
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
• Good coding practices
• Informal rules
• Improve code quality
• Better quality means:
• Fewer correctness issues
• Better performance
• Better usability
• Better maintainability
• Fewer security loopholes
• Fewer surprises
• …
5
What are coding practices?
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
6
var sum = 0, value;
var array = [11, 22, 33];
for (value in array) {
sum += value;
}
> sum ?
Rule: avoid using for..in over arrays
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
7
var sum = 0, value;
var array = [11, 22, 33];
for (value in array) {
sum += value;
}
> sum ?
11 + 22 + 33 => 66
array index
(not array value)
0 + 1 + 2 => 3 array index : string
0+"0"+"1"+"2" => "0012"
Rule: avoid using for..in over arrays
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
• Cross-browser issues
• Result depends on the Array prototype object
8
var sum = 0, value;
var array = [11, 22, 33];
for (value in array) {
sum += value;
}
> sum ?
11 + 22 + 33 => 66
array index
(not array value)
0 + 1 + 2 => 3 array index : string
0+"0"+"1"+"2" => "0012"
> "0012indexOftoString..."
Rule: avoid using for..in over arrays
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
9
var sum = 0, value;
var array = [11, 22, 33];
for (value in array) {
sum += value;
}
> sum ?
for (i=0; i < array.length; i++) {
sum += array[i];
}
function addup(element, index, array) {
sum += element;
}
array.forEach(addup);
Rule: avoid using for..in over arrays
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
10
var sum = 0, value;
var array = [11, 22, 33];
for (value in array) {
sum += value;
}
> sum ?
for (i=0; i < array.length; i++) {
sum += array[i];
}
function addup(element, index, array) {
sum += element;
}
array.forEach(addup);
Rule: avoid using for..in over arrays
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
Coding Practices and Lint Tools
• Existing Lint-like checkers
– Inspect source code
– Rule-based checking
– Detect common mistakes
• Limitations:
– Approximates behavior
– Unknown aliases
– Lint tools favor precision over soundness
• Difficulty: Precise static program analysis
11
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
12
• Dynamic Linter checking code quality rules for JS
• Open-source, robust, and extensible framework
• Formalized and implemented 28 rules
– Counterparts of static rules
– Additional rules
• Empirical study
– Compare static and dynamic checking
DLint
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
a.f = b.g PutField(Read("a", a), "f", GetField(Read("b", b), "g"))
if (a.f()) ... if (Branch(Method(Read("a", a), "f")()) ...
x = y + 1 x = Write("x", Binary(‘+’,Read("y", y), Literal(1))
analysis.Literal(c) analysis.Branch(c)
analysis.Read(n, x) analysis.Write(n, x)
analysis.PutField(b, f, v) analysis.Binary(op, x, y)
analysis.Function(f, isConstructor) analysis.GetField(b,f)
analysis.Method(b, f, isConstructor) analysis.Unary(op, x)
...
13
Jalangi: A Dynamic Analysis Framework for JavaScript
[Sen et al. ESEC/FSE'2013]
• Single-event: Stateless checking
• Multi-event: Stateful checking
14
Runtime Patterns
• propWrite(base, name, val)
• propRead(base, name, val)
• cond(val)
• unOp(op, val, res)
• binOp(op, left, right, res)
• call(base, f, args, ret, isConstr)
Predicates over runtime events
Example:
propWrite(*, "myObject", val)
| isPrim(val)
Formalization: declarative specification
15
16
Language Misuse
Avoid setting properties of primitives,
which has no effect.
var fact = 42;
fact.isTheAnswer = true;
console.log(fact.isTheAnswer);
> undefined
DLint Checker Predicate:
propWrite(base,*,*) Λ isPrim(base)
17
Avoid producing NaN (Not a Number).
var x = 23 – "five";
> NaN
DLint Checker Predicate:
unOp(*, val, NaN) Λ val ≠ NaN
binOp(*, left, right, NaN) Λ left ≠ NaN
Λ right ≠ NaN
call(*, *, args,NaN, *) Λ NaN ≠ args
Uncommon Values
18
Avoid concatenating undefined to string.
var value;
...
var str = "price: ";
...
var result = str + value;
> "price: undefined"
DLint Checker Predicate:
binOp(+, left, right, res)
Λ (left = undefined ∨ right = undefined)
Λ isString(res)
Uncommon Values
19
Beware that all wrapped primitives
coerce to true.
var b = false;
if (new Boolean(b)) {
console.log("true");
}
> true
DLint Checker Predicate:
cond(val) Λ isWrappedBoolean(val)
Λ val.valueOf() = false
API Misuse
Avoid accessing the undefined property.
var x; // undefined
var y = {};
y[x] = 23; // { undefined: 23 }
propWrite(*, "undefined",*)
propRead(*, "undefined", *)
20
Type Related Checker
21
22
23
• Modify SpiderMonkey to intercept JavaScript files
• Transpile JavaScript code with Jalangi
• DLint monitors runtime states and finds issues
• Reports root cause and code location
24
JS program
Instrumented
JS program
Behavior
Information
Final Report
DLint Checkers
Jalangi
DLint Overview
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
25
Evaluation
Research Questions
• DLint warnings vs. JSHint warnings?
• Additional warnings from DLint?
• Coding convention vs. page popularity?
Experimental Setup
• 200 web sites (top 50 + others)
• Comparison to JSHint
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
26
• Some sites: One approach finds all
• Most sites: Better together
0% 20% 40% 60% 80% 100%
% of warnings on each site
Websites
JSHint Unique Common DLint Unique
% of Warnings: DLint vs. JSHint
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
27
• 53 warnings per page
• 49 are missed by JSHint
0
1
2
3
4
I5 T6 L3 T5 A2 V2 L4 A5 T1 L2 L1 A6 A8 A3 T2 A4 I1 I4 V3 L5 I2 T4 L6 A7 T3
Logarithmicaverage.#
warning/site(base2)
DLint checkers
8
4
2
1
0
Checker shares warning with JSHint
Checker shares no warnings with JSHint
Additional Warnings Reported by DLint
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
28
Correlation between Alexa popularity
and number of DLint warnings: 0.6
0
0.0025
0.005
0.0075
0.01
0.0125
0.015
0.0175
0.02
#DLintWarn./#Cov.Op.
Websites traffic ranking
Quartile 1-3
Mean
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
#JSHintWarning/LOC
Websites traffic ranking
Quartile 1-3
Mean
Coding Convention vs. Page Popularity
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
29
74
359
191
416
1401
62
202
2335
4933
79
205
62
125
167
6
15
26
8
0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Do not use Number, Boolean, String as a constructor.
The Function constructor is a form of eval.
The object literal notation {} is preferable.
The array literal notation [] is preferable.
document.write can be a form of eval.
Do not override built-in variables.
Implied eval (string instead of function as argument).
eval can be harmful.
Missing 'new' prefix when invoking a constructor.
Fount by JSHint Only Common with DLint
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
30
E.g., 181 calls of eval(), Function(), etc. missed by JSHint
31
77
181
74
833
79
187
413
6
8
0% 20% 40% 60% 80% 100%
WrappedPrimitives
Literals
DoubleEvaluation
ArgumentsVariable
ConstructorFunctions
A8L4A1L1T5
Found by Dlint Only Common with JSHint
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
31
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
32
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
33
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
34
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
NaN case study for IKEA
35
<prices>
<normal>
<priceNormal unformatted="9.9">$9.90</priceNormal>
<pricePrevious />
<priceNormalPerUnit />
<pricePreviousPerUnit />
</normal>
</prices>
previousPrice =
getElementValue("pricePrevious" + suffix, normal);
parseFloat(previousPrice).toFixed(2).replace(...)
.replace('.00', ''));
XML: Empty Element
JS: undefined
JS: NaN
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
36
37
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
38
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
39
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
40
var decode64 = "";
if (dataLength > 3 && dataLength % 4 == 0) {
while (index < dataLength) {
decode64 += String.fromCharCode(...);
}
if (sixbits[3] >= 0x40) {
decode64.length -= 1;
}
}
From Google Octane’s Game Boy Emulator benchmark:
Rule: avoid setting field on primitive values
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
41
var decode64 = "";
if (dataLength > 3 && dataLength % 4 == 0) {
while (index < dataLength) {
decode64 += String.fromCharCode(...);
}
if (sixbits[3] >= 0x40) {
decode64.length -= 1;
}
}
From Google Octane’s Game Boy Emulator benchmark:
No effect because decode64 is a primitive string.
Rule: avoid setting field on primitive values
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
42
window.onbeforeunload=
"Twitch.player.getPlayer().pauseVideo();"
window.onunload=
"Twitch.player.getPlayer().pauseVideo();"
Rule: avoid no effect operations
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
43
window.onbeforeunload=
"Twitch.player.getPlayer().pauseVideo();"
window.onunload=
"Twitch.player.getPlayer().pauseVideo();"
window.onbeforeunload = function () {
Twitch.player.getPlayer().pauseVideo();
}
Rule: avoid no effect operations
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
www.google.com/chrome,
included code from Modernizr:
https://github.com/Modernizr/Modernizr/pull/1419
44
Rule: avoid using for..in on arrays
for (i in props) { // props is an array
prop = props[i];
before = mStyle.style[prop];
...
}
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
45
Takeaways
Dynamic lint-like checking for JavaScript
• Static checkers are not sufficient, DLint complements
• DLint is an open-source, robust, and extensible tool
– Works on real-world websites
– Found 19 clear bugs on most popular websites
More information:
• Paper: “DLint: Dynamically Checking Bad Coding Practices in JavaScript”
• Source Code: https://github.com/Berkeley-Correctness-Group/DLint
• Google “DLint Berkeley”
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
46
Takeaways
Thanks!
Dynamic lint-like checking for JavaScript
• Static checkers are not sufficient, DLint complements
• DLint is an open-source, robust, and extensible tool
– Works on real-world websites
– Found 19 clear bugs on most popular websites
More information:
• Paper: “DLint: Dynamically Checking Bad Coding Practices in JavaScript”
• Source Code: https://github.com/Berkeley-Correctness-Group/DLint
• Google “DLint Berkeley”
Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
47
http://www.phdcomics.com/comics.php?f=1553

More Related Content

What's hot

Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Feng Zhang
 
Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...
Lionel Briand
 
A Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution TechniquesA Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution Techniques
Sung Kim
 
Data collection for software defect prediction
Data collection for software defect predictionData collection for software defect prediction
Data collection for software defect prediction
AmmAr mobark
 
Csise15 codehunt
Csise15 codehuntCsise15 codehunt
Csise15 codehuntTao Xie
 
Applications of Machine Learning and Metaheuristic Search to Security Testing
Applications of Machine Learning and Metaheuristic Search to Security TestingApplications of Machine Learning and Metaheuristic Search to Security Testing
Applications of Machine Learning and Metaheuristic Search to Security Testing
Lionel Briand
 
Software Analytics: Towards Software Mining that Matters
Software Analytics: Towards Software Mining that MattersSoftware Analytics: Towards Software Mining that Matters
Software Analytics: Towards Software Mining that Matters
Tao Xie
 
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Lionel Briand
 
Web Service Antipatterns Detection Using Genetic Programming
Web Service Antipatterns Detection Using Genetic ProgrammingWeb Service Antipatterns Detection Using Genetic Programming
Web Service Antipatterns Detection Using Genetic Programming
Ali Ouni
 
Mining Software Repositories
Mining Software RepositoriesMining Software Repositories
Mining Software Repositories
Israel Herraiz
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
Sung Kim
 
A Natural Language Programming Approach for Requirements-based Security Testing
A Natural Language Programming Approach for Requirements-based Security TestingA Natural Language Programming Approach for Requirements-based Security Testing
A Natural Language Programming Approach for Requirements-based Security Testing
Lionel Briand
 
DeepAM: Migrate APIs with Multi-modal Sequence to Sequence Learning
DeepAM: Migrate APIs with Multi-modal Sequence to Sequence LearningDeepAM: Migrate APIs with Multi-modal Sequence to Sequence Learning
DeepAM: Migrate APIs with Multi-modal Sequence to Sequence Learning
Sung Kim
 
A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...
A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...
A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...
Ali Ouni
 
STRICT-SANER2015
STRICT-SANER2015STRICT-SANER2015
STRICT-SANER2015
Masud Rahman
 
Findability through Traceability - A Realistic Application of Candidate Tr...
Findability through Traceability  - A Realistic Application of Candidate Tr...Findability through Traceability  - A Realistic Application of Candidate Tr...
Findability through Traceability - A Realistic Application of Candidate Tr...
Markus Borg
 
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program RepairIt Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
Claire Le Goues
 
Deep API Learning (FSE 2016)
Deep API Learning (FSE 2016)Deep API Learning (FSE 2016)
Deep API Learning (FSE 2016)
Sung Kim
 
Search-driven String Constraint Solving for Vulnerability Detection
Search-driven String Constraint Solving for Vulnerability DetectionSearch-driven String Constraint Solving for Vulnerability Detection
Search-driven String Constraint Solving for Vulnerability Detection
Lionel Briand
 
Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...
Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...
Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...
Sangmin Park
 

What's hot (20)

Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
 
Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...
 
A Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution TechniquesA Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution Techniques
 
Data collection for software defect prediction
Data collection for software defect predictionData collection for software defect prediction
Data collection for software defect prediction
 
Csise15 codehunt
Csise15 codehuntCsise15 codehunt
Csise15 codehunt
 
Applications of Machine Learning and Metaheuristic Search to Security Testing
Applications of Machine Learning and Metaheuristic Search to Security TestingApplications of Machine Learning and Metaheuristic Search to Security Testing
Applications of Machine Learning and Metaheuristic Search to Security Testing
 
Software Analytics: Towards Software Mining that Matters
Software Analytics: Towards Software Mining that MattersSoftware Analytics: Towards Software Mining that Matters
Software Analytics: Towards Software Mining that Matters
 
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
 
Web Service Antipatterns Detection Using Genetic Programming
Web Service Antipatterns Detection Using Genetic ProgrammingWeb Service Antipatterns Detection Using Genetic Programming
Web Service Antipatterns Detection Using Genetic Programming
 
Mining Software Repositories
Mining Software RepositoriesMining Software Repositories
Mining Software Repositories
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
 
A Natural Language Programming Approach for Requirements-based Security Testing
A Natural Language Programming Approach for Requirements-based Security TestingA Natural Language Programming Approach for Requirements-based Security Testing
A Natural Language Programming Approach for Requirements-based Security Testing
 
DeepAM: Migrate APIs with Multi-modal Sequence to Sequence Learning
DeepAM: Migrate APIs with Multi-modal Sequence to Sequence LearningDeepAM: Migrate APIs with Multi-modal Sequence to Sequence Learning
DeepAM: Migrate APIs with Multi-modal Sequence to Sequence Learning
 
A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...
A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...
A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix A...
 
STRICT-SANER2015
STRICT-SANER2015STRICT-SANER2015
STRICT-SANER2015
 
Findability through Traceability - A Realistic Application of Candidate Tr...
Findability through Traceability  - A Realistic Application of Candidate Tr...Findability through Traceability  - A Realistic Application of Candidate Tr...
Findability through Traceability - A Realistic Application of Candidate Tr...
 
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program RepairIt Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
 
Deep API Learning (FSE 2016)
Deep API Learning (FSE 2016)Deep API Learning (FSE 2016)
Deep API Learning (FSE 2016)
 
Search-driven String Constraint Solving for Vulnerability Detection
Search-driven String Constraint Solving for Vulnerability DetectionSearch-driven String Constraint Solving for Vulnerability Detection
Search-driven String Constraint Solving for Vulnerability Detection
 
Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...
Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...
Griffin: Grouping Suspicious Memory-Access Patterns to Improve Understanding...
 

Similar to DLint: dynamically checking bad coding practices in JavaScript (ISSTA'15 Slides)

final_ICSE '22 Presentaion_Sherry.pdf
final_ICSE '22 Presentaion_Sherry.pdffinal_ICSE '22 Presentaion_Sherry.pdf
final_ICSE '22 Presentaion_Sherry.pdf
XueqiYang
 
Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...
John Allspaw
 
Object Oriented Programming OOP Lab Manual.docx
Object Oriented Programming OOP Lab Manual.docxObject Oriented Programming OOP Lab Manual.docx
Object Oriented Programming OOP Lab Manual.docx
RashidFaridChishti
 
Software Testing:
 A Research Travelogue 
(2000–2014)
Software Testing:
 A Research Travelogue 
(2000–2014)Software Testing:
 A Research Travelogue 
(2000–2014)
Software Testing:
 A Research Travelogue 
(2000–2014)
Alex Orso
 
Symbolic Execution And KLEE
Symbolic Execution And KLEESymbolic Execution And KLEE
Symbolic Execution And KLEE
Shauvik Roy Choudhary, Ph.D.
 
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail ScienceSQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
University of Washington
 
Avihu Efrat's Viola and Jones face detection slides
Avihu Efrat's Viola and Jones face detection slidesAvihu Efrat's Viola and Jones face detection slides
Avihu Efrat's Viola and Jones face detection slides
wolf
 
ICSE '22 Presentaion_Sherry.pdf
ICSE '22 Presentaion_Sherry.pdfICSE '22 Presentaion_Sherry.pdf
ICSE '22 Presentaion_Sherry.pdf
XueqiYang
 
tracking.ppt
tracking.ppttracking.ppt
tracking.ppt
BangalirecipeLaboni
 
What do practitioners ask about code clone? A preliminary investigation of St...
What do practitioners ask about code clone? A preliminary investigation of St...What do practitioners ask about code clone? A preliminary investigation of St...
What do practitioners ask about code clone? A preliminary investigation of St...
Au Gai
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...
Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...
Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...
MLconf
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
Andrey Karpov
 
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Annibale Panichella
 
Presentation by Lionel Briand
Presentation by Lionel BriandPresentation by Lionel Briand
Presentation by Lionel Briand
Ptidej Team
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
岳華 杜
 
A Validation of Object-Oriented Design Metrics as Quality Indicators
A Validation of Object-Oriented Design Metrics as Quality IndicatorsA Validation of Object-Oriented Design Metrics as Quality Indicators
A Validation of Object-Oriented Design Metrics as Quality Indicatorsvie_dels
 
Static program analysis tools
Static program analysis toolsStatic program analysis tools
Static program analysis tools
Kamil Jezek
 
Final Presentation (REVISION 2)
Final Presentation (REVISION 2)Final Presentation (REVISION 2)
Final Presentation (REVISION 2)Chad Buckallew
 
Entity-Relationship Queries over Wikipedia
Entity-Relationship Queries over WikipediaEntity-Relationship Queries over Wikipedia

Similar to DLint: dynamically checking bad coding practices in JavaScript (ISSTA'15 Slides) (20)

final_ICSE '22 Presentaion_Sherry.pdf
final_ICSE '22 Presentaion_Sherry.pdffinal_ICSE '22 Presentaion_Sherry.pdf
final_ICSE '22 Presentaion_Sherry.pdf
 
Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...
 
Object Oriented Programming OOP Lab Manual.docx
Object Oriented Programming OOP Lab Manual.docxObject Oriented Programming OOP Lab Manual.docx
Object Oriented Programming OOP Lab Manual.docx
 
Software Testing:
 A Research Travelogue 
(2000–2014)
Software Testing:
 A Research Travelogue 
(2000–2014)Software Testing:
 A Research Travelogue 
(2000–2014)
Software Testing:
 A Research Travelogue 
(2000–2014)
 
Symbolic Execution And KLEE
Symbolic Execution And KLEESymbolic Execution And KLEE
Symbolic Execution And KLEE
 
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail ScienceSQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
 
Avihu Efrat's Viola and Jones face detection slides
Avihu Efrat's Viola and Jones face detection slidesAvihu Efrat's Viola and Jones face detection slides
Avihu Efrat's Viola and Jones face detection slides
 
ICSE '22 Presentaion_Sherry.pdf
ICSE '22 Presentaion_Sherry.pdfICSE '22 Presentaion_Sherry.pdf
ICSE '22 Presentaion_Sherry.pdf
 
tracking.ppt
tracking.ppttracking.ppt
tracking.ppt
 
What do practitioners ask about code clone? A preliminary investigation of St...
What do practitioners ask about code clone? A preliminary investigation of St...What do practitioners ask about code clone? A preliminary investigation of St...
What do practitioners ask about code clone? A preliminary investigation of St...
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...
Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...
Hanjun Dai, PhD Student, School of Computational Science and Engineering, Geo...
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
 
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
 
Presentation by Lionel Briand
Presentation by Lionel BriandPresentation by Lionel Briand
Presentation by Lionel Briand
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
 
A Validation of Object-Oriented Design Metrics as Quality Indicators
A Validation of Object-Oriented Design Metrics as Quality IndicatorsA Validation of Object-Oriented Design Metrics as Quality Indicators
A Validation of Object-Oriented Design Metrics as Quality Indicators
 
Static program analysis tools
Static program analysis toolsStatic program analysis tools
Static program analysis tools
 
Final Presentation (REVISION 2)
Final Presentation (REVISION 2)Final Presentation (REVISION 2)
Final Presentation (REVISION 2)
 
Entity-Relationship Queries over Wikipedia
Entity-Relationship Queries over WikipediaEntity-Relationship Queries over Wikipedia
Entity-Relationship Queries over Wikipedia
 

Recently uploaded

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

DLint: dynamically checking bad coding practices in JavaScript (ISSTA'15 Slides)

  • 1. Liang Gong1, Michael Pradel2, Manu Sridharan3 and Koushik Sen1 1 UC Berkeley 2 TU Darmstadt 3 Samsung Research America DLint: Dynamically Checking Bad Coding Practices in JavaScript
  • 2. Why JavaScript? …2 • The RedMonk Programming Language Ranking (1st) – Based on GitHub and StackOverflow • Assembly language for the web • Web applications, DSL, Desktop apps, Mobile apps
  • 3. 3 • Designed and Implemented in 10 days • Not all decisions were well-thought • Problematic language features – Error prone – Poor performance – Prone to security vulnerabilities • Problematic features are still around – Backward compatibility Problematic JavaScript Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 4. 4 Problematic JavaScript Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 5. • Good coding practices • Informal rules • Improve code quality • Better quality means: • Fewer correctness issues • Better performance • Better usability • Better maintainability • Fewer security loopholes • Fewer surprises • … 5 What are coding practices? Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 6. 6 var sum = 0, value; var array = [11, 22, 33]; for (value in array) { sum += value; } > sum ? Rule: avoid using for..in over arrays Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 7. 7 var sum = 0, value; var array = [11, 22, 33]; for (value in array) { sum += value; } > sum ? 11 + 22 + 33 => 66 array index (not array value) 0 + 1 + 2 => 3 array index : string 0+"0"+"1"+"2" => "0012" Rule: avoid using for..in over arrays Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 8. • Cross-browser issues • Result depends on the Array prototype object 8 var sum = 0, value; var array = [11, 22, 33]; for (value in array) { sum += value; } > sum ? 11 + 22 + 33 => 66 array index (not array value) 0 + 1 + 2 => 3 array index : string 0+"0"+"1"+"2" => "0012" > "0012indexOftoString..." Rule: avoid using for..in over arrays Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 9. 9 var sum = 0, value; var array = [11, 22, 33]; for (value in array) { sum += value; } > sum ? for (i=0; i < array.length; i++) { sum += array[i]; } function addup(element, index, array) { sum += element; } array.forEach(addup); Rule: avoid using for..in over arrays Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 10. 10 var sum = 0, value; var array = [11, 22, 33]; for (value in array) { sum += value; } > sum ? for (i=0; i < array.length; i++) { sum += array[i]; } function addup(element, index, array) { sum += element; } array.forEach(addup); Rule: avoid using for..in over arrays Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 11. Coding Practices and Lint Tools • Existing Lint-like checkers – Inspect source code – Rule-based checking – Detect common mistakes • Limitations: – Approximates behavior – Unknown aliases – Lint tools favor precision over soundness • Difficulty: Precise static program analysis 11 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 12. 12 • Dynamic Linter checking code quality rules for JS • Open-source, robust, and extensible framework • Formalized and implemented 28 rules – Counterparts of static rules – Additional rules • Empirical study – Compare static and dynamic checking DLint Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 13. a.f = b.g PutField(Read("a", a), "f", GetField(Read("b", b), "g")) if (a.f()) ... if (Branch(Method(Read("a", a), "f")()) ... x = y + 1 x = Write("x", Binary(‘+’,Read("y", y), Literal(1)) analysis.Literal(c) analysis.Branch(c) analysis.Read(n, x) analysis.Write(n, x) analysis.PutField(b, f, v) analysis.Binary(op, x, y) analysis.Function(f, isConstructor) analysis.GetField(b,f) analysis.Method(b, f, isConstructor) analysis.Unary(op, x) ... 13 Jalangi: A Dynamic Analysis Framework for JavaScript [Sen et al. ESEC/FSE'2013]
  • 14. • Single-event: Stateless checking • Multi-event: Stateful checking 14 Runtime Patterns
  • 15. • propWrite(base, name, val) • propRead(base, name, val) • cond(val) • unOp(op, val, res) • binOp(op, left, right, res) • call(base, f, args, ret, isConstr) Predicates over runtime events Example: propWrite(*, "myObject", val) | isPrim(val) Formalization: declarative specification 15
  • 16. 16 Language Misuse Avoid setting properties of primitives, which has no effect. var fact = 42; fact.isTheAnswer = true; console.log(fact.isTheAnswer); > undefined DLint Checker Predicate: propWrite(base,*,*) Λ isPrim(base)
  • 17. 17 Avoid producing NaN (Not a Number). var x = 23 – "five"; > NaN DLint Checker Predicate: unOp(*, val, NaN) Λ val ≠ NaN binOp(*, left, right, NaN) Λ left ≠ NaN Λ right ≠ NaN call(*, *, args,NaN, *) Λ NaN ≠ args Uncommon Values
  • 18. 18 Avoid concatenating undefined to string. var value; ... var str = "price: "; ... var result = str + value; > "price: undefined" DLint Checker Predicate: binOp(+, left, right, res) Λ (left = undefined ∨ right = undefined) Λ isString(res) Uncommon Values
  • 19. 19 Beware that all wrapped primitives coerce to true. var b = false; if (new Boolean(b)) { console.log("true"); } > true DLint Checker Predicate: cond(val) Λ isWrappedBoolean(val) Λ val.valueOf() = false API Misuse
  • 20. Avoid accessing the undefined property. var x; // undefined var y = {}; y[x] = 23; // { undefined: 23 } propWrite(*, "undefined",*) propRead(*, "undefined", *) 20 Type Related Checker
  • 21. 21
  • 22. 22
  • 23. 23
  • 24. • Modify SpiderMonkey to intercept JavaScript files • Transpile JavaScript code with Jalangi • DLint monitors runtime states and finds issues • Reports root cause and code location 24 JS program Instrumented JS program Behavior Information Final Report DLint Checkers Jalangi DLint Overview Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 25. 25 Evaluation Research Questions • DLint warnings vs. JSHint warnings? • Additional warnings from DLint? • Coding convention vs. page popularity? Experimental Setup • 200 web sites (top 50 + others) • Comparison to JSHint Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 26. 26 • Some sites: One approach finds all • Most sites: Better together 0% 20% 40% 60% 80% 100% % of warnings on each site Websites JSHint Unique Common DLint Unique % of Warnings: DLint vs. JSHint Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 27. 27 • 53 warnings per page • 49 are missed by JSHint 0 1 2 3 4 I5 T6 L3 T5 A2 V2 L4 A5 T1 L2 L1 A6 A8 A3 T2 A4 I1 I4 V3 L5 I2 T4 L6 A7 T3 Logarithmicaverage.# warning/site(base2) DLint checkers 8 4 2 1 0 Checker shares warning with JSHint Checker shares no warnings with JSHint Additional Warnings Reported by DLint Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 28. 28 Correlation between Alexa popularity and number of DLint warnings: 0.6 0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 #DLintWarn./#Cov.Op. Websites traffic ranking Quartile 1-3 Mean 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 #JSHintWarning/LOC Websites traffic ranking Quartile 1-3 Mean Coding Convention vs. Page Popularity Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 29. 29 74 359 191 416 1401 62 202 2335 4933 79 205 62 125 167 6 15 26 8 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% Do not use Number, Boolean, String as a constructor. The Function constructor is a form of eval. The object literal notation {} is preferable. The array literal notation [] is preferable. document.write can be a form of eval. Do not override built-in variables. Implied eval (string instead of function as argument). eval can be harmful. Missing 'new' prefix when invoking a constructor. Fount by JSHint Only Common with DLint Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 30. 30 E.g., 181 calls of eval(), Function(), etc. missed by JSHint 31 77 181 74 833 79 187 413 6 8 0% 20% 40% 60% 80% 100% WrappedPrimitives Literals DoubleEvaluation ArgumentsVariable ConstructorFunctions A8L4A1L1T5 Found by Dlint Only Common with JSHint Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 31. 31 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 32. 32 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 33. 33 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 34. 34 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 35. NaN case study for IKEA 35 <prices> <normal> <priceNormal unformatted="9.9">$9.90</priceNormal> <pricePrevious /> <priceNormalPerUnit /> <pricePreviousPerUnit /> </normal> </prices> previousPrice = getElementValue("pricePrevious" + suffix, normal); parseFloat(previousPrice).toFixed(2).replace(...) .replace('.00', '')); XML: Empty Element JS: undefined JS: NaN Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 36. Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. 36
  • 37. 37 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 38. 38 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 39. 39 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 40. 40 var decode64 = ""; if (dataLength > 3 && dataLength % 4 == 0) { while (index < dataLength) { decode64 += String.fromCharCode(...); } if (sixbits[3] >= 0x40) { decode64.length -= 1; } } From Google Octane’s Game Boy Emulator benchmark: Rule: avoid setting field on primitive values Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 41. 41 var decode64 = ""; if (dataLength > 3 && dataLength % 4 == 0) { while (index < dataLength) { decode64 += String.fromCharCode(...); } if (sixbits[3] >= 0x40) { decode64.length -= 1; } } From Google Octane’s Game Boy Emulator benchmark: No effect because decode64 is a primitive string. Rule: avoid setting field on primitive values Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 42. 42 window.onbeforeunload= "Twitch.player.getPlayer().pauseVideo();" window.onunload= "Twitch.player.getPlayer().pauseVideo();" Rule: avoid no effect operations Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 43. 43 window.onbeforeunload= "Twitch.player.getPlayer().pauseVideo();" window.onunload= "Twitch.player.getPlayer().pauseVideo();" window.onbeforeunload = function () { Twitch.player.getPlayer().pauseVideo(); } Rule: avoid no effect operations Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 44. www.google.com/chrome, included code from Modernizr: https://github.com/Modernizr/Modernizr/pull/1419 44 Rule: avoid using for..in on arrays for (i in props) { // props is an array prop = props[i]; before = mStyle.style[prop]; ... } Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 45. 45 Takeaways Dynamic lint-like checking for JavaScript • Static checkers are not sufficient, DLint complements • DLint is an open-source, robust, and extensible tool – Works on real-world websites – Found 19 clear bugs on most popular websites More information: • Paper: “DLint: Dynamically Checking Bad Coding Practices in JavaScript” • Source Code: https://github.com/Berkeley-Correctness-Group/DLint • Google “DLint Berkeley” Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.
  • 46. 46 Takeaways Thanks! Dynamic lint-like checking for JavaScript • Static checkers are not sufficient, DLint complements • DLint is an open-source, robust, and extensible tool – Works on real-world websites – Found 19 clear bugs on most popular websites More information: • Paper: “DLint: Dynamically Checking Bad Coding Practices in JavaScript” • Source Code: https://github.com/Berkeley-Correctness-Group/DLint • Google “DLint Berkeley” Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley.