-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
vm: never abort on caught syntax error #17394
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
'use strict'; | ||
|
||
const { | ||
ContextifyScript: Script, | ||
ContextifyScript, | ||
kParsingContext, | ||
|
||
makeContext, | ||
|
@@ -39,6 +39,19 @@ const { | |
// - isContext(sandbox) | ||
// From this we build the entire documented API. | ||
|
||
class Script extends ContextifyScript { | ||
constructor(code, options) { | ||
// Calling `ReThrow()` on a native TryCatch does not generate a new | ||
// abort-on-uncaught-exception check. A dummy try/catch in JS land | ||
// protects against that. | ||
try { | ||
super(code, options); | ||
} catch (e) { | ||
throw e; /* node-do-not-add-exception-line */ | ||
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. Any idea for how to avoid this? Or: Is this even actually a bad thing? 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. Why would it be a bad thing? 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. I am not sure - it seems like something that people might find out, start to use, and be unhappy when they find out we changed/removed/etc. it 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. I'm not sure what "it" refers to. The line in the (decorated) stack trace? What info could they glean from that? 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. No, sorry, I should have been clearer - I was talking about the 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. Hah, okay. I read your question as "is it a bad thing for the throw to show up." I wouldn't say so, and yes, I'd say it's only a matter of time before people find out about the magic comment. :-) If you want to exclude stack frames, you can filter based on the script id. Probably overkill for this, though. |
||
} | ||
} | ||
} | ||
|
||
const realRunInThisContext = Script.prototype.runInThisContext; | ||
const realRunInContext = Script.prototype.runInContext; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Flags: --abort-on-uncaught-exception | ||
'use strict'; | ||
require('../common'); | ||
const vm = require('vm'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/13258 | ||
|
||
try { | ||
new vm.Script({ toString() { throw new Error('foo'); } }, {}); | ||
} catch (err) {} | ||
|
||
try { | ||
new vm.Script('[', {}); | ||
} catch (err) {} |
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.
@nodejs/v8 Is this a bug in V8?
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.
Yeah a ReThrow is not actually a new throw. It just "re-activates" the exception.
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.
@hashseed Does that mean one could get the right behavior by exiting the
TryCatch
scope, then usingisolate->ThrowException()
?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.
Yeah. Though the message you get with this kind of "rethrow" will show the stack trace of the new throw location.