Closed Bug 1527810 Opened 6 years ago Closed 5 years ago

function's "caller" getter throws error when the caller is in strict mode, while V8 returns null

Categories

(Core :: JavaScript Engine, defect, P3)

65 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1610206

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

Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID

(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?

(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.

okay, the 2nd example is not about arguments.callee, but function's "caller" property.

the 1st example throws error on google chrome too.

Status: RESOLVED → REOPENED
Component: Untriaged → JavaScript Engine
Ever confirmed: true
Product: Firefox → Core
Resolution: INVALID → ---
Summary: Arguments.callee throws error by ES6 class constructors → arguments.callee.caller throws error when caller is in strict mode.
Whiteboard: [parity-chrome]
Summary: arguments.callee.caller throws error when caller is in strict mode. → function's "caller" getter throws error when caller is in strict mode.

(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-objects

Where do you read that?

NOTE 3

Ordinary arguments objects define a non-configurable accessor property named "callee" which throws a TypeError exception on access.

(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-objects

Where 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.

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.

Status: REOPENED → NEW
Summary: function's "caller" getter throws error when caller is in strict mode. → function's "caller" getter throws error when the caller is in strict mode, while V8 returns null

I hate ES6 more and more each day. :D Thanks for investigating this! Have a nice day!

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.

Priority: -- → P3

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.

See Also: → 1606421

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.

Thanks!

Status: NEW → RESOLVED
Closed: 6 years ago5 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.