-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
fix(page.evaluate): better function serialization #3480
fix(page.evaluate): better function serialization #3480
Conversation
lib/ExecutionContext.js
Outdated
} catch (e1) { | ||
// This means we have a function shorthand. Try another | ||
// time prefixing 'function '. | ||
functionText = 'function ' + functionText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about async static generators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async done; the rest is too exotic for now!
lib/ExecutionContext.js
Outdated
@@ -94,8 +94,23 @@ class ExecutionContext { | |||
if (typeof pageFunction !== 'function') | |||
throw new Error('The following is not a function: ' + pageFunction); | |||
|
|||
let functionText = pageFunction.toString(); | |||
try { | |||
eval(functionText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be worried about unintended side effects here. Consider: function functionText(){return 5}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch; switched to new Function
instead
Can we also add a note about |
lib/ExecutionContext.js
Outdated
try { | ||
new Function('(' + functionText + ')'); | ||
} catch (e1) { | ||
// This means we have a function shorthand. Try another |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This means we have a function shorthand. Try another | |
// This means we might have a function shorthand. Try another |
References #1665