Function()
2008/9/6 Garrett Smith <dhtmlkitchen at gmail.com>:
I have a question about the Function constructor algorithm:
- Let P be the empty string.
- If no arguments were given, let body be the empty string and go to step 13.
Would it be OK to just use:-
- If no arguments were given, return a function as specified in 13.2.
The resulting function would be indistinguishable.
The ECMAScript spec only defines programatically distinguishable behaviour. As long as the behaviour is indistinguishable from the spec the underlying behaviour of the engine can be whatever is decided upon by the engine devs.
On Fri, Sep 5, 2008 at 11:12 PM, liorean <liorean at gmail.com> wrote:
2008/9/6 Garrett Smith <dhtmlkitchen at gmail.com>:
I have a question about the Function constructor algorithm:
- Let P be the empty string.
- If no arguments were given, let body be the empty string and go to step 13.
Would it be OK to just use:-
- If no arguments were given, return a function as specified in 13.2.
The resulting function would be indistinguishable.
The ECMAScript spec only defines programatically distinguishable behaviour. As long as the behaviour is indistinguishable from the spec the underlying behaviour of the engine can be whatever is decided upon by the engine devs.
Hmm. Yeah.
The scope property would be the global object, but that would also seem to unobservable for an empty function.
The current wording describes a solution that is less than optimal, and actually describes the step of creating an empty string for this situation. It is verbose about something that would probably otherwise be implemented more efficiently by engine devs.
Garrett
Garrett Smith wrote:
I have a question about the Function constructor algorithm:
- Let P be the empty string.
- If no arguments were given, let body be the empty string and go to step 13.
Would it be OK to just use:- [...]
This is an "as if" description of the algorithm. But I don't see that the case of no arguments is worth optimizing anyway.
On Sat, Sep 6, 2008 at 3:08 PM, David-Sarah Hopwood <david.hopwood at industrial-designers.co.uk> wrote:
Garrett Smith wrote:
I have a question about the Function constructor algorithm:
- Let P be the empty string.
- If no arguments were given, let body be the empty string and go to step 13.
Would it be OK to just use:- [...]
This is an "as if" description of the algorithm. But I don't see that the case of no arguments is worth optimizing anyway.
It would be used for creating a function with no body.
Garrett
On Sat, Sep 6, 2008 at 1:05 AM, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
The resulting function would be indistinguishable. The performance would be potentially faster (no parsing "" to create a Function). Firefox is very slow with Function constructor.
var slow = Function(); var fast = function(){};
Garrett, this post is really baffling. :)
What makes you think the ES3 specification is to blame for the slowness you're seeing? For all I know, our implementation pre-dates the spec. ;-)
If it's a problem that "Firefox is very slow", I heartily encourage you to file a bug at bugzilla.mozilla.org. Patches are always welcome. SpiderMonkey's Function constructor is implemented at: hg.mozilla.org/mozilla-central/file/a5491c33992e/js/src/jsfun.cpp#l1796
I have a question about the Function constructor algorithm:
Would it be OK to just use:-
The resulting function would be indistinguishable. The performance would be potentially faster (no parsing "" to create a Function). Firefox is very slow with Function constructor.
var slow = Function(); var fast = function(){};