15.5.5.2 string.[[GetOwnProperty]](P)

2010-07-11

PD|undefined|mixed string.[[GetOwnProperty]](P:arrayIndex|mixed)

The special method is only used to access individual characters of the string directly.

In fact, if P is not an array index, or an existing property on this string, undefined will be returned.

From 15.4: A property P is an "array index" if and only if ToString(ToUInt32(P)) === P and ToUInt32(P) is not equal to (2^32)-1 (because that denotes NaN). In other words, any 32bit unsigned integer (except for one) can be a valid array index, when converted to string.

Code: (Meta Ecma)
string.[[GetOwnProperty]] = function(P){
var desc = S.[[GetOwnProperty]](S, P); // the original from 8.12.1
if (desc !== undefined) return desc;
if (ToString(ToUInt32(P)) !== P || ToUInt32(P) == Math.pow(2,32)-1) return undefined; // "if not array index"
var str = S.[[PrimitiveValue]];
var index = ToUint32(P);
var len = str.length;
if (len <= index) return undefined;
var resultStr = str[index];
return PD{[[Value]]:resultStr, [[Enumerable]]:true, [[Writable]]:false, [[Configurable]]:false};
}