Must built-in prototypes also be valid instances? (Was: Why DataView.prototype object's [[Class]] is "Object"?)

Mark S. Miller erights at google.com
Tue Oct 2 14:46:44 PDT 2012


On Tue, Oct 2, 2012 at 11:01 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On Oct 2, 2012, at 10:18 AM, Kevin Smith wrote:
>
>
> private @FooBrand;
>> class Foo {
>>    constructor() {
>>         /* establish the internal Fooness of the instance */
>>         this. at FooBrand = true;
>>    }
>> }
>> Foo.isFoo = function (obj) {return !!obj. at FooBrand};
>>
>
> Using this strategy, will isFoo not fail, if the specified object came
> from a different global context (frame)?
>
> Kevin
>
>
> Indeed it would, but why shouldn't it?  Foo in another  frame is a
> different class.  If you need to do cross-frame brand, that seems like an
> additional requirement would require additional mechanism.
>
> Wouldn't a WeakMap branding scheme has similar issues. You would need to
> share via some means a common WeakMap among constructors in different
> frames.  Just like to make symbol based branding work for this requirement
> you would have to share a private symbol between frames.
>
> For classes, I agree it should fail cross frame -- they are different
classes. But what about builtins? Note that ES5 [[Class]] is a cross-frame
brand for builtins. And Array.isArray is an ad-hoc one-off cross-frame
brand check.




> Allen
>
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121002/a62cdc53/attachment.html>


More information about the es-discuss mailing list