jasnell / proposal-istypes

TC-39 Proposal for additional is{Type} APIs
201 stars 7 forks source link

Reconciling Spider-Monkey #9

Closed rwaldron closed 7 years ago

rwaldron commented 7 years ago

In Spider-Monkey:

(typeof Function.isGenerator === "function") === true; // Strangely, this doesn't appear to work the way I assumed it would. 

function * g() {}

g.isGenerator() === true;
jasnell commented 7 years ago

Good to know. Will need to track this.

pitaj commented 7 years ago

Just for some more information:

In Gecko, the isGenerator function is a method of the Function prototype. Since Function instanceof Function === true, Function.isGenerator() returns whether the constructor Function is a generator, which always resolves to false.

Since Function.isGenerator(maybeGeneratorFunction) is only available on the Function constructor object as proposed, a polyfill should be able to avoid a false positive on Firefox by using the following check:

if (!Object.hasOwnProperty.call(Function, 'isGenerator') || typeof Function.isGenerator !== 'function') {
  // polyfill `Function.isGenerator`
}

Edit: For clarification, Function.isGenerator is not defined in this proposal.

ljharb commented 7 years ago

This will be true of any methods on Function.prototype - it'd have to be just Function.isGenerator, so that you'd never call foo.isGenerator(), but instead Function.isGenerator(foo).

jasnell commented 7 years ago

Don't believe we need to continue tracking this with the current proposal