forked from facebookarchive/prepack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error if an abstract function that might throw is called from within …
…a try This is a follow up to facebookarchive#1142. If we call an unknown function it might throw which will take a different control Flow. facebookarchive#1264 is the follow up to do this properly but since we don't have a use case right now, we can just issue a recoverable error if this happens.
- Loading branch information
1 parent
9e402ad
commit aadf322
Showing
5 changed files
with
65 additions
and
2 deletions.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// additional functions | ||
// abstract effects | ||
// expected errors: [{location: {"start":{"line":26,"column":11},"end":{"line":26,"column":21},"identifierName":"abstractFn","source":"test/error-handler/try-and-call-abstract-function.js"}, errorCode: "PP0021", severity: "RecoverableError", message: "Possibly throwing function call inside try/catch"}] | ||
|
||
let abstractFn = global.__abstract ? __abstract('function', '(function() { return true; })') : function() { return true; }; | ||
|
||
function concreteFunction() { | ||
return true; | ||
} | ||
|
||
function additional1() { | ||
let value; | ||
try { | ||
// This is ok. | ||
value = concreteFunction(); | ||
} catch (x) { | ||
value = false; | ||
} | ||
// This is ok. | ||
return abstractFn(value); | ||
} | ||
|
||
function additional2() { | ||
try { | ||
// This is not ok. | ||
return abstractFn(); | ||
} catch (x) { | ||
return false; | ||
} | ||
} | ||
|
||
inspect = function() { | ||
let ret1 = additional1(); | ||
let ret2 = additional2(); | ||
return JSON.stringify({ ret1, ret2 }); | ||
} |