tc39 / proposal-shadowrealm

ECMAScript Proposal, specs, and reference implementation for Realms
https://tc39.es/proposal-shadowrealm/
1.41k stars 67 forks source link

Require properties of ShadowRealm's global object added by host to be enumerable #394

Closed ByteEater-pl closed 5 months ago

ByteEater-pl commented 5 months ago

The draft spec says:

The host may use this hook to add properties to the ShadowRealm's global object. Those properties must be configurable.

It seems the same sentence should require them to be enumerable.

Otherwise, there seemingly cannot be code which denies all added capabilities to code running later which isn't written for a specific set of hosts. Even if the programmer manages to include almost all existing hosts, read their (hopefully existing and good enough) documentation and sift through what they add, it's not future-proof.

leobalter commented 5 months ago

Assuming you control the ShadowRealm instantiation, there isn't anything preventing you from observing all names, including non enumerable properties, using something like Object.getOwnPropertyDescriptors.

Some setup is expected if you intend to use ShadowRealm in a way to prevent/control access to certain names.

ByteEater-pl commented 5 months ago

OK

mhofman commented 5 months ago

@ByteEater-pl actually makes a good point in the context of #392.

This is not currently an issue because the 262 side creates the global object as a regular object, which means all properties can be enumerated through [[OwnPropertyKeys]]. However that PR wants to change the responsibility of creating the global object to the host, in which case the object could have exotic behavior and implement some properties as "non-own" to get around the object invariants. I will comment on that PR.