function's "caller" getter throws error when the caller is in strict mode, while V8 returns null
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
People
(Reporter: laszlo.janszky, Unassigned)
References
Details
(Whiteboard: [parity-chrome])
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
Steps to reproduce:
1.) with arguments.callee
class A {
constructor(){
arguments.callee;
}
}
new A(); // not ok
2.) with arguments.callee.caller
class A {
constructor(){
f();
}
}
function f(){
arguments.callee.caller;
}
new A(); // not ok
Actual results:
throws error
Expected results:
should not throw error
Comment 1•6 years ago
|
||
it should throw error, per spec.
https://tc39.github.io/ecma262/#sec-arguments-exotic-objects
Reporter | ||
Comment 2•6 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #1)
it should throw error, per spec.
https://tc39.github.io/ecma262/#sec-arguments-exotic-objects
Where do you read that?
Reporter | ||
Comment 3•6 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #1)
it should throw error, per spec.
https://tc39.github.io/ecma262/#sec-arguments-exotic-objects
I did not find anything related to this behavior in the linked text and this is the only browser, which throws error. I tried with Chrome and Opera too.
Comment 4•6 years ago
|
||
okay, the 2nd example is not about arguments.callee, but function's "caller" property.
the 1st example throws error on google chrome too.
Updated•6 years ago
|
Comment 5•6 years ago
|
||
(In reply to László Jánszky from comment #2)
(In reply to Tooru Fujisawa [:arai] from comment #1)
it should throw error, per spec.
https://tc39.github.io/ecma262/#sec-arguments-exotic-objectsWhere do you read that?
NOTE 3
Ordinary arguments objects define a non-configurable accessor property named "callee" which throws a TypeError exception on access.
Reporter | ||
Comment 6•6 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #5)
(In reply to László Jánszky from comment #2)
(In reply to Tooru Fujisawa [:arai] from comment #1)
it should throw error, per spec.
https://tc39.github.io/ecma262/#sec-arguments-exotic-objectsWhere do you read that?
NOTE 3
Ordinary arguments objects define a non-configurable accessor property named "callee" which throws a TypeError exception on access.
Okay, that's true. I just did not know that using classes enables strict mode.
Comment 7•6 years ago
|
||
according to the spec, the 2nd example is just implementation-dependent.
https://tc39.github.io/ecma262/#sec-forbidden-extensions
If an implementation extends any function object with an own property named "caller" the value of that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function object. If it is an accessor property, the function that is the value of the property's [[Get]] attribute must never return a strict function when called.
basically, the spec doesn't define anything about "caller" property, but just adds the above restriction.
and class constructor is in strict mode.
https://tc39.github.io/ecma262/#sec-strict-mode-code
All parts of a ClassDeclaration or a ClassExpression are strict mode code.
then, google chrome returns null
for such access.
so, per spec, both throwing and returning null should be valid behavior.
Updated•6 years ago
|
Reporter | ||
Comment 8•6 years ago
|
||
I hate ES6 more and more each day. :D Thanks for investigating this! Have a nice day!
Comment 9•6 years ago
•
|
||
There's a proposal to standardize Function.prototype.caller
and .arguments
. We'll wait to see what happens before changing behavior here. It looks like the proposal would leave the detail that's at issue here unspecified. I'll push to have it specified one way or the other.
Updated•6 years ago
|
Comment 10•6 years ago
|
||
In the second test case, a TypeError is also thrown by Safari and Edge. If/when Function.prototype.caller
is standardised, we’ll most certainly pick Firefox/Safari/Edge’s behaviour (throw a TypeError) in that particular test case.
So, this bug could be closed as Working as Intended.
Comment 11•5 years ago
|
||
With Bug 1610206 fixed, a censored caller now induces a returned value of null instead of a thrown TypError (like V8, and contrarily to what I’ve claimed in previous comment.)
In short: Fixed with Bug 1610206.
Comment 12•5 years ago
|
||
Thanks!
Description
•