Closed Bug 1219028 Opened 5 years ago Closed 5 years ago

Remove use of non-standard Function.prototype.isGenerator from devtools/.

Categories

(DevTools :: General, defect)

defect
Not set

Tracking

(firefox44 fixed)

RESOLVED FIXED
Firefox 44
Tracking Status
firefox44 --- fixed

People

(Reporter: arai, Unassigned)

References

Details

https://hg.mozilla.org/mozilla-central/file/3af8b8e56340/devtools/shared/DevToolsUtils.js#l814

> exports.isGenerator = function (fn) {
>   return typeof fn === "function" && fn.isGenerator();
> };

Function.prototype.isGenerator is non-standard and we're going to remove it (bug 1119777).
looks like only ES6 generator is used there, so it could be written as following if fn always comes from same global.

> let GeneratorFunction = Object.getPrototypeOf(function*(){}).constructor;
> exports.isGenerator = function (fn) {
>   return fn instanceof GeneratorFunction;
> };

if fn may come from different global, following will be the alternative.

> exports.isGenerator = function (fn) {
>   if (typeof fn !== "function") {
>     return false;
>   }
>   let proto = Object.getPrototypeOf(fn);
>   if (!proto) {
>     return false;
>   }
>   let ctor = proto.constructor;
>   if (!ctor) {
>     return false;
>   }
>   return ctor.name == "GeneratorFunction";
> };
can legacy generator be passed to isGenerator function?
if yes and they're all in-tree things, we should fix it too.
if yes and they can be user input or something, we should fix everything at once when dropping legacy generator support.
if no, we can just apply one of the fix in comment #0 :)
Flags: needinfo?(jsantell)
(In reply to Tooru Fujisawa [:arai] from comment #1)
> can legacy generator be passed to isGenerator function?
> if yes and they're all in-tree things, we should fix it too.
> if yes and they can be user input or something, we should fix everything at
> once when dropping legacy generator support.
> if no, we can just apply one of the fix in comment #0 :)

We can ignore legacy generators, but must handler generators from other globals. r=me on the second implementation in comment 0. Thanks!
Flags: needinfo?(jsantell)
https://hg.mozilla.org/integration/mozilla-inbound/rev/bda42988725cb4ed31f56abc9ff7717d91adf64a
Bug 1219028 - Remove use of non-standard Function.prototype.isGenerator from devtools/. r=fitzgen
https://hg.mozilla.org/mozilla-central/rev/bda42988725c
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 44
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.