create_snapshot_basic.phpt 644 B

1234567891011121314151617181920212223242526272829303132
  1. --TEST--
  2. Test V8Js::createSnapshot() : Basic snapshot creation & re-use
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . '/skipif.inc');
  6. if (!method_exists('V8Js', 'createSnapshot')) {
  7. die('SKIP V8Js::createSnapshot not supported');
  8. }
  9. ?>
  10. --FILE--
  11. <?php
  12. $doublifySource = <<<EOJS
  13. function doublify(x) {
  14. return 2 * x;
  15. }
  16. EOJS;
  17. $snap = V8Js::createSnapshot($doublifySource);
  18. if (strlen($snap) > 0) {
  19. var_dump("snapshot successfully created");
  20. }
  21. $v8 = new V8Js('PHP', array(), array(), true, $snap);
  22. $v8->executeString('var_dump(doublify(23));');
  23. ?>
  24. ===EOF===
  25. --EXPECT--
  26. string(29) "snapshot successfully created"
  27. int(46)
  28. ===EOF===