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

function's object name property and class names #44

Open
ewnjtgouierg opened this issue Feb 6, 2022 · 2 comments
Open

function's object name property and class names #44

ewnjtgouierg opened this issue Feb 6, 2022 · 2 comments

Comments

@ewnjtgouierg
Copy link

ewnjtgouierg commented Feb 6, 2022

Hello!

At the moment:

FF ignores 'name'

V8 respects 'name' BUT it is used differently in trace produced by:
	
	1) console.trace
	2) throw "Test"

		AND

	3) (new Error).stack
	4) <any code that results in uncaught error>

(1) and (2) simply present name's value as is
(3) and (4) prepend it with a class name if there's such

I belive this should be standardised (if someone could point me to the part of the proposal that deals with it - thanks in advance, I'm not good with them yet & simple text search for "class" in current specification yields 0 results)

While the current inconsistency makes getting always sensible stack trace for ES6 and framework-based OOP code impossible, I'm more concerned that the practice of prepending configurable "name" property with class name can become a standard.

As I understand, "name" was made configurable to let developers get meaningful stack traces for whatever OOP framework they use. Then (correct me if there're other use cases), the fact the "name" is used means developer takes full responsibility of how function name is represented in stack trace, it's not a browser's concern any more, so it must not prepend it with anything or process it in any other way.

In frameworks that have concept of extending a class, the factual constructor name is a generic "pre-constructor" function, hence factual full method names are similar to constructor.doThis and constructor.doThat ("constructor" instead of the real class name)

"name" allows framework to prefix method names with real class names, i.e. "ClassName.doThis", but trace (3) and (4) display it as "constructor.ClassName.doThis"

There's also a problem of static methods allowed by ES6.
V8 currently prepends them with "Function."
Obviously there should be a class name instead, but I cannot think of a representation that would satisfy everyone: both static and dynamic methods are called with . operator - how to clearly show which one it is?
Configurable "name" lets everyone choose whatever makes sense to them, i.e. show static one as A:a (vs. A.a) etc.

I am not sure though, if it's possible to say whether the configurable property has been modified or not.

If no, a simple solution would be to consider it modified if it is not a valid function name (this covers A.a and similar representations), though it feels hackish so I'm not sure browsers would want to implement it.

@ljharb
Copy link
Member

ljharb commented Feb 6, 2022

This proposal can’t force any changes on engines - in other words, we’re constrained to specify what they already do.

If there’s a single engine’s behavior that you think should be changed, then that engine needs to be convinced to change it.

@ewnjtgouierg
Copy link
Author

thank you! Sorry, new to this

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

No branches or pull requests

2 participants