archives

« Bugzilla Issues Index

#3392 — toMethod should create a function without a prototype property


Since methods do not have a prototype property, Function.prototype.toMethod should also create a function without a prototype property.

function f() {}
assert(f.hasOwnProperty('prototype'));
var g = f.toMethod({});
assert(!g.hasOwnProperty('prototype'));

It is not clear to me if the spec is handling this or not?


(In reply to Erik Arvidsson from comment #0)
> It is not clear to me if the spec is handling this or not?

Steps 4-6 in 9.2.12 CloneMethod cover this case. Only internal methods and internal slots are copied over, including non-standard internal slots (bug 2012). "copied over" is possibly the wrong choice of words, because the internal slot values are not copied as in "a new copy of the value is created", but instead the value of each internal slot is set to the value of the corresponding internal slot of the original object.

The note after 9.2.12 explains this, too (The part about "restricted function properties" still needs to be removed - bug 3345). Unfortunately that note is on the next page in the pdf version, so it's easy to miss.


(In reply to André Bargull from comment #1)
> (In reply to Erik Arvidsson from comment #0)
> > It is not clear to me if the spec is handling this or not?
>
> Steps 4-6 in 9.2.12 CloneMethod cover this case. Only internal methods and
> internal slots are copied over, including non-standard internal slots (bug
> 2012). "copied over" is possibly the wrong choice of words, because the
> internal slot values are not copied as in "a new copy of the value is
> created", but instead the value of each internal slot is set to the value of
> the corresponding internal slot of the original object.
>
> The note after 9.2.12 explains this, too (The part about "restricted
> function properties" still needs to be removed - bug 3345). Unfortunately
> that note is on the next page in the pdf version, so it's easy to miss.

However, this means that if the function has a [[Construct]] internal method it will now use Object.prototype as the prototype for new instances.

I guess the moral of the story is that you really need to code something like:
var g = Object.mixin(f.toMethod(obj), f);

Except we don't have Object.mixin any more!


moved to deferred features because toMethod has been deferred