PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/slow/ir_inlining/try_catch_call_001.php

http://github.com/facebook/hiphop-php
PHP | 43 lines | 34 code | 6 blank | 3 comment | 11 complexity | 7c3314e69379ad9c01589cde9d3bd9ae MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. function thrower() {
  3. for ($i = 0; $i < 10; ++$i) mt_rand(); // make it not-inlinable
  4. // Make hhbbc not prove it's going to throw:
  5. for ($i = 0; $i < 10 + mt_rand() ? 1 : 0; ++$i) {
  6. mt_rand();
  7. }
  8. if ($i >= 10) throw new Exception('heh');
  9. return false;
  10. }
  11. function better_handle_exceptions_if_you_inline() {
  12. try {
  13. thrower();
  14. } catch (Exception $x) {
  15. echo "got it\n";
  16. return "all is well";
  17. }
  18. }
  19. function main() {
  20. // Generate a prologue for thrower:
  21. try { thrower(); } catch (Exception $x) {}
  22. // Push down bytecode offsets
  23. for ($i = 0; $i < 10; ++$i) mt_rand();
  24. for ($i = 0; $i < 10; ++$i) mt_rand();
  25. for ($i = 0; $i < 10; ++$i) mt_rand();
  26. for ($i = 0; $i < 10; ++$i) mt_rand();
  27. for ($i = 0; $i < 10; ++$i) mt_rand();
  28. for ($i = 0; $i < 10; ++$i) mt_rand();
  29. for ($i = 0; $i < 10; ++$i) mt_rand();
  30. for ($i = 0; $i < 10; ++$i) mt_rand();
  31. $z = better_handle_exceptions_if_you_inline();
  32. var_dump($z);
  33. }
  34. <<__EntryPoint>>
  35. function main_try_catch_call_001() {
  36. main();
  37. }