Skip to content

Conversation

@IrinaYatsenko
Copy link
Contributor

@IrinaYatsenko IrinaYatsenko commented Jul 20, 2018

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

@IrinaYatsenko IrinaYatsenko requested a review from LouisLaf July 20, 2018 21:20
} \
catch (const JavascriptException& err) \
{ \
JavascriptExceptionObject* exceptionObject = err.GetAndClear(); \
Copy link
Collaborator

@LouisLaf LouisLaf Jul 20, 2018

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

Copy link
Contributor

@rajatd rajatd Jul 20, 2018

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Propagating it now and added a test for it.


In reply to: 204181201 [](ancestors = 204181201)

Copy link
Contributor Author

@IrinaYatsenko IrinaYatsenko Jul 24, 2018

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)

Copy link
Contributor

@MSLaguana MSLaguana Jul 24, 2018

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

Copy link
Contributor Author

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)

Copy link
Contributor

@MSLaguana MSLaguana Jul 25, 2018

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

Copy link
Contributor Author

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
Copy link
Contributor

@MSLaguana MSLaguana Jul 21, 2018

Choose a reason for hiding this comment

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

Small typo here #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes :) thanks!


In reply to: 204220967 [](ancestors = 204220967)

#endif

#define BEGIN_TYPEOF_ERROR_HANDLER(scriptContext) \
JavascriptExceptionObject* exceptionObject = nullptr; \
Copy link
Contributor

@MSLaguana MSLaguana Jul 21, 2018

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

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");
Copy link
Contributor

@MSLaguana MSLaguana Jul 26, 2018

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

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 one throws (in V8 as well) -- expected?


In reply to: 205543506 [](ancestors = 205543506)

Copy link
Contributor

@MSLaguana MSLaguana Jul 26, 2018

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

@IrinaYatsenko
Copy link
Contributor Author

@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?

Copy link
Contributor

@MSLaguana MSLaguana left a 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!

Copy link
Collaborator

@LouisLaf LouisLaf left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@rajatd rajatd left a comment

Choose a reason for hiding this comment

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

:shipit:

@chakrabot chakrabot merged commit dacef92 into chakra-core:release/1.10 Jul 27, 2018
chakrabot pushed a commit that referenced this pull request Jul 27, 2018
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).
chakrabot pushed a commit that referenced this pull request Jul 27, 2018
…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).
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.

6 participants