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

remove evil new Function in $createNamedFunction #17273

Closed
wants to merge 9 commits into from

Conversation

NickCarducci
Copy link
Contributor

@NickCarducci NickCarducci commented Jun 19, 2022

in favor of immediately identified function key object {[n]:new fn.apply(null,args)}[n]

Copy link
Contributor Author

@NickCarducci NickCarducci left a comment

Choose a reason for hiding this comment

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

apply invokes like call and unlike bind but does accept arguments as an array in one argument.[ The passed] body function should retain its this, and not have new

Copy link
Contributor Author

@NickCarducci NickCarducci left a comment

Choose a reason for hiding this comment

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

';' removed from inside object

var context = {};
for (var prop in body) {
context[prop] = body[prop];
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the same as Object.assign(context, body)?

Is this needed? Why can't we just use this as the context like we do above on line 205?

Can you remove the DYNAMIC_EXECUTION == 0 condition above and just always use this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh now I understand. The following really isn't helpful except to inform you on why I got here.

Even string to function or eval() lovers should be ok without the named function, even, or at least the original... Yes, I'd bet Object.assign(context, body); does that for-loop, abstracted. I would prefer this one, { [name]: function(arguments){return body.apply(this,arguments);}.bind(body)}[name], also may be an abstracted assign (but declared with it), since the factory 'createNamedFunction' names itself for that purpose and I don't know why else the returned function needs to be named before returning (or why it needs to be named dynamically at all, for that matter). The whole point of this exercise is to declare a wrapper for the call {[name]:body.apply(body)}[name], for reasons I'm still unsure of.

Do you know why else the createNamedFunction exists? Your library is versatile but the DYNAMIC_EXECUTION == 0 gets by without it named, so the whole returned object seems ambivalent to the name... Can it be made into a dummy so current commands don't fail for people? Leaving that out from the script seems to be @robertaboukhalil idea, leading us into the evil new Function. Maybe some other environments requires that it be named?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, since it is an if statement, there is no need to worry about it failing without the dummy idea.

maybe is a pointer, still unsure of the purpose of naming, let alone just to return it into a variable
Copy link
Contributor Author

@NickCarducci NickCarducci left a comment

Choose a reason for hiding this comment

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

name declaration before return may be useful for AST or another environment or use case; unsure. nonetheless, it is done

var context = {};
for (var prop in body) {
context[prop] = body[prop];
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh now I understand. The following really isn't helpful except to inform you on why I got here.

Even string to function or eval() lovers should be ok without the named function, even, or at least the original... Yes, I'd bet Object.assign(context, body); does that for-loop, abstracted. I would prefer this one, { [name]: function(arguments){return body.apply(this,arguments);}.bind(body)}[name], also may be an abstracted assign (but declared with it), since the factory 'createNamedFunction' names itself for that purpose and I don't know why else the returned function needs to be named before returning (or why it needs to be named dynamically at all, for that matter). The whole point of this exercise is to declare a wrapper for the call {[name]:body.apply(body)}[name], for reasons I'm still unsure of.

Do you know why else the createNamedFunction exists? Your library is versatile but the DYNAMIC_EXECUTION == 0 gets by without it named, so the whole returned object seems ambivalent to the name... Can it be made into a dummy so current commands don't fail for people? Leaving that out from the script seems to be @robertaboukhalil idea, leading us into the evil new Function. Maybe some other environments requires that it be named?

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Honestly I don't know much about the history of this function, but I imagine it makes debugging and stack tracing way more readable if you have function names that make sense to reader, and not just "anonymous" everywhere.

Anyway, I think this change is looking really good now!

@sbc100
Copy link
Collaborator

sbc100 commented Jun 21, 2022

Thanks for working on this by the way!

@sbc100
Copy link
Collaborator

sbc100 commented Jun 21, 2022

The flake8 errors should be fixed by a merge/rebase with main?

The other errors do look related.

@NickCarducci
Copy link
Contributor Author

Rebase and merge your pull request commits

To rebase and merge pull requests, you must have write permissions in the repository, and the repository must allow rebase merging.

Remove evil js in named function factory #17281

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.

None yet

2 participants