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

fix(page.evaluate): better function serialization #3480

Merged
merged 7 commits into from Nov 1, 2018

Conversation

aslushnikov
Copy link
Contributor

@aslushnikov aslushnikov commented Nov 1, 2018

References #1665

} catch (e1) {
// This means we have a function shorthand. Try another
// time prefixing 'function '.
functionText = 'function ' + functionText;
Copy link
Collaborator

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?

Copy link
Contributor Author

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!

@@ -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);
Copy link
Collaborator

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}.

Copy link
Contributor Author

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

@JoelEinbinder
Copy link
Collaborator

JoelEinbinder commented Nov 1, 2018

Can we also add a note about toStringing the pageFunctions? This has come up many times before.

try {
new Function('(' + functionText + ')');
} catch (e1) {
// This means we have a function shorthand. Try another
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// This means we have a function shorthand. Try another
// This means we might have a function shorthand. Try another

@aslushnikov aslushnikov merged commit 3596c5f into puppeteer:master Nov 1, 2018
@aslushnikov aslushnikov deleted the better-serialization branch November 2, 2018 19:44
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