prototype for operator proposal for review

Jeff Walden jwalden+es at MIT.EDU
Tue May 17 22:27:26 PDT 2011

On 05/17/2011 09:49 PM, Luke Hoban wrote:
> It seems the syntax is perhaps aiming to avoid needing to allocate an intermediate object – but I imagine engines could potentially do that for Object.make and friends as well if it was important for performance?

It's probably possible to do that.  But such hacks are rather fragile.  I suspect this would take roughly the form of the way SpiderMonkey optimizes Function.prototype.apply, which is roughly to look for calls of properties named "apply" and do special-case behavior with a PIC in the case that that property is actually |Function.prototype.apply|.  It takes some pretty gnarly code, duplicated two places (possibly a third, but that might not be necessary), to make it all happen.  That sort of pattern certainly can be repeated if push comes to shove.  But I believe doing so is far inferior to dedicated, first-class syntactical support to make the semantics absolutely unambiguous and un-confusable with anything else.

In this particular case, I suspect implementing a PIC that way would be even gnarlier, because it wouldn't just be a PIC on the identity of the |Object.make| property, it'd have to also apply to computation of the arguments provided in the function "call" (or a not-call if you're using a PIC this way).  That too can probably be done.  But it'd be pretty tricky (thinking of things like the PIC only being applicable if the argument is an object literal, and of it being mostly inapplicable if it's anything else).  And if you wanted to extend that to apply to more functions than just a single Object.make function, the hacks will be even more complex, possibly not even by a constant increment.

And of course this would also make it harder for IDEs and such to give good first-class syntax highlighting here, because the syntax for this would be ambiguous with user-created stuff.

Anyway, food for thought.  And I know others here are more familiar with this than I am, so please chime in with more if you have it, or corrections if you have them.


More information about the es-discuss mailing list