object_prototype.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. Test V8::executeString() : Prototype with PHP callbacks
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $js = <<<'EOT'
  8. String.prototype.test = function(){ return PHP.test(this.toString(), arguments); };
  9. String.prototype.test_two = function(){ return PHP.test_two.__call('func', [this.toString(), arguments]); };
  10. Array.prototype.test = function(){ return PHP.test(this.toString(), arguments); };
  11. Array.prototype.test_two = function(){ return PHP.test_two.__call('func', [this.toString(), arguments]); };
  12. "Foobar".test("foo", "bar");
  13. "Foobar".test_two("foo", "bar");
  14. ["a","b","c"].test("foo", "bar");
  15. ["a","b","c"].test_two("foo", "bar");
  16. EOT;
  17. class A
  18. {
  19. public function __call($name, $args)
  20. {
  21. var_dump($args);
  22. return NULL;
  23. }
  24. }
  25. $a = new V8Js();
  26. $a->test = function ($value) { var_dump(func_get_args()); return 'HELLO: ' . md5($value); };
  27. $a->test_two = new A();
  28. $a->executeString($js, 'foo');
  29. ?>
  30. ===EOF===
  31. --EXPECTF--
  32. array(2) {
  33. [0]=>
  34. string(6) "Foobar"
  35. [1]=>
  36. object(V8Object)#%d (2) {
  37. ["0"]=>
  38. string(3) "foo"
  39. ["1"]=>
  40. string(3) "bar"
  41. }
  42. }
  43. array(2) {
  44. [0]=>
  45. string(6) "Foobar"
  46. [1]=>
  47. object(V8Object)#%d (2) {
  48. ["0"]=>
  49. string(3) "foo"
  50. ["1"]=>
  51. string(3) "bar"
  52. }
  53. }
  54. array(2) {
  55. [0]=>
  56. string(5) "a,b,c"
  57. [1]=>
  58. object(V8Object)#%d (2) {
  59. ["0"]=>
  60. string(3) "foo"
  61. ["1"]=>
  62. string(3) "bar"
  63. }
  64. }
  65. array(2) {
  66. [0]=>
  67. string(5) "a,b,c"
  68. [1]=>
  69. object(V8Object)#%d (2) {
  70. ["0"]=>
  71. string(3) "foo"
  72. ["1"]=>
  73. string(3) "bar"
  74. }
  75. }
  76. ===EOF===