Add Reflect.isConstructor and Reflect.isCallable?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Add Reflect.isConstructor and Reflect.isCallable?

Tom Schuster
Hello,

right now there is no way in normal JS code to replicate the IsConstructor check defined in 7.2.4.
IsCallable can be done with "typeof == function". I think this might be useful in some cases and is trivial to implement.

Cheers,
Tom

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Tom Schuster
Is there somebody interested in this? The draft spec is rather simple:
 
Reflect.isCallable (target)

1. If Type(target) is not Object, then throw a TypeError exception.
2. Return the result of calling the abstract operation IsCallable(target).

 Reflect.isConstructor (target)

1. If Type(target) is not Object, then throw a TypeError exception.
2. Return the result of calling the abstract operation IsConstructor(target).

I am not sure about step 1, but it follows the style of Reflect.isExtensible

On Tue, Dec 16, 2014 at 10:05 PM, Tom Schuster <[hidden email]> wrote:
Hello,

right now there is no way in normal JS code to replicate the IsConstructor check defined in 7.2.4.
IsCallable can be done with "typeof == function". I think this might be useful in some cases and is trivial to implement.

Cheers,
Tom

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Jason Orendorff
In reply to this post by Tom Schuster
On Tue, Dec 16, 2014 at 3:05 PM, Tom Schuster <[hidden email]> wrote:
> Hello,
>
> right now there is no way in normal JS code to replicate the IsConstructor
> check defined in 7.2.4.

function isConstructor(obj) {
    var p = new Proxy(obj, {construct() { return p; }});
    try {
        new p;
    } catch (exc) {
        return false;
    }
    return true;
}

This works by exposing the code in 9.5.15 ProxyCreate that's more or
less equivalent to IsConstructor.

-j
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Jason Orendorff
Having said that, I do think Reflect.isCallable and isConstructor
would be a fine addition to ES7. These places where we check if an
internal method exists feel like a sort of secret-handshake part of
the MOP; we should expose them.

Any objections?

Would someone please add it to the agenda for the next meeting?

-j
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Rick Waldron
Done: https://github.com/tc39/agendas/blob/master/2015/01.md

On Fri Dec 19 2014 at 12:26:33 PM Jason Orendorff <[hidden email]> wrote:
Having said that, I do think Reflect.isCallable and isConstructor
would be a fine addition to ES7. These places where we check if an
internal method exists feel like a sort of secret-handshake part of
the MOP; we should expose them.

Any objections?

Would someone please add it to the agenda for the next meeting?

-j
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Tom Schuster
Thank you both.
Looking forward to the feedback.

On Fri, Dec 19, 2014 at 6:55 PM, Rick Waldron <[hidden email]> wrote:
Done: https://github.com/tc39/agendas/blob/master/2015/01.md

On Fri Dec 19 2014 at 12:26:33 PM Jason Orendorff <[hidden email]> wrote:
Having said that, I do think Reflect.isCallable and isConstructor
would be a fine addition to ES7. These places where we check if an
internal method exists feel like a sort of secret-handshake part of
the MOP; we should expose them.

Any objections?

Would someone please add it to the agenda for the next meeting?

-j
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Tom Van Cutsem-3
Adding Reflect.{isCallable, isConstructor} looks reasonable to me. If the spec needs these internally, chances are JS developers will need them at one point. And as you note, typeof === "function" is a common work-around in use today. So +1.

2014-12-21 0:20 GMT+01:00 Tom Schuster <[hidden email]>:
Thank you both.
Looking forward to the feedback.

On Fri, Dec 19, 2014 at 6:55 PM, Rick Waldron <[hidden email]> wrote:
Done: https://github.com/tc39/agendas/blob/master/2015/01.md

On Fri Dec 19 2014 at 12:26:33 PM Jason Orendorff <[hidden email]> wrote:
Having said that, I do think Reflect.isCallable and isConstructor
would be a fine addition to ES7. These places where we check if an
internal method exists feel like a sort of secret-handshake part of
the MOP; we should expose them.

Any objections?

Would someone please add it to the agenda for the next meeting?

-j
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

RE: Add Reflect.isConstructor and Reflect.isCallable?

Gary Guo
If added, it can help ES engines to write more code in ES instead of native languages. So +1 as well.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Add Reflect.isConstructor and Reflect.isCallable?

Tom Schuster
Was this discussed? I can't find any reference to it.

On Mon, Dec 22, 2014 at 1:34 AM, Gary Guo <[hidden email]> wrote:
If added, it can help ES engines to write more code in ES instead of native languages. So +1 as well.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss