8257 interfacing 2 in microprocessor for btech students
Dompletion: DOM-Aware JavaScript Code Completion
1. DOMPLETION
DOM-Aware JavaScript Code Completion
An approach to assist the Web Developers in
writing DOM manipulating JavaScript code
Kartik Bajaj, Karthik Pattabiraman, Ali Mesbah
University of British Columbia
{kbajaj, karthikp, amesbah}@ece.ubc.ca 1
2. Running Example (JavaScript)
1. function add(a,b) {
2. return a + b;
3. }
4.
5. var input1 = 10;
6. var input2 = 20;
7. if(input1 != 0) {
8. var sum = add(input1,input2);
9. alert(sum);
10. } else {
11. var sum = input2;
12. alert(sum);
13. }
2
3. Document Object Model (DOM)
document.getElementsByTagName(“input”);
3
HTML
BODY
DIV
id=“container”
INPUT
class=“val1”
value=“10”
INPUT
class=“val2”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
document.getElementsByClassName(“val1”);
document.getElementsByClassName(“val2”);
document.querySelector(“html body #container input”);
4. DOM JavaScript Interaction
1. function add(a,b) {
2. return a + b;
3. }
4.
5. var input1 = 10;
5’. var input1 = document.getElementsByClassName(“val1”)[0].value;
6. var input2 = 20;
6’. var input2 = document.getElementsByClassName(“val2”)[0].value;
7. if(input1 != 0) {
8. var sum= add(input1,input2);
9. alert(sum);
9’. var html = “<p id=‘true’> + add(input1,input2) + “</p>”;
9’’. document.getElementById(“result”).innerHTML += html;
10. } else {
11. var sum = input2;
12. alert(input2);
12’. var html += “<p id=‘false’>” + sum+ “</p>”;
12’’. document.getElementById(“result”).innerHTML += html;
13. }
4
5. Updated DOM State(s)
Input 21
DOM State 0 DOM State 1
5
true”
30”
HTML
BODY
DIV
id=“container”
INPUT
class=“val1”
value=“10”
INPUT
class=“val2”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
P
id=“false”
html=“20”
20
2
7. Challenges
7
Is this class name correct?
1. function add(a,b) {
Does 2. return the element a + b;
exist in DOM?
3. }
4.
5. var input1 = document.getElementsByClassName(“val1”)[0].value;
6. var input2 = document.getElementsByClassName(“val2”)[0].value;
7. if(input1 != 0) {
8. var sum= add(input1,input2);
9. var html = “<p id=‘true’> + add(input1,input2) + “</p>”;
10. document.getElementById(“result”).innerHTML += html;
11. } else {
12. var sum = input2;
13. var html += “<p id=‘false’>” + sum+ “</p>”;
14. document.getElementById(“result”).innerHTML += html;
15. }
Does it have the property “value”?
What is the updated DOM structure?
8. Straw man Approach
Manually inspect the DOM
Develop, Execute, Repeat
Tedious and time consuming
8
9. Problem Statement
• JavaScript code is challenging to develop and
analyze
– Handling interactions between JS and DOM
[MSR’14][ESEM’13]
• Lack of tool support [ESEM’13]
– Instant feedback required
9
11. Proposed Solution
Analyze each DOM state and assist the
developer while writing JavaScript Code
BUT
Number of DOM states can be infinite!!!
11
12. Intuition
DOM states exhibit patterns
12
HTML
BODY
DIV
id=“container”
INPUT
class=“val1”
value=“10”
INPUT
class=“val2”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
HTML
BODY
DIV
id=“container”
INPUT
class=“val1”
value=“10”
INPUT
class=“val2”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
P
id=“true”
html=“30”
S 0 S 1
13. DOM Element Locators
13
BODY
DIV
id=“container”
INPUT
class=“val”
value=“10”
INPUT
class=“val”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
html body div#container input.val1
html body div#container input.val2
html body div#container button#add
html body div#container span.result
html body div#container input.val1
html body div#container input.val2
html body div#container button#add
html body div#container span.result p#true
html body div#container input.val1
html body div#container input.val2
html body div#container button#add
html body div#container span.result p#false
HTML
p
id=“false”
true”
html=“30”
S 012
14. Compression Techniques
14
html body div#container input.val1
html body div#container input.val1.val2
html body div#container input.val2
html body div#container input.val{d}
html body div#container button#add
html body div#container span.result
html body div#container input.val1
html body div#container input.val2
html body div#container button #add
html body div#container span.result p#true
html body div#container span.result
p#true#flase
html body div#container input.val1
html body div#container input.val2
html body div#container button #add
Duplicates Removed
Similar IDs combined
Similar classes combined
15. DOM Analysis
• Manual
• Automatic
• Crawl available DOM states.
• Convert each DOM state to a list of DOM
Element Locators.
• Detect patterns in DOM Element Locators.
15
16. JavaScript Code Analysis
16
1. function add(a,b) {
2. return a + b;
3. }
4.
5. var input1 = document.getElementsByClassName(“val1”)[0].value;
6. var input2 = document.getElementsByClassName(“val2”)[0].value;
7. if(input1 != 0) {
8. var sum= add(input1,input2);
9. var html = “<p id=‘true’> + add(input1,input2) + “</p>”;
10. document.getElementById(“result”).innerHTML += html;
11. } else {
12. var sum = input2;
13. var html += “<p id=‘false’>” + sum+ “</p>”;
14. document.getElementById(“result”).innerHTML += html;
15. }
.....
if(condition) {
then-statements;
} else {
else-statements;
.....
HTML
BODY
.....
condition;
log true;
then-statements;
.....
.....
condition;
then-statements;
.....
.....
condition;
log false
else-statements;
.....
.....
condition;
else-statements;
.....
DIV
id=“container”
INPUT
class=“val1”
value=“10”
INPUT
class=“val2”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
S0
class=“result”
html=“Result:”
17. HTML
BODY
DIV
id=“container”
INPUT
class=“val”
value=“10”
INPUT
class=“val”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
p
id=“false”
html=“30”
HTML
BODY
DIV
id=“container”
INPUT
class=“val”
value=“10”
INPUT
class=“val”
value=“20”
BUTTON
id=“add”
value=“Add”
SPAN
class=“result”
html=“Result:”
p
id=“true”
html=“30”
Example
17
1. function add(a,b) {
2. return a + b;
3. }
4.
5. var input1 = document.getElementsByClassName(“val1”)[0].value;
6. var input2 = document.getElementsByClassName(“val2”)[0].value;
7. input1 != 0;
8. dompleteLog(“main”,true);
9. var sum= add(input1,input2);
10. var html = “<p id=‘true’> + add(input1,input2) + “</p>”;
11. document.getElementById(“result”).innerHTML += html;
1. function add(a,b) {
2. return a + b;
3. }
4.
5. var input1 = document.getElementsByClassName(“val1”)[0].value;
6. var input2 = document.getElementsByClassName(“val2”)[0].value;
7. input1 != 0;
8. dompleteLog(“main”,false);
9. var sum = input2;
10. var html += “<p id=‘false’>” + sum+ “</p>”;
11. document.getElementById(“result”).innerHTML += html;
S1
S2
18. Code Analysis
• Generate possible code paths
• Execute JavaScript code
• Intercept calls to DOM API
• Analyze Logs
18
23. Evaluation
RQ1: Do DOM element locators converge?
RQ2: How accurate are the code completion suggestions?
– Precision
– Recall
RQ3: What is the performance overhead incurred?
23
31. RQ3: Performance
DOM Analysis Phase
• Crawled each web application until DOM element
locators merge.
• Recorded time elapsed by the end of each state
Code Analysis Phase
• Recorded time taken to list the suggestions
31
32. RQ3: Results
• DOM Analysis
– 173 seconds (3 minutes approx.)
• Code Analysis
– Min time: 1 second
– Max time: 6 seconds
– Avg. time: 2.8 seconds
32
Incurred only once
33. User Study
• 9 Participants
Group A : Using DOMpletion
Group B : Without DOMpletion
• 4 Tasks to analyze the DOM JavaScript
interactions
103
268
Time (Seconds)
Group A Group B
97.50% 90.83%
47.50%
76.25%
Recall Precision
Group A Group B 33
34. Contributions
1. Discussed challenges behind DOM based code completion.
2. Fully automated code completion technique using static and
dynamic analysis of JavaScript code and DOM.
3. Implementation in an open source tool called DOMpletion.
4. Empirical evaluation to assess DOMpletion.
https://github.com/saltlab/dompletion
34
Up to 83 % Recall and 90% Precision
2.8 seconds average time
Notas del editor
describe the meaning
approach to assist the web developers in writing JavaScript code that interacts with DOM
before we go further lets have a quick look at the running example which we follow throughout the presentation
The code looks simple.. however when writing code for web applications
the code needs to be modified to get input and redirect outputs to the web application..
For this javascript code, lets use this really simple calculator application..
Before we go futher lets have a quick look how this web application is represneted in the web browser and how does javascript code written by the programmer interacts with it..
each web application is represented in the form of Document Object Model tree i.e DOM tree
each node in the DOM tree corresponds to certain elements in the web application.
For example, in this case the two highlighted leaf nodes represent the two input elements.
In order for the web developer to interacts with these elements
The takeway from this slide is there are more than one ways for a developer to select DOM elements and developers need to precisely analyze the DOM before selecting the DOM element.
dom is highly dynamic and interleaves and evolves with javascript code
----- Meeting Notes (2014-09-10 13:19) -----
red part separate
code completions for interactions between JS and DOM
Loosely typed JS
Highly dynamic DOM
These approaches are static and mainly used for finding errors in the code
not for code-completion
I order to compare the dom states, we need to get rid of the irrelevant information and focus on what exactly matters to the developers..
long time to generate
why do we need to compress??
need to provide quick answer to the developers
simulate unseen dom states using the detected patterns
DOM Analysis Phase 1
In this phase, we crawl the web application. This crawling can be either automated based on the randomized crawler or the developer can crawl the web app manually, if the developer wants to focus on limited number of DOM states.
Next, for DOM state we create a list of DOM element locators. By DOM element locators we refer to the combination of tag names, class names and ids attached to each element along with the hierarchical information.
Next, we detect patterns among these DOM element locators. the basic intuition behind our work is that these DOM element locators tend to converge over the increasing number of DOM states and exhibit patterns that can be recognized. During the evaluation phase we validate this intuition.
The output of this phase looks like this
----- Meeting Notes (2014-09-08 16:54) -----
general algo read the paper
----- Meeting Notes (2014-09-10 13:19) -----
show DOM in the corner
To provide a brief overview of our approach, we require two inputs from the developer.
The 1st one being the URL of the web application for which the developer is writing the JavaScript Code. If the web application is not running the developer can also provide the HTML code as an input to the system.
The 2nd one is the JavaScript that the developer is writing.
The 1st phase of our approach begins in the background and does not require any specific instruction from the developer. It starts with the 1st DOM state, keep exploring next available DOM states and collecting information.
The 2nd phase starts when the developer hits the code completion key. The JavaScript code written till then is taken as an input and dynamically analyzed.
The outputs of 1st and 2nd phase are then compared to generate suggestions for the user.
----- Meeting Notes (2014-09-08 16:54) -----
comes later phase for summary
----- Meeting Notes (2014-09-10 13:19) -----
dnt animate
We have implemented DOMpletion as plugin for the Brackets IDE using its Live Development feature to analyze the DOM.
The Brackets IDE is built as a Desktop application using nodejs.
We use Esprima JavaScript parser built in JavaScript to parse the JavaScript code given as input.
Therefore, keeping our implementation of DOM-Aware code completion tool in JavaScript itself.
Evaluation
We cover three main points:
Convergence of DOM element locators, i.e the intuition we had for the DOM analysis phase.
Accuracy in terms of precision and recall for the proposed technique.
Performance overhead caused by DOMpletion
----- Meeting Notes (2014-09-10 13:19) -----
this applies to other web sites too
css selector tpo
----- Meeting Notes (2014-09-10 13:19) -----
show code demo to complete
hierarchical information definition
how far the suggestion is and make it a positive statement
say about no hierarchy too
related work graph
----- Meeting Notes (2014-09-10 13:19) -----
summary of results
show just email address