set_time_limit_002.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test V8::setTimeLimit() : Time limit can be changed
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . '/skipif.inc');
  6. if (getenv("SKIP_SLOW_TESTS")) {
  7. die("skip slow test");
  8. }
  9. ?>
  10. --FILE--
  11. <?php
  12. $JS = <<< EOT
  13. var jsfunc = function() {
  14. PHP.incrTimeLimit();
  15. var start = (new Date()).getTime();
  16. var text = "abcdefghijklmnopqrstuvwyxz0123456789";
  17. while ((new Date()).getTime() - start < 800) {
  18. /* pass at least 800ms in the loop so the timer loop has plenty of
  19. * time to trigger. */
  20. var encoded = encodeURI(text);
  21. }
  22. };
  23. jsfunc;
  24. EOT;
  25. $v8 = new V8Js();
  26. /* Set very short time limit, but enough so v8 can start up safely. */
  27. $v8->setTimeLimit(200);
  28. $v8->incrTimeLimit = function() use ($v8) {
  29. $v8->setTimeLimit(500);
  30. };
  31. $func = $v8->executeString($JS);
  32. var_dump($func);
  33. try {
  34. $func();
  35. } catch (V8JsTimeLimitException $e) {
  36. print get_class($e); print PHP_EOL;
  37. print $e->getMessage(); print PHP_EOL;
  38. }
  39. ?>
  40. ===EOF===
  41. --EXPECTF--
  42. object(V8Function)#%d (0) {
  43. }
  44. V8JsTimeLimitException
  45. Script time limit of 500 milliseconds exceeded
  46. ===EOF===