Skip to content

Latest commit

 

History

History
261 lines (172 loc) · 6.84 KB

js-spec.md

File metadata and controls

261 lines (172 loc) · 6.84 KB

JavaScript feature set overview

Enumerating which language constructs and types are allowed. Some high level design goals, example implementation and inspirations are mentioned. This is non normative work in progress.

See the following document for a detailed reasoning about each choice of cutting features from the grammar:

Statements

  • if-else
  • while
  • for-in
  • comments
  • function definition
  • return
  • optional compound block within if, while or for statements ({})
  • ES3/NS5: try-catch, throw

convenience:

  • function expression

missing:

  • ES3/NS4: switch-case-default, do-while, label-goto
  • for (the C-styled one), for-of, break, continue, with, varargs, arbitrary block scopes with {}
  • NS2: arguments
  • ES3/NS4: call, apply
  • ES6: tail call optimization

Operators

  • !, ~, +, -, *, /, %, <, >, <=, >=, ^, |, &, <<, >>, >>>, ===, !==

convenience:

  • parenthesis subexpressions, short-circuiting &&, ||, '+' also works for string concatenation
  • ES1/NS3: typeof

missing:

  • ==, !=, +=, ++, class, new (mocked for some built-in objects), precedence (have to fully parenthesize)
  • ES3/NS5: instanceof
  • ES1/NS2: ternary operator
  • ES1/NS2: comma operator
  • NS4: delete

Values

  • var
  • undefined
  • null
  • decimal integers
  • NaN
  • string literals (without escaping)
  • Object and Array square bracket member accessor ([])

convenience:

  • var initializer, object dot member accessor, member access chaining
  • ES3/NS4: anonymous function expression

missing:

  • this, true, false, hexadecimal, float, string control character escapes
  • NS3: void
  • ES3: Object and Array literals
  • ES5: const, let

Functions

  • eval
  • eval2: not standard, a sandboxed variant not operating on the current environment, but on one passed in as an Object argument
  • isNaN
  • parseInt(s, 10)

missing:

  • parseFloat, escape, unescape

Language objects

missing:

  • Boolean, Function, Math, Number, RegExp

Array

  • .length
  • [i]

missing:

  • ES2/NS3: join, reverse, sort
  • ES3/NS4: concat, pop, push, shift, slice, splice, unshift

Date

missing:

  • everything except a few basic arithmetics with the current time in milliseconds (date + number, date / number, date % number, date - date)

Object

  • ES3: .hasOwnProperty

missing:

  • NS3: valueOf

String

  • .length
  • .charAt
  • ES2/NS4: String.prototype.fromCharCode
  • ES2/NS4: .charCodeAt

convenience:

  • .indexOf
  • ES3/NS4: .match

missing:

  • .lastIndexOf, .substring, .toLowerCase, .toUpperCase
  • ES2/NS3: .split
  • ES3/NS4: .concat, .slice, .replace, .search, .substr

Application server

TODO This section still needs more research, a proof of concept and then drafting.
  • console.log()
  • process.stdin.on('data', function(data) {})
  • require('fs').readFileSync(file)
  • require('fs').writeFileSync(file, data)
  • require('node:net').createServer(function(socket) {}).listen(function(){}).close()
  • require('node:net').createConnection({}, function() {}).on('data', function(data) {}).write('')
  • require('node:net').connect({})

Navigator objects

These are not provided by the interpreter, but by the runtime of the web browser user agent.

Document

  • document.close
  • document.write
  • document['FormName']['ElementName'].value

convenience:

  • document.docType, document.documentElement.innerHTML

missing:

  • document.open (implicit)

Cookies

A hardened minimal subset required to interface with most common gratis web hosting, storage and authorization providers

  • document.cookie (expires)
  • public suffix list

Window

  • window.location.href
  • NS2: window.setTimeout (function argument)

missing:

  • window.location.replace, window.setTimeout (string variant), window.clearTimeout
  • NS4: window.setInterval

XMLHttpRequest

  • new XMLHttpRequest
  • .open
  • .onload
  • .onerror
  • .ontimeout
  • .status
  • .timeout
  • .send
  • .responseText

Implementation

Multiple proof of concept interpreter runtimes are in progress. If you would like to help with implementing this subset in a minimalistic way and provide feedback, let's get in touch to help shape the specification for the better.

A simple, text-entry & pre based browser written in the JavaScript subset interpreted by the interpreter in the browser:

Work in progress C interpreter aiming for short source that is easy to review, small size of compressed binary code and low memory footprint:

Not published yet:

  • Multiple C-based interpreters for various subsets

Planned on shortlist:

  • A minimalistic real world web app running in the C browser and runtime

Inspiration

Best practices

References

JavaScript 1.0

JavaScript 1.1

JavaScript 1.2

EcmaScript