The Future of JavaScript I mean ECMAScript Douglas Crockford - - PowerPoint PPT Presentation

the future of javascript
SMART_READER_LITE
LIVE PREVIEW

The Future of JavaScript I mean ECMAScript Douglas Crockford - - PowerPoint PPT Presentation

The Future of JavaScript I mean ECMAScript Douglas Crockford Yahoo! Welcome to the Future! Such as it is. The Worlds Most Popular Programming Language The Worlds Most Popular Programming Language The Worlds Most Unpopular


slide-1
SLIDE 1

The Future of JavaScript

I mean ECMAScript Douglas Crockford Yahoo!

slide-2
SLIDE 2

Welcome to the Future!

Such as it is.

slide-3
SLIDE 3

The World’s Most Popular Programming Language

slide-4
SLIDE 4

The World’s Most Popular Programming Language The World’s Most Unpopular Programming Language

slide-5
SLIDE 5

ECMAScript is the language that people use without bothering to learn it first.

Programming is complicated

  • business. It should never be

undertaken in ignorance.

slide-6
SLIDE 6

Functions are first class.

Static Scoping. (Mostly.)

slide-7
SLIDE 7

Writing in ECMAScript language without understanding closure is like writing in Java without understanding classes.

slide-8
SLIDE 8

Global

var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; var digit_name = function (n) { return names[n]; }; alert(digit_name(3)); // 'three'

slide-9
SLIDE 9

Slow

var digit_name = function (n) { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return names[n]; }; alert(digit_name(3)); // 'three'

slide-10
SLIDE 10

Closure

var digit_name = (function () { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function (n) { return names[n]; }; }()); alert(digit_name(3)); // 'three'

slide-11
SLIDE 11

Soft Objects

  • An object is simply a dynamic container of

name/value pairs.

  • New pairs (or properties) may be added at

any time.

  • The value of a property may be a function.
  • The pseudo-parameter this is bound at

invocation time.

  • An object can inherit from another object.
slide-12
SLIDE 12

Object Literals

  • Like JSON objects, but more powerful.
  • Values can be obtained from expressions.
  • Values can be functions.
slide-13
SLIDE 13
slide-14
SLIDE 14

Scheme Self Java LiveScript

slide-15
SLIDE 15

Scheme Self Java LiveScript JavaScript

slide-16
SLIDE 16

Scheme Self Java LiveScript JavaScript ECMAScript

slide-17
SLIDE 17

ECMAScript

  • 1999 Third EditionES3
  • 2009 Fifth Edition

ES5

– Default Strict

  • Avoid ES5/Default.
  • For the short term, work in the intersection
  • f ES3 and ES5/Strict
  • For the long term, work with ES5/Strict.
slide-18
SLIDE 18

Harmony

  • The code name of the next proposal is Harmony,

not ES6.

  • We want to avoid giving proposals edition

numbers because it gives the false appearance

  • f inevitability or momentum.
  • Harmony will be built on the Strict Language.
  • Harmony will probably have incompatible

syntax, so programs written in the Harmony language will fail on all pre-Harmony browsers.

  • Hopefully the IE6 problem will be gone by the

time our work is done.

slide-19
SLIDE 19

JavaScript is the virtual machine of the Internet.

slide-20
SLIDE 20

Server Side JavaScript

  • This is not a new idea.
  • Netscape offered an SSJS product in

1996.

  • It was a page template system using a

<server> tag and a write function to insert matter in the output stream.

  • It had all of the disadvantages of the other

page template systems with a really slow JS engine.

slide-21
SLIDE 21

Threading

Pro

  • No rethinking is

necessary.

  • Blocking programs are
  • k.
  • Execution continues as

long as any thread is not blocked. Con

  • Stack memory per thread.
  • If two threads use the

same memory, a race may occur.

  • Overhead.
  • Deadlock.
  • Thinking about reliability

is extremely difficult.

  • System/Application

confusion.

slide-22
SLIDE 22

Fortunately, there is a model that completely avoids all of the reliability hazards of threads.

slide-23
SLIDE 23

The Event Loop!

slide-24
SLIDE 24

Browser Event Loop

  • Event queue containing callback functions.

(timer, ui, network)

  • Turn: Remove one callback from the
  • queue. It runs to completion.
  • Prime Directive: Never block. Never wait.

Finish fast.

  • The Event Loop is one of the best parts of

the browser.

  • Avoid: alert, confirm , prompt, XHR

synchronous.

slide-25
SLIDE 25

JavaScript does not have READ.

That has always been seen as a huge disadvantage, but it is actually a wonderful thing.

slide-26
SLIDE 26

Event Loop

Pro

  • Free of races and

deadlocks.

  • Only one stack.
  • Very low overhead.
  • Resilient. If a turn fails,

the program can still go

  • n.

Con

  • Programs must never

block.

  • Programs are inside out!

Waa!

  • Turns must finish quickly.
slide-27
SLIDE 27

Long running tasks

  • Two solutions for long running programs:
  • 1. Eteration: Break the task into multiple

turns.

  • 2. Move the task into a separate process

(workers).

slide-28
SLIDE 28

What about Server Side JavaScript with an Event Loop?

slide-29
SLIDE 29

node.js

  • node.js implements a web server in a

JavaScript event loop.

  • It is a high-performance event pump.
  • fs.read(fd, length, position, encoding,

function (err, str, bytesRead) {...})

  • Everything is non-blocking.
  • Except:

– some synchronous functions – require

slide-30
SLIDE 30

Your stuff runs on both sides

JS/V8 Browser DOM JS DOM node.js YUI3 Your stuff Your stuff YUI3

slide-31
SLIDE 31

Requestor

myRequestor = function (sync) { service_request(arguments, function (result) { sync(result, error); }); }; par([requestors…], sync, timeout); seq([requestors…], sync, timeout);

slide-32
SLIDE 32

Security

slide-33
SLIDE 33
slide-34
SLIDE 34

Cross site scripting attacks were invented in 1995.

We made no progress on the fundamental problem.

slide-35
SLIDE 35

XSS has two causes:

  • 1. Sharing of the global object.

The Principle of Excessive Authority.

  • 2. Misinterpretation of HTML.
slide-36
SLIDE 36

What can an attacker do if he gets some script into your page?

slide-37
SLIDE 37

An attacker can request additional scripts from any server in the world.

Once it gets a foothold, it can

  • btain all of the scripts it needs.
slide-38
SLIDE 38

An attacker can read the document.

The attacker can see everything the user sees.

slide-39
SLIDE 39

An attacker can make requests of your server.

Your server cannot detect that the request did not originate with your application.

slide-40
SLIDE 40

If your server accepts SQL queries, then the attacker gets access to your database.

SQL was optimized for SQL Injection Attacks

slide-41
SLIDE 41

An attacker has control over the display and can request information from the user.

The user cannot detect that the request did not originate with your application.

slide-42
SLIDE 42

An attacker can send information to servers anywhere in the world.

slide-43
SLIDE 43

The consequences of a successful attack are horrible.

Harm to customers. Loss of trust. Legal liabilities.

slide-44
SLIDE 44

The browser does not prevent any of these terrible things.

Web standards require these weaknesses.

slide-45
SLIDE 45

15 Years

  • f XSS
slide-46
SLIDE 46

HTML5

A big step in the wrong direction.

slide-47
SLIDE 47

Tragically, HTML5 ignores and worsens the XSS problem.

“…HTML doesn’t ever have markup injection vulnerabilities…”

http://lists.w3.org/Archives/Public/public-webapps/2010AprJun/0648.html
slide-48
SLIDE 48

My Recommendation

  • Suspend the HTML5 standards process.
  • Repair the XSS hazard.
  • Review the HTML5 proposals with respect

to the new security discipline.

slide-49
SLIDE 49

And then there is the Mashup Problem

  • A mashup is the combining of programs

representing multiple interests.

  • The browser confuses those interests.
  • A mashup is a self-inflicted XSS attack.
  • So an advertiser on a page gets the same

privileges as an Ajax library or an analytics file, which is the same as the main applications, which is the same as any XSS code that falls into the page.

  • Advertising is a self-inflicted XSS attack.
slide-50
SLIDE 50

Safe JavaScript Subsets

Deny access to the global object and the DOM. Caja. http://code.google.com/p/google-caja/ ADsafe. http://www.ADsafe.org/

slide-51
SLIDE 51

ECMAScript Fifth Edition Strict

December 2009

slide-52
SLIDE 52

ES5/Strict makes it possible to have static verification of third party code without over- constraining the programming model.

The best of both Caja and ADsafe.

slide-53
SLIDE 53

The IE6 Problem

slide-54
SLIDE 54

IE6 MUST DIE!

slide-55
SLIDE 55

IE7 MUST DIE!

slide-56
SLIDE 56

IE8 MUST DIE!

slide-57
SLIDE 57

IE9

slide-58
SLIDE 58

Thank you and good night.