unicode.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST
  2. Test V8::executeString() : Check if imported code works with some unicode symbols
  3. --SKIPIF--
  4. <?php
  5. # check if v8js was compiled with snapshot support
  6. define('V8_WITH_SNAPSHOT', method_exists("V8Js", "createSnapshot"));
  7. # maybe more characters (e.g. from http://www.ltg.ed.ac.uk/~richard/unicode-sample.html?)
  8. $unicode = 'äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█    ㌀ ㌁ ㌂ ㌃';
  9. # insert unicode via snapshot
  10. if (V8_WITH_SNAPSHOT) {
  11. $snapshot = V8Js::createSnapshot("var snapshot = {unicode: '" . $unicode . "'}");
  12. } else {
  13. # argument is only checked for type and further ignored
  14. $snapshot = '';
  15. }
  16. # start V8Js
  17. $jscript = new V8Js('php', array(), array(), true, $snapshot);
  18. # insert unicode via php var
  19. $jscript->unicode = $unicode;
  20. # insert unicode via executeString
  21. $jscript->executeString("var execStr = {unicode: '" . $unicode . "'}");
  22. # return to php
  23. $jscript->executeString("values = {}");
  24. if (V8_WITH_SNAPSHOT) {
  25. $jscript->executeString("values['snapshot'] = snapshot.unicode");
  26. } else {
  27. # shim this test
  28. $jscript->executeString("values['snapshot'] = '" . $unicode . "'");
  29. }
  30. $jscript->executeString("values['php'] = php.unicode");
  31. $jscript->executeString("values['execStr'] = execStr.unicode");
  32. $values = $jscript->executeString("values");
  33. echo "snapshot: $values->snapshot\n";
  34. echo "php : $values->php\n";
  35. echo "execStr : $values->execStr\n";
  36. ?>
  37. ===EOF===
  38. --EXPECT--
  39. snapshot: äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█    ㌀ ㌁ ㌂ ㌃
  40. php : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█    ㌀ ㌁ ㌂ ㌃
  41. execStr : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█    ㌀ ㌁ ㌂ ㌃
  42. ===EOF===