[whatwg/storage] Question: Expected behavior for Object.keys with storage objects (Issue #140)

A question has come up around what the behavior (per relevant specifications) of `Object.keys` should be when it is passed `window.localStorage` or `window.sessionStorage`. Should it return an array of the key names (as all popular browser currently do), should it return an empty array, or does the specification leave it up to the browsers to decide? As you may be aware, this is a very popular technique for iterating through storage keys.

It seems to me the question is whether or not storage objects should be/are enumerable.

ECMA 262 states:

> 20.1.2.18 Object.keys ( O )
> When the keys function is called with argument O, the following steps are taken:

> 1. Let obj be ? [ToObject](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toobject)(O).
> 2. Let nameList be ? [EnumerableOwnPropertyNames](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-enumerableownpropertynames)(obj, key).
> 3. Return [CreateArrayFromList](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-createarrayfromlist)(nameList).

https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.keys

The `Storage` interface spec [says](https://html.spec.whatwg.org/multipage/webstorage.html#the-storage-interface) there is an associated [storage proxy map](https://storage.spec.whatwg.org/#storage-proxy-map), which to my understanding is still just a map. It is not clear to me if these maps are techinically enumerable.

> A [Storage](https://html.spec.whatwg.org/multipage/webstorage.html#storage-2) object has an associated:
> map
> A [storage proxy map](https://storage.spec.whatwg.org/#storage-proxy-map).

> A storage proxy [map](https://infra.spec.whatwg.org/#ordered-map) is equivalent to a map, except that all operations are instead performed on its backing map.

**Question**: If a browser is strictly following the specifications above, should `Storage` objects be treated as enumerable, and thus have `Object.keys(localStorage/sessionStorage)` return an array of keys? Or, per the specifications, are `Storage` objects not technically enumerable, and thus `Object.keys` return an empty array?

Hope that makes sense, thanks!



-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/storage/issues/140
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/storage/issues/140@github.com>

Received on Tuesday, 22 March 2022 18:50:29 UTC