0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 08:11:52 +00:00

Create unicode.php

Create compatibility with versions compiled without snapshot support
This commit is contained in:
Peter Hoffmann 2017-06-12 10:37:54 +02:00 committed by GitHub
parent 2c60547ece
commit 3559f1797e

View File

@ -1,15 +1,20 @@
--TEST
Test V8::executeString() : Check if imported code works with umlauts
Test V8::executeString() : Check if imported code works with some unicode symbols
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
# check if v8js was compiled with snapshot support
define('V8_WITH_SNAPSHOT', method_exists("V8Js", "createSnapshot"));
# maybe more characters (e.g. from http://www.ltg.ed.ac.uk/~richard/unicode-sample.html?)
$unicode = 'äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█    ㌀ ㌁ ㌂ ㌃';
# insert unicode via snapshot
$snapshot = V8Js::createSnapshot("var snapshot = {unicode: '" . $unicode . "'}");
if (V8_WITH_SNAPSHOT) {
$snapshot = V8Js::createSnapshot("var snapshot = {unicode: '" . $unicode . "'}");
} else {
# argument is only checked for type and further ignored
$snapshot = '';
}
# start V8Js
$jscript = new V8Js('php', array(), array(), true, $snapshot);
@ -22,7 +27,12 @@ $jscript->executeString("var execStr = {unicode: '" . $unicode . "'}");
# return to php
$jscript->executeString("values = {}");
$jscript->executeString("values['snapshot'] = snapshot.unicode");
if (V8_WITH_SNAPSHOT) {
$jscript->executeString("values['snapshot'] = snapshot.unicode");
} else {
# shim this test
$jscript->executeString("values['snapshot'] = '" . $unicode . "'");
}
$jscript->executeString("values['php'] = php.unicode");
$jscript->executeString("values['execStr'] = execStr.unicode");
$values = $jscript->executeString("values");
@ -31,8 +41,8 @@ echo "snapshot: $values->snapshot\n";
echo "php : $values->php\n";
echo "execStr : $values->execStr\n";
?>
===EOF
--EXPECTF--
===EOF===
--EXPECT--
snapshot: äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█
php : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█
execStr : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█