Array methods applied to strings
Allen.Wirfs-Brock at microsoft.com
Mon May 11 14:00:09 PDT 2009
All built-ins are by definition non-strict. The issue regarding whether the array generics throw when encountering non-writable is a specific design point of those functions, not something that is determined by the strict mode.
There was one change that had to be made to all the built-ins to accommodated strict mode changes to the spec. In ES5, method calls do not wrapper the this value if it happens to be a primitive value. However, the method prolog of non-strict functions (10.4.3) do force the wrappering of the this value so there is no observable difference from ES3 for non-strict functions written in ECMAScript. Strict function may have an observable primitive valued this value. Built-ins do not use 10.4.3 as their prolog, hence they are like strict functions in that their this value may be primitive. This is dealt with in the specification by each function that has a sensitivity to the primitiveness of its this value. The specification of such functions explicitly wrapper primitive this values if they need to.
Regarding Array.prototype.pop.call("abc"), line 1 of its algorithm is:
1. Let O be the result of calling ToObject passing the this value as the argument.
>From: Brendan Eich [mailto:brendan at mozilla.org]
>Sent: Monday, May 11, 2009 1:32 PM
>To: David-Sarah Hopwood; Allen Wirfs-Brock
>Cc: es5-discuss at mozilla.org
>Subject: Re: Array methods applied to strings
>On May 11, 2009, at 1:21 PM, Brendan Eich wrote:
>> Good point: strict mode is opt-in, yet natives do not change
>> semantics according to it according to the spec.
>I meant natives in general. Of course, eval, call, and apply do change
>due to caller strictness.
>The mutating Array generics are the case at hand: push, pop, shift,
>unshift, reverse, sort, splice.
>I just noticed that 184.108.40.206, Array.prototype.map, which now uses
>[[DefineOwnProperty]], still has a stray ref to [[ThrowingPut]] in the
>last paragraph before the Note. Similar left-over language seems to
>exist in 11.1.4, Array Initialiser.
More information about the es5-discuss