MODELING AND REASONING

Similar documents
Document Object Model (DOM) Level 3 Events

Document Object Model (DOM) Level 3 Events

Document Object Model (DOM) Level 3 Events

Document Object Model (DOM) Level 2 Events

CSC Web Programming. JavaScript Browser Objects

Lecture 8. ReactJS 1 / 24

An updated events syntax for XML-based markup languages

Javascript Events. Web Authoring and Design. Benjamin Kenwright

Principles of Programming Languages

Topic 16: Validation. CITS3403 Agile Web Development. Express, Angular and Node, Chapter 11

CISC 1600 Lecture 2.4 Introduction to JavaScript

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

Catching Events. Bok, Jong Soon

Interactor Tree. Edith Law & Mike Terry

Telerik Test Studio. Web/Desktop Testing. Software Quality Assurance Telerik Software Academy

Events: another simple example

ADsafety. Type-based Verification of JavaScript Sandboxing. Joe Gibbs Politz Spiridon Aristides Eliopoulos Arjun Guha Shriram Krishnamurthi

Operational Semantics 1 / 13

DOM Primer Part 2. Contents

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

CSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM

C07: Testing and JUnit

Apps Framework API. Version Samsung Smart Electronics Copyright All Rights Reserved

CS558 Programming Languages

The Future of the Web: HTML 5, WebSockets, Comet and Server Sent Events

Logic and Computation

Tizen Web Runtime. Ming Jin, Samsung Electronics. (May 8, 2012)

moxie-js-client documentation

SAMPLE CHAPTER. Edd Yerburgh MANNING

CITS3403 Agile Web Development Semester 1, 2018

Putting Static Analysis to Work for Verification

PROGRAMMING LANGUAGE SEMANTICS AS NATURAL SCIENCE

Events. Mendel Rosenblum. CS142 Lecture Notes - Events

JavaScript: Events, DOM and Attaching Handlers

Mugshot: Recording and Replaying JavaScript Applica9ons. James Mickens

Turning proof assistants into programming assistants

6.001 Notes: Section 15.1

Client vs Server Scripting

Automated Generation of Event-Oriented Exploits in Android Hybrid Apps

No Source Code. EEC 521: Software Engineering. Specification-Based Testing. Advantages

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

Software Testing. Software Testing

Software Integration Guide

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

Lesson: Web Programming(6) Omid Jafarinezhad Sharif University of Technology

Getting Started with Web Services

Black Box Testing. EEC 521: Software Engineering. Specification-Based Testing. No Source Code. Software Testing

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Interactive XML Visualization - using XSLT 2.0 on the Browser. Phil Fearon - Saxonica

Examining the Code. [Reading assignment: Chapter 6, pp ]

Programming Languages and Techniques (CIS120)

Programming in HTML5 with JavaScript and CSS3

How to write good, composable and pure components in

Programming Languages

APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet. Dan McGhan Senior Technical Consultant

Delivering training since 1996

TESTBEDS Paris

Topics in Software Testing

NODE.JS MOCK TEST NODE.JS MOCK TEST I

Verification and Validation. Assuring that a software system meets a user s needs. Verification vs Validation. The V & V Process

Süddeutsche Zeitung, Digital Edition

Lambda Calculus. Concepts in Programming Languages Recitation 6:

Building an OpenLayers 3 map viewer with React

A Browser Developer's Research Wish List. Robert O'Callahan Mozilla Corporation

Sample CS 142 Midterm Examination

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

JavaScript and Events

Unobtrusive JavaScript (Sample Chapter)

Featherweight Firefox

ACT-R RPC Interface Documentation. Working Draft Dan Bothell

How to Convert a Microsoft Word Document to PDF Format

JavaScript Errors in the Wild: An Empirical Study

CS348: Computer Networks (SMTP, POP3, IMAP4); FTP

Reading assignment: Reviews and Inspections

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Node.js. Node.js Overview. CS144: Web Applications

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

JavaScript: More Syntax

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

ZOS15P1 - Rational Business Developper : Comment développer rapidement une application zos/db2 sans connaissance Cobol avec EGL et RBD

widgetjs Documentation

High Performance Single Page Application with Vue.js

Advances in Programming Languages

Page 1. Reading assignment: Reviews and Inspections. Foundations for SE Analysis. Ideally want general models. Formal models

Head First HTML 5 Programming: Chapter 3: Events, Handlers, and all that Jazz.

MANAGING ASYNCHRONY. An Application Perspective

6.001 Notes: Section 8.1

Vue.js Framework. Internet Engineering. Spring Pooya Parsa Professor: Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Timing Analysis of Parallel Software Using Abstract Execution

Shared Variables and Interference

CIS 500 Software Foundations Fall October 2

Reliable programming

event driven programming user input Week 2 : c. JavaFX user input Programming of Interactive Systems

An Extensible Programming Language for Verified Systems Software. Adam Chlipala MIT CSAIL WG 2.16 meeting, 2012

LTC Exporter Program

Provably Correct Software

Build Reactive Websites with RxJS

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

Behavioral Equivalence

Transcription:

MODELING AND REASONING ABOUT DOM EVENTS Benjamin Lerner, Matthew Carroll, Dan Kimmel, Hannah Quay-de la Vallee, Shriram Krishnamurthi Brown University WebApps 2012

Those pesky ads Click here and type expo! to win!!

Those pesky ads Click here and type expo! to win!!

Those pesky ads Click here and type expo! to win!!

What s really going on here?

Event dispatch, informally div #page div #conv div #msg1 div #msg2 div #reply function(evt) { } Click here and type expo! to win!! H E L L O div #AD

Event dispatch, informally div #page Handle x,! keypresses div #conv div #msg1 div #msg2 x div #reply Click here and type expo! to win!! div #AD

Event dispatch, informally div #page Handle x,! keypresses div #conv div #msg1 div #msg2 div #reply Click here and type expo! to win!! div #AD Cancel all but x,! e x p o!

To understand the execution of any web page, we have to understand the model for event dispatch.

Event dispatch, informal summary div #page Dispatch path div #conv div #msg1 x div #msg2 Bubbling Event target Event listener div #reply div #AD e x p o! function(evt) { } Cancel all but x,! Events Event cancelation

Event dispatch the subtleties Interactions between mutations and order of operations Multiple listeners per event per element Tree mutation Adding/removing listeners during dispatch Legacy handlers Default actions

Core dispatch algorithm Build dispatch path Pre-dispatch Start Dispatch-collect JS Collect list of listeners Next node? Dispatch Done Run Dispatch-next Finish Dispatch-default

Surely this is all specified? Yes, but Specification is 113 pages long (Mostly definitions of specific event types) Core dispatch algorithm is 16 pages, With side references to other specifications! Specification is not self-consistent

Example: addeventlistener addeventlistener Registers an event listener, depending on the usecapture parameter, on the capture phase of the DOM event flow or its target and bubbling phases. Parameters type : DOMString Specifies the Event.type associated with the event for which the user is registering. listener : EventListener The listener parameter must be an object that implements the EventListener interface or a function. If listener is a function then it must be used as the callback for the event; otherwise, if listener implements EventListener, then its handleevent method must be used as the callback. usecapture : boolean If true, usecapture indicates that the user wishes to add the event listener for the capture and target phases only, i.e., this event listener will not be triggered during the bubbling phase. If false, the event listener must only be triggered during the target and bubbling phases. This parameter must be optional. If not provided, the EventTarget.addEventListener method must behave as if usecapture were specified to be false.

Modeling the event dispatch We built a model in Redex of the event dispatch algorithm 1000 lines of commented code Analyzable Testable Executable Composable

Redex: what and why Redex is a framework designed for language engineers Makes it easy to: Specify operational semantics Simulate running of programs Examine syntax and state of programs as they run Particularly convenient when trying to match web specs: Mostly written in an idiomatic, step-by-step manner

addeventlistener, revisited (define-metafunction DOM [(addlistener LS string_type bool_usecapture loc_listener) (addlistenerhelper (addlistenerhelper LS string_type target bool_usecapture loc_listener) string_type,(if (term bool_usecapture) (term capture) (term bubble)) bool_usecapture loc_listener))))])

Using the model: formal analysis Common knowledge about event dispatch: Modifying the tree shouldn t impact the current dispatch. Every node gets visited twice (capture and bubble) except the target. Event dispatch is deterministic. Event dispatch terminates. All of these are theorems that hold of our model Good for user understanding. Good for analyses that rely upon them.

Example: dispatch path is fixed Build dispatch path Pre-dispatch Start Only state to modify dispatch path QED. Dispatch-collect JS Collect list of handlers Next node? Dispatch Done Run Dispatch-next Finish Dispatch-default

That s nice, so? Model relevance What assurance do we have that the model reflects reality? Annotate the correspondence explicitly Spec text annotations model rules An informed reader could read both together and confirm they match. (Compare the spec for addeventlistener with our model)

Using the model: automatic testing Can automatically construct test cases All small trees, random larger ones All pairs of 1-line listeners; random longer ones Export Simulate Execute Compare

Using the model: debug execution Two real-world Thunderbird extensions: Nostalgy

Using the model: debug execution Two real-world Thunderbird extensions: Thunderbird Conversations

Using the model: debug execution Nostalgy: hot-keys for saving messages Type S, then a folder name save message to folder Conversations: Gmail-like quick-reply box What should happen when you quick-reply with a word containing s? More importantly, when the wrong thing happens, why? And how should we fix it?

Future Uses A full account of dynamic web behavior: Events (this work) JavaScript DOM Network Storage Testing and verification of larger web applications

Recap: Contributions A tractable, formal model of web event dispatch Analyzable Amenable to traditional PL techniques Testable Has found actual bugs in current browsers Executable Can help explain odd app behaviors or debug broken extensions Composable Can be combined with other models for increased precision