An Empirical Study on the Rewritability of the with Statement in JavaScript Changhee Park (Joint work with Hongki Lee and Sukyoung Ryu) KAIST October.

Slides:



Advertisements
Similar presentations
17 HTML, Scripting, and Interactivity Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and.
Advertisements

EIONET Training Zope Page Templates Miruna Bădescu Finsiel Romania Copenhagen, 28 October 2003.
CPSC 388 – Compiler Design and Construction
GATEKEEPER MOSTLY STATIC ENFORCEMENT OF SECURITY AND RELIABILITY PROPERTIES FOR JAVASCRIPT CODE Salvatore Guarnieri & Benjamin Livshits Presented by Michael.
The Web Warrior Guide to Web Design Technologies
1 / 28 Modeling the HTML DOM and Browser API in Static Analysis of JavaScript Web Applications ESEC/FSE 2011 Anders Møller, Magnus Madsen and Simon Holm.
1 Owais Mohammad Haq Department of Computer Science Eastern Michigan University April, 2005 Java Script.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Tutorial 10 Programming with JavaScript
HTML Recall that HTML is static in that it describes how a page is to be displayed, but it doesn’t provide for interaction or animation. A page created.
JavaScript, Third Edition
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
CST JavaScript Validating Form Data with JavaScript.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
DHTML: Working with Objects Creating a Dynamic Web Page.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
Introduction to Client Side Scripting CS Client Side Scripting Client side means the Browser is interpreting the script Script is downloaded with.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Accessing XML Documents Using DOM ©NIITeXtensible Markup Language/Lesson 8/Slide 1 of 23 Objectives In this lesson, you will learn to: * Use XML DOM objects.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Introduction to.
DHTML.
Javascript and Dynamic Web Pages: Client Side Processing
Programming Web Pages with JavaScript
JavaScript: Good Practices
© 2015, Mike Murach & Associates, Inc.
Section 17.1 Section 17.2 Add an audio file using HTML
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Document Object Model (DOM): Objects and Collections
Introduction to JavaScript
JavaScript Introduction
JavaScript an introduction.
Web Systems Development (CSC-215)
Web Design and Development
Introduction to JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

An Empirical Study on the Rewritability of the with Statement in JavaScript Changhee Park (Joint work with Hongki Lee and Sukyoung Ryu) KAIST October 23, 2011

Famous Word about the with Statement

Overview Introduction of the with statement Real-world usage patterns of the with statement Rewritability of the with statement Future work Conclusion

Introduction Syntax in ECMAScript The body of the with statement

Introduction Semantics 1. Evaluate exp to a JavaScript object( with object) 2. Add the object to the front of the scope chain All properties in the with object become local variables in the body of the with statement 3. Evaluate stmt 4. Remove the with object from the scope chain

Good Parts document body div An HTML document A DOM(Document Object Model) tree

Good Parts

Bad Parts Introducing a new scope at run time – Performance overhead – Infeasible static analysis

Bad Parts Infeasible static analysis obj1, obj2, fun1 Global obj, localvar1 fun1

Bad Parts Infeasible static analysis obj1, obj2, fun1 Global obj, localvar1 fun1 one with : obj1

Bad Parts Infeasible static analysis obj1, obj2, fun1 Global obj, localvar1 fun1 two with : obj2

Empirical Study with statements used in real-world – Amount – Usage patterns

Methodology Real-world JavaScript code – 100(98) worldwide most popular web sites by alexa.com Tool – TracingSafari, Purdue University Customized version of WebKit – Static analyzer using the Rhino parser

Methodology Two data sets - LOADING set JavaScript code collected for 30s at loading time - INTERACTION set JavaScript code collected for 2 minutes with user interactions(mouse click events)

Methodology Three kinds of with statement – Static with statements Static with keyword detected by the Rhino Parser (static) – Executed with statements with statements evaluated by the interpreter (executed)

Methodology Three kinds of with statement – Dynamic with statements Dynamically instrumented and executed with statements (dynamic) By filtering out static with statements from executed with statements

Amount of with Statements Type of with Web sites with countsUnique with s Static1554 Executed83612 Dynamic2135 LOADING set INTERACTION set Type of with Web sites with countsUnique with s Static382, Executed271, Dynamic Duplicates 0% 66.6% 61.5% Duplicates 74.4% 82.5% 81.8%

Usage Patterns Seven usage patterns 1. DOMAccess pattern 2. This pattern 3. Global pattern 4. Empty pattern 5. Template pattern 6. Generator pattern 7. Others pattern

Usage Patterns 1. DOMAccess pattern with object : DOM element Example from paypal.com Access or change the values of DOM element attributes

Usage Patterns 2. This pattern with object : this

Usage Patterns 2. This pattern Use the same naming convention between private and public properties

Usage Patterns 3. Global pattern with object : window Example from ebay.com Run the code by eval under the global scope

Usage Patterns 4. Empty pattern with object : any object Has the empty body

Usage Patterns 5. Template pattern with object : template data Example from 163.com Process HTML templates

Usage Patterns 6. Generator pattern with object : any object Contains dynamic code generating functions such as eval, Function, setTimeout, and setInterval

Usage Patterns 7. Others pattern with object : any object Avoid repeatedly accessing the with object

Usage Patterns LOADING set

Usage Patterns INTERACTION set

Template Pattern in Dynamic with Example from 163.com For an arbitrary tag? Only process tag Generate new process code with an input tag

Rewritability of with Statements Many static approaches disallow the with statement Safe subsets of JavaScript GoogleFacebookYAHOO! CajitaFBJSADsafe What if it is possible to rewrite the with statement to other statements?

Rewriting Strategy Main idea obj has the id property? Yes No

Rewriting Strategy Main idea

Rewriting Strategy Rewriting the assignment expression ReferenceError exception!!

Rewriting Strategy Rewriting the assignment expression

Rewriting Strategy Rewriting the variable declaration v

Rewriting Strategy Rewriting the function expression v

Rewritability Check Rewritability of with statements in each pattern PatternRewritabilityRewriting DOMAccess YesBy the rewriting strategy This YesBy the rewriting strategy Global Yes Empty YesBy the rewriting strategy Template YesBy the rewriting strategy Generator No Others YesBy the rewriting strategy

Rewritability Check Generator pattern Not possible to rewrite in general!!

Rewritability Check Global pattern : example from ebay.com

Rewritability Check According to the ECMAScript 5th edition, rewriting is possible by aliasing

Rewritability Check Summary – We can rewrite all static with statements in all patterns except for Generator pattern – 100% of static with statements in the LOADING set and 93.8% in the INTERACTION set are rewritable

Future Work Extension to the top 1,000 sites Formalization of the rewriting process Implementation of the rewriting process

Conclusion Usage of with statements in real world – 38% of the top 98 sites have static occurrences of with statements with simple user interactions Rewritability of with statements – We can rewrite all static with statements to other statements if the with statements do not have dynamic code generating functions