Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test which restrictions are currently implemented in browsers #1

Closed
claudepache opened this issue Jan 14, 2019 · 3 comments
Closed

Comments

@claudepache
Copy link
Owner

claudepache commented Jan 14, 2019

Current implementations may or may not add restrictions on the following kinds of (mostly post-ES3) function:

  • strict functions
  • functions with non-simple parameter list
  • arrow functions
  • generator functions
  • async functions
  • bound functions
  • proxied functions
  • builtin functions
  • functions in another Realm
  • getters and setters in object literals
  • methods in object literals

Moreover, there are two kinds of restriction that may apply:

  1. Attempting to access the caller or the arguments property on such a function object:
    1. throws a TypeError, or
    2. returns null or undefined.
  2. When the caller property is about to return such a function object:
    1. throws a TypeError, or
    2. returns null or undefined.
@littledan
Copy link

Hmm, it'd be interesting to see how these restrictions are implemented across various JS engines. This could be tested via eshost and jsvu, if anyone is interested.

@claudepache
Copy link
Owner Author

claudepache commented Mar 12, 2019

Preliminary tests on Firefox, Chrome, Safari and Edge:

  1. When attempting to access caller or arguments on:
    • a strict, built-in, bound, arrow, generator, async function: everyone: throw a TypeError
    • an object method or getter: Firefox, Chrome, Safari: throw a TypeError
    • a proxied function: Firefox: throw a TypeError
  2. When caller is about to return:
    • a strict function: Firefox, Edge, Safari: throw a TypeError; Chrome: return null
    • a built-in function: Firefox, Chrome, Safari: return null ; Edge: return that function 👎
    • a generator or an async function : Safari: throw a TypeError

Note: When testing Safari, we should be aware that, because of PTC, the caller may not be the one that you think:

function getCaller() { return getCaller.caller }

;(function() { "use strict"; var r = getCaller(); return r })()
// TypeError: Function.caller used to retrieve strict caller

;(function() { "use strict"; return getCaller() })()
// PTC applies; no error (unless executed from within a strict-mode environment, of course)

@claudepache
Copy link
Owner Author

claudepache commented Mar 12, 2019

So, roughly, for case 1, we can distinguish two classes of functions:

  1. “ES3 functions” (e.g. non-strict functions constructed with the ”function” keyword) — accessing .arguments or .caller property on those functions is allowed;
  2. other functions — attempting to access .arguments or .caller on those functions throws a TypeError.

Edge treats methods and getters in object literals as “ES3 functions”, other engines as “other functions”.

And for case 2, we can distinguish three or four classes of functions:

  1. sloppy-mode functions — revealing them through .caller is allowed;
  2. strict-mode functions — revealing them through .caller is forbidden: either throw a TypeErrror or return null;
    • Safari does also throw a TypeError for generators and async functions;
  3. built-in functions — revealing them through .caller is either forbidden (returning null); or allowed (which is objectionable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants