David Bruant (2013-10-31T15:50:40.000Z)
Le 31/10/2013 16:38, Anne van Kesteren a écrit :
> This keeps coming up. Last instance:
> http://mxr.mozilla.org/mozilla-central/source/dom/base/ObjectWrapper.jsm#16
>
> We have it for Array using Array.isArray().
Array.isArray is not at all equivalent to instanceof. Not even related.
     Object.create(Array.prototype) instanceof Array === true

     var a = [];
     a.__proto__ = null;
     Array.isArray(a) === true;

We need both types of checks, one for "is such object in the prototype 
chain?" and the other for "how is this object magic?" (Array, Date, 
WeakMap, File, whatev's). The source code you're linking to seems to 
want the latter.

> It is unclear why the
> arguments for arrays not apply to other types of objects, such as
> array buffers, nodes, blobs, files, etc.
>
> We could introduce something like
>
>    Object.crossGlobalInstanceOf(instance, type)
>
> which checks @@crossGlobalBrand or some such which works for built-ins
> and is also usable by jQuery and the like.
I'm not sure it's worth making it work for jQuery. This is trying to 
make a good use of same-origin multi-global which shouldn't exist in the 
first place. Keeping same-origin access as it is and encouraging people 
to add @sandbox even on same-origin iframes seems like a better idea.

Should the addition be a nicer Object.prototype.toString.call?

David
domenic at domenicdenicola.com (2013-11-12T18:47:06.503Z)
Le 31/10/2013 16:38, Anne van Kesteren a écrit :
> This keeps coming up. Last instance:
> http://mxr.mozilla.org/mozilla-central/source/dom/base/ObjectWrapper.jsm#16
>
> We have it for `Array` using `Array.isArray()`.

`Array.isArray` is not at all equivalent to instanceof. Not even related.

```js
Object.create(Array.prototype) instanceof Array === true

var a = [];
a.__proto__ = null;
Array.isArray(a) === true;
```

We need both types of checks, one for "is such object in the prototype 
chain?" and the other for "how is this object magic?" (Array, Date, 
WeakMap, File, whatev's). The source code you're linking to seems to 
want the latter.

> It is unclear why the
> arguments for arrays not apply to other types of objects, such as
> array buffers, nodes, blobs, files, etc.
>
> We could introduce something like
>
>     Object.crossGlobalInstanceOf(instance, type)
>
> which checks @@crossGlobalBrand or some such which works for built-ins
> and is also usable by jQuery and the like.

I'm not sure it's worth making it work for jQuery. This is trying to 
make a good use of same-origin multi-global which shouldn't exist in the 
first place. Keeping same-origin access as it is and encouraging people 
to add @sandbox even on same-origin iframes seems like a better idea.

Should the addition be a nicer `Object.prototype.toString.call`?