@@toStringTag spoofing for null and undefined

Caitlin Potter caitpotter88 at gmail.com
Mon Feb 9 21:03:41 PST 2015


> String.prototype is a String object (with string value ""), Function.prototype is a function, etc. If you try on ES5
> browsers you will get the same result. See the spec for the reason.

According to the most recent draft

> 21.1.2.3 String.prototype
>
> The initial value of String.prototype is the intrinsic object %StringPrototype% (21.1.3).
>
> This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
>
> 21.1.3 Properties of the String Prototype Object
> The String prototype object is itself an ordinary object. It is not a String instance and does not have a
> [[StringData]] internal slot.

“It is not a String instance and does not have a [[StringData]] internal slot.” is essentially saying that it is n’either a string primitive value, or a String wrapper object. Whether it reflects implementation reality or not is sort of besides the point at this stage.

I believe making String non-exotic has been discussed, and if this has changed from ES5, it could be related to that.

> On Feb 9, 2015, at 11:53 PM, Gary Guo <nbdd0121 at hotmail.com> wrote:
> 
> String.prototype is a String object (with string value ""), Function.prototype is a function, etc. If you try on ES5 browsers you will get the same result. See the spec for the reason.
> 
> Subject: Re: @@toStringTag spoofing for null and undefined
> From: claude.pache at gmail.com
> Date: Mon, 9 Feb 2015 16:43:23 +0100
> CC: allen at wirfs-brock.com; es-discuss at mozilla.org
> To: nbdd0121 at hotmail.com
> 
> 
> Le 9 févr. 2015 à 16:15, Gary Guo <nbdd0121 at hotmail.com> a écrit :
> 
> I propose addition of String.prototype[@@toStringTag] as well as abridgement of Object.prototype.toString. 
> 
> The issue with that approach, is that `O.p.toString.call(String.prototype)` will return "[object String]", but, for ES6, `String.prototype` is not a String object, leading to a false positive that could break legacy code. (Don't know whether it is a problem in practice.)
> 
> ―Claude
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list