Open Bug 1396933 Opened 7 years ago Updated 2 years ago

Error message for strict mode functions' and arguments' properties is misleading

Categories

(Core :: JavaScript Engine, enhancement, P2)

55 Branch
enhancement

Tracking

()

REOPENED
Tracking Status
firefox55 --- affected
firefox56 --- affected
firefox57 --- fix-optional

People

(Reporter: jakwings, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [js:correctness])

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:55.0) Gecko/20100101 Firefox/55.0
Build ID: 20170824053838

Steps to reproduce:

Run code: (function(){'use strict'}).callee || (()=>'use strict').callee


Actual results:

Returned: undefined


Expected results:

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
There is no restriction for "callee" on strict-mode functions. Maybe you got confused by the "caller" restriction on strict-mode functions, or the "callee" restriction on arguments-objects in strict-mode functions?
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
the error message seems to be misleading, since it's mixing 2 things up.

what you cannot do are:
  1. (function(){'use strict'}).caller
     https://tc39.github.io/ecma262/#sec-addrestrictedfunctionproperties (step 3)
  2. (function(){'use strict'}).arguments
     https://tc39.github.io/ecma262/#sec-addrestrictedfunctionproperties (step 4)
  3. (function () {'use strict'; return arguments.caller;})()
     https://tc39.github.io/ecma262/#sec-arguments-exotic-objects the (NOTE 4) (the requirement is dropped tho)
  4. (function () {'use strict'; return arguments.callee;})()
     https://tc39.github.io/ecma262/#sec-createunmappedargumentsobject (step 8)
     https://tc39.github.io/ecma262/#sec-createmappedargumentsobject (step 23)

we should throw different error message for function's property access and arguments' property access.
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: INVALID → ---
Summary: Access to strict mode functions' callees does not throw errors → Error message for strict mode functions' and arguments' properties is misleading
Blocks: jserror
Severity: normal → enhancement
Thanks. I found that (()=>{}).arguments and (()=>{}).caller also throw errors. Is this a bug?
(In reply to J.W from comment #3)
> Thanks. I found that (()=>{}).arguments and (()=>{}).caller also throw
> errors. Is this a bug?

No, this is also expected. The error message is just (again) a bit misleading:
The "caller" and "arguments" restrictions were originally added in ECMAScript 5 for strict-mode functions, that's why the error message in Firefox still mentions "strict mode", but later ECMAScript editions extended the error restriction to all functions, but normal, non-strict functions. So, any function except when written as `function maybe_some_name(){ ... }` have this restriction.
(In reply to André Bargull from comment #4)
> (In reply to J.W from comment #3)
> > Thanks. I found that (()=>{}).arguments and (()=>{}).caller also throw
> > errors. Is this a bug?
> 
> No, this is also expected. The error message is just (again) a bit
> misleading:
> The "caller" and "arguments" restrictions were originally added in
> ECMAScript 5 for strict-mode functions, that's why the error message in
> Firefox still mentions "strict mode", but later ECMAScript editions extended
> the error restriction to all functions, but normal, non-strict functions.
> So, any function except when written as `function maybe_some_name(){ ... }`
> have this restriction.

OK, I found the related spec and tests:

https://tc39.github.io/ecma262/#sec-forbidden-extensions

> ECMAScript function objects defined using syntactic constructors in strict mode code must not be created with own properties named "caller" or "arguments". Such own properties also must not be created for function objects defined using an ArrowFunction, ... regardless of whether the definition is contained in strict mode code. ... (TIL: and more special cases)

https://tc39.github.io/ecma262/#sec-strict-mode-code

> Function code is strict mode code ... or if the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.

https://github.com/tc39/test262/blob/da4f4385fdf88ff2c8acf036efaaa62f8cd6bd58/test/language/expressions/arrow-function/ArrowFunction_restricted-properties.js
Priority: -- → P2
Whiteboard: [js:correctness]
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.