set_time_limit_002.phpt 1.0 KB

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