LIBRARIES AS LANGUAGES: TYPECHECKING JQUERY PROGRAMS Benjamin Lerner Liam Elberty Jincheng Li Shriram Krishnamurthi.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

The DOM tree CS The DOM tree CS380 2 Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in.
CT-376 jQuery Most popular javascript library today Latest version:
JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
Modifying existing content Adding/Removing content on a page using jQuery.
JQuery & SharePoint San Antonio Users Group – September Meeting September 22, 2009 Microsoft SharePoint Server.
Events Part III The event object. Learning Objectives By the end of this lecture, you should be able to: – Learn to use the hover() function – Work with.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
Detecting Conflicts Among Declarative UI Extensions Benjamin Lerner Brown University Dan Grossman UW Computer Science & Engineering.
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.
Lecture 10. Back to the table example We can now return to considering in detail the first XSLT style-sheet we saw –The one which, when applied to the.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
JQuery. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing and manipulation event handling.
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Key question  What are the three standardized core languages used to implement web pages? Write the full name not the abbreviation and describe the “layer”
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
Jquery Nasrullah. Jquery jQuery is a JavaScript Library. jQuery greatly simplifies JavaScript programming. jQuery is easy to learn.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Navigating the DOM with ExtJS By Aaron Conran. Document Object Model The Document Object Model or DOM is a standard to represent HTML, XHTML and other.
JQuery Youn-Hee Han
. Taught by: Muhammad Ali Baloch midahot. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Computer Science and Software Engineering© 2014 Project Lead The Way, Inc. HTML5 Evolving Standards JavaScript.
HTML.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
Introduction to jQuery. 2 Objectives When you complete this chapter, you will be able to: Select elements using jQuery syntax Use built-in jQuery functions.
LING 408/508: Programming for Linguists Lecture 11 October 5 th.
Web Technologies Lecture 8 JQuery. “A fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax.
Style Sheets. Coding Style Sheets  Style sheets use RULES to create the style  A selector (a tag or user-defined style name)  and then declarations.
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
JQUERY AND AJAX
Wes Preston DEV 202. Audience: Info Workers, Dev A deeper dive into use-cases where client-side rendering (CSR) and SharePoint’s JS Link property can.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
.. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between HTML and JavaScript. The jQuery library.
INTRODUCTION ABOUT DIV Most websites have put their content in multiple columns. Multiple columns are created by using or elements. The div element is.
JQuery.
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
XML Related Technologies
Concepts of HTML, CSS and Javascript
CGS 3066: Web Programming and Design Spring 2017
Revision.
Document Object Model (DOM): Objects and Collections
Web Programming Language
..
Input CS 422: UI Design and Programming
JavaScript and the DOM MIS 2402 Jeremy Shafer Department of MIS
An Introduction to Animation
MIS JavaScript and API Workshop (Part 2)
Document Object Model.
Chapter 6 Introducing Cascading Style Sheets
HTML 5 SEMANTIC ELEMENTS.
Lecture 23, Computer Networks (198:552)
JavaScript CS 4640 Programming Languages for Web Applications
Chengyu Sun California State University, Los Angeles
Getting started with jQuery
Murach's JavaScript and jQuery (3rd Ed.)
Murach's JavaScript and jQuery (3rd Ed.)
Web Programming and Design
JavaScript: BOM and DOM CS Programming Languages for Web Applications
© 2017, Mike Murach & Associates, Inc.
Presentation transcript:

LIBRARIES AS LANGUAGES: TYPECHECKING JQUERY PROGRAMS Benjamin Lerner Liam Elberty Jincheng Li Shriram Krishnamurthi

Programming Web Pages in JavaScript Myth 1: HTML documents are trees of pointers Reality: much more tightly linked body div p p span

Programming Web Pages in JavaScript Myth 2: just walk pointers from node to node function findAllP() { results = []; q = [body]; while ((cur = q.pop()) !== null) { if (cur.elementName == “p”) results.push(cur); q.push(cur.childNodes); } } body div p p span Assembly language for trees

Programming Web Pages with Query Languages We have higher-level languages to express these ideas! – Any intuitions you have from XQuery, CSS, XDuce/CDuce are appropriate here…

Programming with jQuery jQuery is a library for tree programming E.g. “Find all nodes and turn them green” $(“p”).css(“color”, “green”) Domain-specific language

What does this jQuery code do? $(“.tweet span”).next().html() Depends on the shape of the page!

$(“.tweet span”).next().html() … … Ben Now Hi

$(“.tweet span”).next().html() … … Ben Now Hi

$(“.tweet span”).next().html() … … Ben Now Hi

$(“.tweet span”).next().html() … … Ben Now Hi

$(“.tweet span”).next().html() … … Ben Now Hi “ Now”

$(“.tweet span”).next().text() … … Ben Now Hi “ Now Hi”

Query: Selects some nodes in the page Navigate: Move to new nodes, relative to existing ones Manipulate: Retrieve or modify data from node(s) What’s going on here? $(“.tweet span”).next().html()

DOM nodes DOM nodes.map().html().next()... How jQuery works New DOM nodes New DOM nodes.map().html().next()... prev New DOM nodes New DOM nodes.map().html().next()... prev “... ” $(“.tweet span”)

So what can go wrong? “Standard” type errors: –.map() a function over wrong types of elements Ambiguity: – Getting the.html() of one node, but have many Overshooting: – Asking for the.children() of a leaf node… Wrong selection: – $(“div.mispleling”)

How to catch these errors? Working backwards: x.html() is ok if x has exactly 1 node x.next() is ok if x has at least 1 node The $() function returns some number of nodes, based on its argument… Need more than just simple types: Need to track sizes

Catching “standard type errors” jq = A recursive, parametric type of... html : [jq ]  Str, text : [jq ]  Str,... next : [jq ]  ????

Catching ambiguity errors jq = A recursive, parametric type of... html : [jq ]  Str, text : [jq ]  Str,... next : [jq ]  ????

Catching ambiguity errors jq = A recursive, parametric type of... html : [jq >]  Str, text : [jq >]  Str,... next : [jq >]  ???? Multiplicities: Lightweight sizes for containers

Multiplicities New kind M Only allowed as arguments to type constructors No values have a type of kind M Simple, finite set of constructors: 0, 1, 01, 1+, 0+ Intuition: interval arithmetic Multiplication: 01 > = 0+ Addition:

Catching ambiguity errors jq = A recursive, parametric type of... html : [jq >]  Str, text : ([jq >]  Str) & ([jq[1+ >] Str  jq >),... next : [jq >]  ???? Intersection types + multiplicities = precise getter/setter types

Catching overshoot errors jq = A recursive, parametric type of... html : [jq >]  Str, text : ([jq >]  Str) & ([jq[1+ >] Str  jq >),... next : [jq >]  jq >> Type-level functions to figure out structure

How to get structure information? “Well, on this page, a Tweet is …” (Tweet : Div classes = {tweet} optional = {starred} (Author : Span classes = {span}) (Time : Span classes = {time}) (Content : Span classes = {content})) Compute type functions from this local structure

One last piece: matching selectors jq = A recursive, parametric type of... html : [jq >]  Str, text : ([jq >]  Str) & ([jq[1+ >] Str  jq >),... next : [jq >]  jq >> $ : forall s

Matching selectors against local structure (Tweet : Div classes = {tweet} optional = {starred} (Author : Span classes = {span}) (Time : Span classes = {time}) (Content : Span classes = {content})) “*.tweet > *.time”1+ “*.tweet > *.content + *”0

Full recipe: “Standard type errors”  standard types Ambiguity errors  multiplicities Overshooting errors  local structure Wrong selection  local structure

Evaluation Examined 12 examples from Learning JQuery and its accompanying blog – Manually derived local structure from text descriptions Type-checked example queries  All pass typechecking, with no extra annotations Manually introduced bugs  All now fail

Evaluation: Typical example $(“.tweet”).children().next().next().next().css(“color”) $(“.tweet”).children().next().next().css(“color”) $(“.tweet”).children().next().css(“color”)  ‘css’ expects 1, got 0  ‘css’ expects 1, got 1+

Subtleties DOM Mutation $(“.tweet”).findClass(“starred”).removeClass(“starred”) $(“.tweet”).findClass(“starred”)  how many?? Overly broad queries What should $(“div > p”) match? … See paper for more details

Try it out! Implemented in TeJaS: Customizable, extensible type systems for JS