-
Notifications
You must be signed in to change notification settings - Fork 9k
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
feat(executioncontext): warn on nested js handle #3591
Merged
aslushnikov
merged 6 commits into
puppeteer:master
from
bgschiller:warn-on-nested-js-handle
Jan 14, 2019
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0fe9b8
feat(ExecutionContext): warn on nested js handle
bgschiller 778339d
feat(ExecutionContext): warn about nested JSHandle
bgschiller 488eab3
only warn on TypeError
bgschiller c30683a
feat(ExecutionContext): warn on nested js handle
bgschiller c6c4d9c
remove trailing comma for node6
bgschiller 89da3ad
nit: naming
aslushnikov File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,15 +111,22 @@ class ExecutionContext { | |
throw new Error('Passed function is not well-serializable!'); | ||
} | ||
} | ||
|
||
const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.callFunctionOn', { | ||
functionDeclaration: functionText + '\n' + suffix + '\n', | ||
executionContextId: this._contextId, | ||
arguments: args.map(convertArgument.bind(this)), | ||
returnByValue: false, | ||
awaitPromise: true, | ||
userGesture: true | ||
}).catch(rewriteError); | ||
let funcCallResultP; | ||
try { | ||
funcCallResultP = this._client.send('Runtime.callFunctionOn', { | ||
functionDeclaration: functionText + '\n' + suffix + '\n', | ||
executionContextId: this._contextId, | ||
arguments: args.map(convertArgument.bind(this)), | ||
returnByValue: false, | ||
awaitPromise: true, | ||
userGesture: true | ||
}); | ||
} catch (err) { | ||
if (err instanceof TypeError && err.message === 'Converting circular structure to JSON') | ||
err.message += ' Are you passing a nested JSHandle?'; | ||
throw err; | ||
} | ||
const { exceptionDetails, result: remoteObject } = await funcCallResultP.catch(rewriteError); | ||
if (exceptionDetails) | ||
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails)); | ||
return createJSHandle(this, remoteObject); | ||
|
@@ -162,6 +169,7 @@ class ExecutionContext { | |
throw new Error('Execution context was destroyed, most likely because of a navigation.'); | ||
throw error; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: stray line |
||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 error happens due to
convertArgument
call. Let's scope it down to this: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.
Unfortunately, the error actually happens after convertArgument, in
CDPSession.send
. It looks like convertArgument prepares the args for serialization, but the call to JSON.stringify is later on.