Closed Bug 1379717 Opened 7 years ago Closed 7 years ago

Throw TypeError when accessing "caller/arguments" properties on accessor methods

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(1 file)

Test case 1:
---
var o = { get m(){} };
var g = Object.getOwnPropertyDescriptor(o, "m").get;
print(g.arguments);
---

Test case 2:
---
var o = { get m(){} };
var g = Object.getOwnPropertyDescriptor(o, "m").get;
print(g.caller);
---

Expected: Both test cases throw a TypeError
Actual: No error thrown

JSC/V8 throw a TypeError, Chakra doesn't.
Attached patch bug1379717.patchSplinter Review
I didn't want to add yet another condition to the IsNewerTypeFunction() function, when we could simply branch on the function kind instead.
Attachment #8884952 - Flags: review?(shu)
(In reply to André Bargull from comment #0)
> Test case 2:
> ---
> var o = { get m(){} };
> var g = Object.getOwnPropertyDescriptor(o, "m").get;
> print(g.caller);
> ---
> 
> Expected: Both test cases throw a TypeError
> Actual: No error thrown
> 
> JSC/V8 throw a TypeError, Chakra doesn't.

Isn't that only supposed to throw on strict mode?
Doesn't the first item in Forbidden Extensions[1] explicitly say that no such properties must be added, regardless of whether the code is in strict mode or not?

[1] https://tc39.github.io/ecma262/#sec-forbidden-extensions
(In reply to Nicolas B. Pierron [:nbp] from comment #2)
> (In reply to André Bargull from comment #0)
> > Test case 2:
> > ---
> > var o = { get m(){} };
> > var g = Object.getOwnPropertyDescriptor(o, "m").get;
> > print(g.caller);
> > ---
> > 
> > Expected: Both test cases throw a TypeError
> > Actual: No error thrown
> > 
> > JSC/V8 throw a TypeError, Chakra doesn't.
> 
> Isn't that only supposed to throw on strict mode?

ES6 added a new restriction that any function form except for FunctionDeclaration and FunctionExpression must not be created with own "arguments" and "caller" properties (https://tc39.github.io/ecma262/#sec-forbidden-extensions). But since SpiderMonkey implements these legacy properties as accessors (*), we need to 'translate' this restriction into throwing a TypeError when the accessors are called with anything besides FunctionDeclaration and FunctionExpression.

(*) This is an ongoing experiment for TC39, in case TC39 decides to spec these legacy properties.
Comment on attachment 8884952 [details] [diff] [review]
bug1379717.patch

Review of attachment 8884952 [details] [diff] [review]:
-----------------------------------------------------------------

Nice job expanding out the test.
Attachment #8884952 - Flags: review?(shu) → review+
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/3bceabbf445d
Throw TypeError when accessing caller/arguments on accessor method. r=shu
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/3bceabbf445d
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
Depends on: 1386026
You need to log in before you can comment on or make changes to this bug.