Alexandre Morgaut (2014-06-11T15:40:26.000Z)
domenic at domenicdenicola.com (2014-06-20T19:24:12.888Z)
On 11 juin 2014, at 17:11, André Bargull <andre.bargull at udo.edu> wrote: > The Proxy-based solution needs to be used in these cases. Now we just need to wait until Proxies are available everywhere! ;-) Not sure Proxy solve anything when we want to test the constructor nature of a function and be sure invoking it won't change anything in the current application context To highlight what side-effects mentioned by Rick could be, a tested function while invoked may: - do DOM Manipulations, - change properties in the global object, - initiate Web Sockets or Web Workers... Not safe at all... Testing the prototype is also one thing, but constructors can have no prototype properties or methods but only own properties defined at the instance level (potentially with getters / setters) As created dynamically, such own properties are hard if not impossible to detect without executing the constructor The only safe way I would see, for functions written in JS, would be to use a lexer on the source of the function provided by Function.prototype.toString.call(C) But it would still not be 100% perfect and should probably throw an exception or return a error in some situations in which "this" manipulation may not be detectable. ex: the function code evaluate a dynamic strings (that can not be parsed by a lexer) via eval(), setTimeout()/ setInterval(), or new Function()