@@toStringTag spoofing for null and undefined

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Jan 28 17:16:39 PST 2015

On Jan 28, 2015, at 5:03 PM, John-David Dalton <john.david.dalton at gmail.com> wrote:

> Primary issue is in  isTypedArray(a):
> Uin32Array.prototype.buffer.call(a);
> Besides the typos, accessing .buffer throws in at least Chrome & Firefox.
> Then .buffer is an object so if it doesn't throw there's no .call to execute.

 the ES6 definition of %TypedArray%.prototype.buffer:

%TypedArray%.prototype.buffer is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

1.     Let O be the this value.
2.     If Type(O) is not Object, throw a TypeError exception.
3.     If O does not have a [[ViewedArrayBuffer]] internal slot throw a TypeError exception.
4.     Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
5.     Return buffer.

ES6 expects buffer to be implemented as an accessor property.  That means that the probe in my test should be:
Object.getOwnProperty(Uint32Array.prototype.__proto__, ‘buffer’).get.call(a);

> -JDD
> On Wed, Jan 28, 2015 at 4:55 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> On Jan 28, 2015, at 4:40 PM, John-David Dalton <john.david.dalton at gmail.com> wrote:
>> Kind of a bummer. The isTypedArray example from  https://esdiscuss.org/topic/tostringtag-spoofing-for-null-and-undefined#content-59 is incorrect. Is there an updated reference somewhere?
>> The toStringTag result is handy because it allows checking against several tags at once without having to invoke multiple functions each with their own try-catch and all that perf baggage.
> How is it incorrect?  Are you referring to the fact that both typed arrays and DataView objects have a [[ViewedArrayBuffer]] internal slot.  If so, I think this is a specification but that I should fix.
> Allen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150128/198f9603/attachment.html>

More information about the es-discuss mailing list