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(webkit): do not swallow errors when returning by value #2723

Merged
merged 1 commit into from
Jun 26, 2020
Merged

fix(webkit): do not swallow errors when returning by value #2723

merged 1 commit into from
Jun 26, 2020

Conversation

dgozman
Copy link
Contributor

@dgozman dgozman commented Jun 26, 2020

We currently return undefined whenever we had an error trying
return the evaluation result by error. The most common error
is "execution context destroyed".

This produces very unexpected undefined from methods that do not
ever expect undefined. Instead, we should throw because we were
not able to return the result.

We currently return undefined whenever we had an error trying
return the evaluation result by error. The most common error
is "execution context destroyed".

This produces very unexpected undefined from methods that do not
ever expect undefined. Instead, we should throw because we were
not able to return the result.
@@ -228,6 +228,10 @@ describe('Page.evaluate', function() {
it('should properly serialize undefined fields', async({page}) => {
expect(await page.evaluate(() => ({a: undefined}))).toEqual({});
});
it('should return undefined properties', async({page}) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a test for the case where it previously would return undefined and now throws?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a test for that called 'should not throw an error when evaluation does a synchronous navigation and returns undefined'. It's racy, so run with repeat(1000).

@@ -98,13 +102,10 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
returnByValue: true
});
if (serializeResponse.wasThrown)
return undefined;
throw new Error('Evaluation failed: ' + serializeResponse.result.description);
Copy link
Member

Choose a reason for hiding this comment

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

This will likely break some of the code where no exception is currently expected. My understanding was that the current contract of returning undefined instead of throwing was intentional since ling ago. I personally agree that it's not good to silently swallow errors but Lusha/Joel might remember if there was a specific request for that behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This current behavior is webkit-specific. It has to do with returnByValue being a separate step from the evaluate itself, due to special promise handling.

@dgozman dgozman merged commit 064a0a1 into microsoft:master Jun 26, 2020
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.

2 participants