What's wrong with Web and how to live with it

Sergey Rubanov, EXANTE ltd.

What's wrong with Web

and how to live with it

Sergey Rubanov

JavaScript Samurai

EXANTE ltd.

Harmony

ECMA-262 (6th edition) - ECMAScript 2015 Language Specification

ECMA-402 (2nd edition) - ECMAScript 2015 Internationalization API Specification

My talk TC39 Process (ru)

June 17, 2015

Stable browsers + Edge

June 25, 2015

Unstable browsers

June 27, 2016

Post-Harmony

ECMA-262 (7th edition) - ECMAScript 2016 Language Specification

ECMA-402 (3rd edition) - ECMAScript 2016 Internationalization API Specification

ECMA-414 (1st edition) - ECMAScript Specification Suite

June 14, 2016

Problems?

Syntax evolution

Reserved words

Future reserved words

Annex E

Additions and Changes That Introduce Incompatibilities with Prior Editions

Mozilla
vs
Mootools

array.indexOf(element) !== -1

Mozilla

Array.prototype.contains()

Mozilla

if (!Array.prototype.contains) {
      Array.prototype.contains = ...
}

Mootools 1.2

Array.prototype.includes()

Mozilla

FIN.

FIN.

FIN.

contains vs includes

Tail Calls

A tail call is a return statement with a function call, where nothing has to happen after the call except returning its value.

Kyle Simpson, YDKJS
"use strict";

function factorial(n) {
    if (!n) return 1;
    return n * factorial(n - 1);   // not tail call
}

factorial(170);                    // RangeError
"use strict";

function factorial(n, partialFactorial = 1) {
    if (!n) return partialFactorial;
    return factorial(n - 1, n * partialFactorial); // tail call
}

factorial(170);                                    // 7.257415615308004e+30

Tail Position

Benefits of Proper Tail Calls

Current state of Tail Calls in JavaScript

Syntactic Tail Calls

"use strict";

function factorial(n, acc = 1) {
    if (!n) return partialFactorial;
    return continue factorial(n - 1, n * partialFactorial);
}

Issues with PTC (according to STC proposal)

Additional info

for-in initializers

All of V8, JavaScriptCore, and SpiderMonkey have found themselves unable to honor the ECMAScript 2015 requirement that for (var x = 0 in []); is a SyntaxError (which is documented in Annex E 13.7).

Jay Freeman, issue in ECMA-262 spec repo

WebAssembly

My talk WebAssembly: new Era of Web (ru)

a new binary syntax for low-level safe code, initially co-expressive with asm.js, but in the long run able to diverge from JS’s semantics, in order to best serve as common object-level format for multiple source-level programming languages.

Brendan Eich

Brandan Eich's blog, June 17, 2015

WebAssembly is efficient and fast

The wasm AST is designed to be encoded in a size- and load-time-efficient binary format. WebAssembly aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms.

WebAssembly is safe

WebAssembly describes a memory-safe, sandboxed execution environment that may even be implemented inside existing JavaScript virtual machines. When embedded in the web, WebAssembly will enforce the same-origin and permissions security policies of the browser.

WebAssembly is open and debuggable

WebAssembly is designed to be pretty-printed in a textual format for debugging, testing, experimenting, optimizing, learning, teaching, and writing programs by hand. The textual format will be used when viewing the source of wasm modules on the web.

WebAssembly is part of the open web platform

WebAssembly is designed to maintain the versionless, feature-tested, and backwards-compatible nature of the web. WebAssembly modules will be able to call into and out of the JavaScript context and access browser functionality through the same Web APIs accessible from JavaScript. WebAssembly also supports non-web embeddings.

High-Level Goals

  1. Define a portable, size- and load-time-efficient binary format to serve as a compilation target which can be compiled to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms, including mobile and IoT.

High-Level Goals

  1. Specify and implement incrementally:
    • a Minimum Viable Product (MVP) for the standard with roughly the same functionality as asm.js, primarily aimed at C/C++;
    • an effective and efficient polyfill library for the MVP that translates WebAssembly code into JavaScript in the client so that WebAssembly MVP can run on existing browsers;
    • a follow-up to the MVP which adds several more essential features; and
    • additional features, specified iteratively and prioritized by feedback and experience, including support for languages other than C/C++.

High-Level Goals

  1. Design to execute within and integrate well with the existing Web platform:
    • maintain the versionless, feature-tested and backwards-compatible evolution story of the Web;
    • execute in the same semantic universe as JavaScript;
    • allow synchronous calls to and from JavaScript;
    • enforce the same-origin and permissions security policies;
    • access browser functionality through the same Web APIs that are accessible to JavaScript; and
    • define a human-editable text format that is convertible to and from the binary format, supporting View Source functionality.

High-Level Goals

  1. Design to support non-browser embeddings as well.

High-Level Goals

  1. Make a great platform:
    • build a new LLVM backend for WebAssembly and an accompanying clang port;
    • promote other compilers and tools targeting WebAssembly;
    • enable other useful tooling.

MVP

Essential Post-MVP Features

Some of features to add after the MVP

Links

The steps in the polyfill process

The steps in the standards process

PostCSS

Houdini

Links

What about DOM?

Contact me

github.com/chicoxyzzy
twitter.com/chicoxyzzy
linkedin.com/in/chicoxyzzy

Slides chicoxyzzy.github.io/talks/whats_wrong_with_web