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 str-to-func eval of named function factory #17296

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,11 @@ var LibraryEmbind = {
$createNamedFunction__deps: ['$makeLegalFunctionName'],
$createNamedFunction: function(name, body) {
name = makeLegalFunctionName(name);
#if DYNAMIC_EXECUTION == 0
return function() {
"use strict";
return body.apply(this, arguments);
};
#else
/*jshint evil:true*/
return new Function(
"body",
"return function " + name + "() {\n" +
" \"use strict\";" +
" return body.apply(this, arguments);\n" +
"};\n"
)(body);
#endif
return {
[name]: function () {
return body.apply(body, arguments);
Copy link

@LiuWilson00 LiuWilson00 Feb 13, 2023

Choose a reason for hiding this comment

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

Hello, your pull request is very helpful for me.
but I don't understand why use "body.apply(body, arguments);" in here rather than "body.apply(this, arguments);".
In my case , I change createNamedFunction used "body.apply(body, arguments)" had some error.
but "body.apply(this, arguments)" is work for me.

anyway, thank you so much again,you save me to solu the CSP trouble!!

}
}[name];
},

embind_repr: function(v) {
Expand Down