jasnell / proposal-istypes

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

support for built-in functions/methods #25

Closed jasnell closed 7 years ago

jasnell commented 7 years ago

@ljharb @bengl: Should built-in functions and methods also be supported by this? For instance,

Builtin.is(parseInt, vm.runInNewContext('parseInt'));

Builtin.is(Object.toString, vm.runInNewContext('Object.toString'));

This can be accomplished by requiring that such built-in functions be given a [[Builtin]] internal slot and a @@builtin own property of their own.

Note that passing the builtin function and method to Builtin.typeof() (e.g. Builtin.typeof(parseInt)) would still just return 'function'.

doodadjs commented 7 years ago

For natives (built-ins), will there still be a way to distinguish between a constructor and a function ?

jasnell commented 7 years ago

@doodadjs ... just so I'm clear, are you referring to the difference between new Foo() and Foo() ?

doodadjs commented 7 years ago

Between "new Object()" and Object.hasOwnProperty()

ljharb commented 7 years ago

"is constructor" is a very different type of check than this proposal provides; and you can kind of do that now with something like function hasConstructSlot(x) try { new Proxy(x, { construct() {} }); return true; } catch (e) { return false; } }.

doodadjs commented 7 years ago

I'm talking about natives. But ok.

jasnell commented 7 years ago

@doodadjs ok... yeah I get where you're going, but as @ljharb points out that's a very different kind of check. I do think it would be valuable for a function to indicate via a property if it's a constructor or not, but I'd prefer to handle that separately.

jasnell commented 7 years ago

@ljharb ... the original question still stands here... should Builtin.is() work for builtin functions and methods also?

ljharb commented 7 years ago

Yes, I think so.