Function decompilation tests

Description Code Result Notes
ES3
Native
Object
Some browsers (e.g. Konqueror) have unique "[function]" representation
Built-in
window.alert
Built-in #2
window.focus
Some browsers (e.g. Chrome) omit identifier of some of the built-in methods
User-defined
function test   (arg1, $foo, /* comment */ _BAR)   { // inline comment

  /*
    some
    comment
  */
  noOpStatement;
  nonexistentIdentifier();

  alert(1 + 1);

  if (false) { return 123 }

  return $foo
    .something()   /   _BAR  + /^reg\/ex$/gmi;

  somethingElse();
}

Some browsers (e.g. FF<17) strip all comments and "dead" code (if (false) ..., { }, statements after return, etc.). They also "inline" code (1+1 becomes 2, etc.)

Most of the browsers do not preserve space between function identifier and parameters list.

Some browsers (e.g. Konqueror) insert newlines after parameters list and also "inline" code.

User-defined NFE
var leftHand = function rightHand() { return };
User-defined NFE w. comments around
/* foo bar */ (((function test(){}) /* baz qux */ ))
Some browsers (e.g. IE<9) include comments AND spaces around function in its string representation
User-defined & generated
new Function('x, y', '/* comment */ return x + y')
Some browsers (e.g. Chrome) include extra comments /**/ and/or newlines next to parameters list

Some browsers (e.g. Konqueror) omit brackets surrounding function body

Non-standard
User-defined & with "name"
var withName = function() { };
withName.name = 'someName';
Expression closures
var expressionClosure = function(x, y) x + y
Browsers that support expression closures (e.g. FF), represent them using bracketless notation
"use asm"
function use_asm (x, y) {
  "use asm";
  return x + y;
}
Some browsers (e.g. FF<17) strip "use asm" statement, likely considering it "dead code".
ES5
User-defined & bound
function f (x, y, /* comment */ z) {
  return /* comment */ x + y;
}
var bound = f.bind({ });
Most (all?) of the browsers replace function code with "[native code]" when representing bound functions. Some browsers (e.g. WebKit) show original function identifier and some don't
"use strict"
function use_strict (x, y) {
  "use strict";
  return x + y;
}
Some browsers (e.g. FF<4) strip "use strict" statement, likely considering it "dead code".
ES6
Arrow functions
var a = () => 5;
Browsers that support arrow functions (e.g. FF24+), represent them using () => notation
Functions with rest params
function withRestParams(...args) {
  return args;
}
Browsers that support rest params (e.g. FF24+), represent them using (...args) notation
Functions with default params
function defaultParams(a = 1) { return a === 1; }
Browsers that support default params (e.g. FF24+), represent them using arg = ... notation
Generators
var generator = (function* () { yield 1; });
Browsers that support generators (e.g. FF24+), represent them using function* notation