direct_construct.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Test V8::executeString() : direct construction is prohibited
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. # these are not allowed
  8. echo "-- NOT ALLOWED --\n";
  9. try {
  10. $a = new V8Object;
  11. } catch (V8JsScriptException $e) {
  12. var_dump($e->getMessage());
  13. }
  14. try {
  15. $a = new V8Function;
  16. } catch (V8JsScriptException $e) {
  17. var_dump($e->getMessage());
  18. }
  19. # but these are allowed
  20. echo "-- ALLOWED --\n";
  21. $v8 = new V8Js();
  22. $o = $v8->executeString("({foo:1})");
  23. var_dump($o);
  24. $f = $v8->executeString("(function() { return 1; })");
  25. var_dump($f);
  26. # but these are not allowed
  27. echo "-- NOT ALLOWED --\n";
  28. try {
  29. $oo = new $o();
  30. } catch (V8JsScriptException $e) {
  31. var_dump($e->getMessage());
  32. }
  33. try {
  34. $ff = new $f;
  35. } catch (V8JsScriptException $e) {
  36. var_dump($e->getMessage());
  37. }
  38. // free memory
  39. $o = null; $f = null; $v8 = null;
  40. ?>
  41. ===EOF===
  42. --EXPECTF--
  43. -- NOT ALLOWED --
  44. string(36) "Can't directly construct V8 objects!"
  45. string(36) "Can't directly construct V8 objects!"
  46. -- ALLOWED --
  47. object(V8Object)#%d (1) {
  48. ["foo"]=>
  49. int(1)
  50. }
  51. object(V8Function)#%d (0) {
  52. }
  53. -- NOT ALLOWED --
  54. string(36) "Can't directly construct V8 objects!"
  55. string(36) "Can't directly construct V8 objects!"
  56. ===EOF===