Function.caller now returns null for strict, async, generator functions

Published: | Categories: JavaScript

Description

Firefox 75 has changed the behaviour of the Function.caller property to align with the latest ECMAScript spec proposal. It was previously throwing a TypeError when the caller was a strict function. Starting with Firefox 75, the property will return null for such cases. The same applies to async functions and generator functions where access to the caller was not restricted before.

function x() {
  console.log(x.caller);
}
// All the following functions now logging `null`
(function s() {
  "use strict";
  x(); // Previously throwing
})();
(async function a() {
  x(); // Previously logging `a()`
})();
(function* g() {
  yield x(); // Previously logging `g()`
}().next());

References