set_memory_limit_001.phpt 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Test V8::setMemoryLimit() : Memory limit applied to V8Function calls
  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. var text = "abcdefghijklmnopqrstuvwyxz0123456789";
  15. var memory = "";
  16. for (var i = 0; i < 100; ++i) {
  17. for (var j = 0; j < 10000; ++j) {
  18. memory += text;
  19. }
  20. sleep(0);
  21. }
  22. };
  23. jsfunc;
  24. EOT;
  25. $v8 = new V8Js();
  26. $v8->setMemoryLimit(10000000);
  27. $func = $v8->executeString($JS);
  28. var_dump($func);
  29. try {
  30. $func();
  31. } catch (V8JsMemoryLimitException $e) {
  32. print get_class($e); print PHP_EOL;
  33. print $e->getMessage(); print PHP_EOL;
  34. }
  35. ?>
  36. ===EOF===
  37. --EXPECTF--
  38. object(V8Function)#%d (0) {
  39. }
  40. V8JsMemoryLimitException
  41. Script memory limit of 10000000 bytes exceeded
  42. ===EOF===