Skip to content

fix: Rewrite inspect(…) to be (probably) side‑effect free#286

Open
ExE-Boss wants to merge 2 commits intoengine262:mainfrom
ExE-Boss:fix/inspect/make-side-effect-free
Open

fix: Rewrite inspect(…) to be (probably) side‑effect free#286
ExE-Boss wants to merge 2 commits intoengine262:mainfrom
ExE-Boss:fix/inspect/make-side-effect-free

Conversation

@ExE-Boss
Copy link
Contributor

This rewrites inspect(…) in a way which avoids calling proxy traps and property accessors.
Other non‑Proxy implementations of the object internal methods [[OwnPropertyKeys]], [[GetOwnProperty]], and [[GetPrototypeOf]] seem to be side‑effect free, as far as I can tell.

In the process of doing this, I consolidated a lot of the code paths so that own properties are shown for all object types, including functions, primitive boxes, Promisees, RegExps, and Arrays.

Partially based on #117.

if (isArrayExoticObject(v)) {
return 'Array';
}
if ('PromiseState' in v) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use helpers like isPromiseObject

if (desc instanceof UndefinedValue) {
const parent = X(O.GetPrototypeOf());
if (parent instanceof NullValue || isProxyExoticObject(parent)) {
return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if parent is null, I think it should return Value.undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This intentionally uses undefined (spec value empty) to disambiguate from a data property with a value of Value.undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understanding this case is accessing x.a where prototype of x is null, in this case, x.a should be undefined (language value), is that correct?

const stylizeNoColor: Stylizer = (text) => text;

function getConstructorName(v: ObjectValue) {
Assert(!isProxyExoticObject(v));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or return undefined for ProxyExoticObject? (same for getNoSideEffects etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments