Tamarin and ECMAScript 4. John Resig (ejohn.org) Mozilla Corporation

Similar documents
JavaScript Lecture 1

Compiler Errors. Flash CS4 Professional ActionScript 3.0 Language Reference. 1 of 18 9/6/2010 9:40 PM

JavaScript: Introduction, Types

JavaScript: Sort of a Big Deal,

Distributed Systems Recitation 1. Tamim Jabban

INF5750. Introduction to JavaScript and Node.js

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

arxiv: v1 [cs.pl] 15 Dec 2009

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Adobe Flash Player ActionScript Virtual Machine (Tamarin)

Classes vs Simple Object Delegation In JavaScript

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

Introduction to Programming Using Java (98-388)

Advanced Systems Programming

Chapter 1 Getting Started

Boot Camp JavaScript Sioux, March 31, 2011

Background. Javascript is not related to Java in anyway other than trying to get some free publicity

Powerful JavaScript OOP concept here and now. CoffeeScript, TypeScript, etc

Javascript. Many examples from Kyle Simpson: Scope and Closures

Comp 426 Midterm Fall 2013

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

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

JavaScript: Features, Trends, and Static Analysis

Pascal: operations on basic data structures (selection) (I) 2.3 Accessing and manipulating data

Canonical Form. No argument constructor Object Equality String representation Cloning Serialization Hashing. Software Engineering

JavaScript Libraries. Ajax Experience - October John Resig (ejohn.org)

EL2310 Scientific Programming

Introduction to TypeScript

Java Persistence API (JPA) Entities

Object Model. Object Oriented Programming Spring 2015

JavaScript: The Definitive Guide

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

University of Palestine. Mid Exam Total Grade: 100

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

LAST WEEK ON IO LAB. Install Firebug and Greasemonkey. Complete the online skills assessment. Join the mailing list.

JavaScript: Getting Started

Advanced JavaScript. Advanced JavaScript. Banyan Talks Łukasz Rajchel

JavaScript Doesn't Have to Hurt: Techniques, Tools and Frameworks to Ease JavaScript Development

Pete Forde Partner, Unspace Interactive Toronto, ON January 9, 2007

Lecture 10 Design by Contract

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Introduce C# as Object Oriented programming language. Explain, tokens,

pysharedutils Documentation

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

Distributed Systems Recitation 1. Tamim Jabban

Status Report. JSR-305: Annotations for Software Defect Detection. William Pugh Professor

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

This exam in 7 pages, make sure to read all the questions and use the backside as a draft area. a. The old name of (C++) is (C version 2).

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Data Visualization (CIS 468)

Outline. Central concepts in OO languages Objects as activation records (Simula) Dynamically-typed object-oriented languages

Attacking ECMAScript Engines with Redefinition. Natalie

2. JAVA OOP R E F E R E N C E : O B J E C T O R I E N T E D D E S I G N A N D P R O G R A M M I N G ( H O R S T M A N N )

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

iwiki Documentation Release 1.0 jch

5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.

Introduction to Swift. Dr. Sarah Abraham

Common Misunderstandings from Exam 1 Material

Polymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

classjs Documentation

Framework Fundamentals

Java: framework overview and in-the-small features

The results for a few specific cases below are indicated. allequal ([1,1,1,1]) should return true allequal ([1,1,2,1]) should return false

Let's see a couple of examples

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

Terratype Umbraco Multi map provider

Big software. code reuse: The practice of writing program code once and using it in many contexts.

Student, Perfect Final Exam May 25, 2006 ID: Exam No CS-081/Vickery Page 1 of 6

Swift. Introducing swift. Thomas Woodfin

ECMAScript 2015 The Future of JavaScript is Now!

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic?

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

2.4 Structuring programs

Object Model. Object Oriented Programming Winter

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

COMP 401 Spring 2013 Midterm 1

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Fuzzilli. (Guided-)fuzzing for JavaScript engines. Samuel Groß

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

JQUERYUI - PROGRESSBAR

C#: framework overview and in-the-small features

COMPUTER APPLICATION

Principles of Programming Languages

Java Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Office 2016 Excel Basics 06 Video/Class Project #18 Excel Basics 6: Customize Quick Access Toolbar (QAT) and Show New Ribbon Tabs

Java Classes, Inheritance, and Interfaces

JavaScript for PHP Developers

Domain-Driven Design Activity

the usual suspects UIObject HasWidgets Widget

Microsoft. Microsoft Visual C# Step by Step. John Sharp

C++_ MARKS 40 MIN

Example: Fibonacci Numbers

CS197WP. Intro to Web Programming. Nicolas Scarrci - February 13, 2017

Mixed projects: Java + Kotlin. Svetlana Isakova

Language Reference Manual

Final CSE 131B Spring 2004

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Transcription:

Tamarin and ECMAScript 4 John Resig (ejohn.org) Mozilla Corporation

The Big Picture ECMAScript 3 JavaScript 1.5 ActionScript 2 JScript Etc. SpiderMonkey AVM JScript Engine KJS (Apple) Rhino Opera

The Direction ECMAScript 4 JavaScript 2 ActionScript 4 JScript Etc. Tamarin Screaming Monkey KJS (Apple) Opera

Tamarin Tamarin New Virtual Machine from Adobe Perfect for ActionScript (a mutant cousin of JavaScript 2) The Three Monkeys: ActionMonkey ScreamingMonkey IronMonkey

Three Monkies ActionMonkey Integrating Tamarin into SpiderMonkey Powering Firefox 4 (?) + JavaScript 2 ScreamingMonkey Bringing Tamarin into Internet Explorer (Kicking and screaming?) IronMonkey Bringing Python + Ruby to Tamarin

Path to JavaScript 2 JavaScript 1.5 JavaScript 1.6 JavaScript 1.7 JavaScript 1.8 JavaScript 2 1999 2005 2006 2008 2008-2009

The JavaScript Language Current: JavaScript 1.5 (ECMAScript 3) JavaScript 1.6 (Firefox 1.5) JavaScript 1.7 (Firefox 2) JavaScipt 1.8 (Firefox 3)... JavaScript 2 (ECMAScript 4)

ECMAScript 4 Goals Compatible with ECMAScript 3 Suitable to developing large systems Allow for reusable libraries Merge previous efforts (ActionScript) Fix ECMAScript 3 bugs Keep it usable for small programs

Features Classes and Interfaces Packages and Namespaces Type Annotations Strict Verification Optimization Syntax Shortcuts Iterators and Generators Self-hosting

Classes

Classes class Programmer { var name; var city = Boston, MA ; const interest = computers ; function work() { var p = new Programmer; p.name = John ; p.work(); p.work.apply( someotherp ); p.interest = science ; // Error

Dynamic Classes dynamic class Programmer { var name; var city = Boston, MA ; const interest = computers ; function work() { var p = new Programmer; p.lastname = Resig ; for ( var i in p ) alert( i ); // alert( Resig );

Getters and Setters class Programmer { var _name; function get name(){ return _name; function set name(value){ _name = value + Resig ; var p = new Programmer; p.name = John ; alert( p.name ); // John Resig

Catch-Alls dynamic class Programmer { meta function get(name) {... meta function set(name, value) { alert( Setting + name + to + value); var p = new Programmer p.name = John ; // alert( Setting name to John );

Inheritance class Artist { function draw() { alert( Drawing! ); class Designer extends Artist { override function draw() { alert( Designing! ); var d = new Designer d.draw(); // alert( Designing! );

Inheritance (cont.) final methods can t be overriden class Artist { final function draw() {alert( Drawing! ); class Designer extends Artist { // ERROR: Can t override draw! override function draw() { alert( Designing! );

Inheritance (cont.) final classes can t be inherited from final class Artist { function draw() { alert( Drawing! ); // ERROR: Can t inherit from Artist class Designer extends Artist { override function draw() { alert( Designing! );

Metaclass Provide global functions and properties on a class object class Users { static function find( name ) { //... Users.find( John );

Interfaces Verify that a class implements another interface Artist { function draw(); class Designer implements Artist { function draw() { alert( Designing! ); var d = new Designer(); if ( d is Artist ) alert( Designers are Artists! );

Types

Numbers Numbers are now broken down into: byte int uint double (ECMAScript 3-style Number) decimal

Type Annotations var name : string = John ; let x : double = 5.3; function stuff( x: int, obj: Object ) : boolean {

Function Types Only return specific types: function isvalid() : boolean { Only be used on certain objects types: function every( this: Array, value: int ) { for ( var i = 0; i < this.length; i++ ) alert( this[i] ); every.call( [0,1,2], 3 ); // alert(0); alert(1); alert(2); every.call({a: b, 4); // ERROR

Rest Arguments function stuff( name,...values ){ alert( values.length ); stuff( John, 1, 2, 3, 4 ); // alert( 4 ); function stuff( name : string,...values : [int] ) : void { alert( values.length );

Union and Any Types var test : (string, int, double) = test ; test = 3; test = false; // ERROR type AnyNumber = (byte, int, double, decimal, uint); var test : AnyNumber = 3 These are equivalent: var test : * = test ; var test = test ;

Type Definitions type Point = { x: int, y: int ; var p : Point = { x: 3, y: 24 ;

Nullability Prevent variables from accepting null values var name : * = John ; var name : String! = John ; name = Ted ; name = null; // ERROR function test( name: String? ) { alert( name );

Initialization class User { var name : string!; // Must be initialized var last : string!; function User( n, l ) : name = n, last = l { //...

like type Point = { x: int, y: int ; if ( { x: 3, y: 5 like Point ) alert( That looks like a point to me! ); if (!({ x: 3 like Point) ) alert( Not a point! ); // Loop over array-like things: function every( a: like { length: uint ) { for ( var i = 0; i < a.length; i++ ) alert( a[i] );

wrap Force a type if compatible one doesn t exist type Point = { x: int, y: int ; var p: wrap Point = { x: 3, y: 8 ; var p: Point = { x: 3, y: 8 wrap Point; var p: Point = { x: 3, y: 8 : Point;

Parameterized Types var m: Map.<Object, string>; class Point.<T> { var x: T, y: T; var p = new Point.<double>; p.x = 3.0; p.y = 5.0;

Structure

For.. Each For each loops through values let s = ; for each ( let n in [ a, b, c ] ) s += n; alert(s); // abc

let statements for ( let i = 0; i < a.length; i++ ) alert( a[i] ); // i is undefined Using block statements: { let x = 5; { let x = 6; alert( x ); // 6 alert( x ); // 5

let (cont.) let expressions: var a = 5; var x = 10 + (let (a=3) a) + a*a; // x == 19 let blocks: let ( a=3 ) { alert( a ); // 3 // a is undefined let a = function(){ ;

Packages package simple.tracker { internal var count: int = 0; public function add(){ return ++count; import simple.tracker.* alert( add() ); // alert( 1 ) count // ERROR, undefined

Namespaces namespace extra = extra ; Pre-defined namespaces: ES4 intrinsic iterator meta import dojo.query; import jquery.query; dojo::query( #foo ) jquery::query( div >.foo )

Namespaces (cont.) import dojo.query; import jquery.query; use namespace dojo; query( #foo ) // using dojo use namespace jquery; query( div >.foo ) // using jquery

Multimethods generic function intersect(s1, s2); generic function intersect(s1: Shape, s2: Shape ) { //... generic function intersect(s1: Rect, s2: Rect ) { //...

Program Units use unit jquery http://jquery.com/jquery import com.jquery.*; new jquery(); unit jquery { use unit Selectors lib/selectors ; package com.jquery { class jquery { function find() : jquery {

Operator Overloading class Complex! {... generic intrinsic function +(a: Complex, b: Complex) new Complex( a.real + b.real, a.imag + b.imag ) generic intrinsic function +(a: Complex, b: AnyNumber) a + Complex(b) generic intrinsic function +(a: AnyNumber, b: Complex) Complex(a) + b

Self-Hosting

Map.es The reference implementation s classes are written in ECMAScript package { use namespace intrinsic; use default namespace public; intrinsic class Map.<K,V> { static const length = 2; function Map(equals=intrinsic::===, hashcode=intrinsic::hashcode) : equals = equals, hashcode = hashcode, element_count = 0 { //...

More Info ECMAScript site: http://ecmascript.org/ ECMAScript 4 White Paper Overview: http://www.ecmascript.org/es4/spec/overview.pdf Blogging: http://ejohn.org/