return_this_001.phpt 659 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test V8::executeString() : return this (aka fluent setters, JS-side)
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $js = <<<EOJS
  8. function Bar() {
  9. }
  10. Bar.prototype.setFoo = function(value) {
  11. this.foo = value;
  12. return this;
  13. }
  14. Bar.prototype.setBar = function(value) {
  15. this.bar = value;
  16. return this;
  17. }
  18. theBar = new Bar();
  19. (theBar);
  20. EOJS;
  21. $v8 = new V8Js();
  22. $bar = $v8->executeString($js);
  23. $ret = $bar->setFoo(23)->setBar(42);
  24. var_dump($bar === $ret);
  25. $v8->executeString('var_dump(theBar);');
  26. ?>
  27. ===EOF===
  28. --EXPECTF--
  29. bool(true)
  30. object(Bar)#%d (2) {
  31. ["foo"] =>
  32. int(23)
  33. ["bar"] =>
  34. int(42)
  35. }
  36. ===EOF===