-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Move re-throw of exception out of catch #5497
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
Move re-throw of exception out of catch #5497
Conversation
| } \ | ||
| catch (const JavascriptException& err) \ | ||
| { \ | ||
| JavascriptExceptionObject* exceptionObject = err.GetAndClear(); \ |
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.
It still seem wrong though to not propagate the stack overflow in this case. The rest of the change looks fine. #Closed
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.
maybe we should propagate instead of swallow, exceptions other than the script exceptions we explicitly swallow. #Resolved
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.
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.
per http://es-discourse.com/t/why-typeof-is-no-longer-safe/15 it seems that the general expectation for "typeof" to not throw so I'm going to keep it as is (I couldn't find it in the spec though)
In reply to: 204187371 [](ancestors = 204187371)
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.
From my reading of the spec, I think that we should throw. The spec says that first you evaluate the expression, then you set val to ? GetValue(val). GetValue checks if val is an "abrupt completion", which includes a throw, and returns it if so, and the ? expression syntax means that you should do the same; if the expression returns an abrupt completion, then return that abrupt completion.
If I've parsed that out right, then typeof(expressionThatThrows) should have the exception propagate.
@zenparsing does that sound correct? #Resolved
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.
If typeof operator isn't supposed to be safe, why do we have BEGIN_TYPEOF_ERROR_HANDLER and END_TYPEOF_ERROR_HANDLER macros at all? Are there any exceptions that must be swallowed?
In reply to: 204924632 [](ancestors = 204924632)
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.
It looks to me like some reference errors (or more specifically, some circumstances which would result in a reference error) should be swallowed. There is some subtlety, since if x has not been declared or assigned to, then typeof(x) should return undefined, but typeof((() => x)()) should throw ReferenceError: x is not defined #Resolved
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.
Jimmy, could you please take a look at the tests I've added for typeof? Anything missing? Currently only the test for throwing getter is failing.
In reply to: 205165507 [](ancestors = 205165507)
| CONTEXT ep##c; \ | ||
| EXCEPTION_POINTERS ep = {&ep##er, &ep##c}; | ||
|
|
||
| // Re-frow from catch unwinds the active frame but doesn't clear the stack |
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.
Small typo here #Closed
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.
| #endif | ||
|
|
||
| #define BEGIN_TYPEOF_ERROR_HANDLER(scriptContext) \ | ||
| JavascriptExceptionObject* exceptionObject = nullptr; \ |
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.
Perhaps add another block here to scope the exceptionObject to these macros? I think you'd just need a { here, and a } in END_TYPEOF_ERROR_HANDLER #Closed
c510f65 to
1263bc2
Compare
1263bc2 to
34cc65d
Compare
test/Basics/typeof.js
Outdated
| WScript.Echo("typeof function : " + typeof (f)); | ||
| WScript.Echo("typeof function returning function : " + typeof (f())); | ||
| function test_let() { var res = typeof x; let x = 42; return res; } | ||
| assert.throws(test_let, ReferenceError, "typeof of 'let' variable in its dead zone", "Use before declaration"); |
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.
Perhaps also add a case for typeof x.y when x is undefined #Closed
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.
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.
Yes, it should throw. #Closed
34cc65d to
5413f08
Compare
|
@LouisLaf @rajatd @MSLaguana -- I believe I've finally arrived to the correct exception handling behaviour for typeof. Could you please take a look and sign off? |
MSLaguana
left a comment
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.
Looks good to me!
LouisLaf
left a comment
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.
![]()
rajatd
left a comment
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.
![]()
…f catch to avoid OS stack overflow.
5413f08 to
dacef92
Compare
Merge pull request #5497 from irinayat-MS:StackOverflow Fixes OS.18246154 Re-throw from catch doesn't unwind the stack (only resets the active frame pointer) so, if there are nested try/catch blocks that refrow, the stack keeps growing, which is unhelpful if the initial exception is trying to prevent Stack Overflow. To avoid this, move re-throw outside of the catch (so the stack fully unwinds on each handling site). Took the opportunity to add more test coverage for typeof and fix exception handling deviations from the spec (and V8).
…ut of catch Merge pull request #5497 from irinayat-MS:StackOverflow Fixes OS.18246154 Re-throw from catch doesn't unwind the stack (only resets the active frame pointer) so, if there are nested try/catch blocks that refrow, the stack keeps growing, which is unhelpful if the initial exception is trying to prevent Stack Overflow. To avoid this, move re-throw outside of the catch (so the stack fully unwinds on each handling site). Took the opportunity to add more test coverage for typeof and fix exception handling deviations from the spec (and V8).
Fixes OS.18246154
Re-throw from catch doesn't unwind the stack (only resets the active frame pointer) so, if there are nested try/catch blocks that refrow, the stack keeps growing, which is unhelpful if the initial exception is trying to prevent Stack Overflow. To avoid this, move re-throw outside of the catch (so the stack fully unwinds on each handling site).
Took the opportunity to add more test coverage for typeof and fix exception handling deviations from the spec (and V8).