Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util.inspect shouldn’t format objects with the [[IsHTMLDDA]] internal slot as undefined #31889

Closed
ExE-Boss opened this issue Feb 20, 2020 · 2 comments
Labels
util Issues and PRs related to the built-in util module. v8 engine Issues and PRs related to the V8 dependency.

Comments

@ExE-Boss
Copy link
Contributor

  • Version: v13.9.0
  • Platform: Windows 10 v1903 build 18362.657 64‑bit
  • Subsystem: util

What steps will reproduce the bug?

Run node --allow-natives-syntax -p 'util.inspect(%GetUndetectable())'

What is the expected behavior?

> node --allow-natives-syntax -p 'util.inspect(%GetUndetectable())'
[Function (anonymous)]

What do you see instead?

> node --allow-natives-syntax -p 'util.inspect(%GetUndetectable())'
undefined

Additional information

This is because the type check in util.inspect doesn’t account for objects with the [[IsHTMLDDA]] internal slot:

function formatValue(ctx, value, recurseTimes, typedArray) {
// Primitive types cannot have properties.
if (typeof value !== 'object' && typeof value !== 'function') {
return formatPrimitive(ctx.stylize, value, ctx);
}
if (value === null) {
return ctx.stylize('null', 'null');
}

@devsnek
Copy link
Member

devsnek commented Feb 20, 2020

I suppose this would matter when using electron, since you could actually do util.inspect(document.all). I can add an upstream Object::IsUndetectable and we could check it here.

We could also hack this in as typeof v === 'undefined' && v !== undefined.

@devsnek devsnek added util Issues and PRs related to the built-in util module. v8 engine Issues and PRs related to the V8 dependency. labels Feb 20, 2020
@ExE-Boss
Copy link
Contributor Author

ExE-Boss commented Feb 21, 2020

One solution would be to add util.types.isObject(target), which would perform:

  1. If Type(target) is Object, then return true.
  2. Return false.

That would take care of that check, as C++ code doesn’t care whether an object is undetectable, since you can pass document.all as the this value to both Function.prototype.toString, Object.prototype.toString and Object.prototype.valueOf.


A polyfilled version is:

function isObject(target) {
	if (target === null || target === undefied) return false;
	switch (typeof target) {
		case "object":
		case "function":
			return true;
		case "undefined":
			try {
				return Object.prototype.valueOf.call(target) === target;
			} catch {}
	}
	return false;
}

devsnek added a commit to devsnek/node that referenced this issue Feb 26, 2020
devsnek added a commit to devsnek/node that referenced this issue Mar 10, 2020
addaleax pushed a commit that referenced this issue Mar 30, 2020
Fixes: #31889

PR-URL: #31938
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
targos pushed a commit that referenced this issue Apr 22, 2020
Fixes: #31889

PR-URL: #31938
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

2 participants