mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 14:01:53 +00:00
Renamed to unicode.phpt
added test for commonJS modules
This commit is contained in:
parent
3559f1797e
commit
202f0beefa
@ -1,23 +1,28 @@
|
|||||||
--TEST
|
--TEST
|
||||||
Test V8::executeString() : Check if imported code works with some unicode symbols
|
Test V8::executeString() : Check if imported code works with some unicode symbols
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
# check if v8js was compiled with snapshot support
|
# check if snapshots are supported
|
||||||
define('V8_WITH_SNAPSHOT', method_exists("V8Js", "createSnapshot"));
|
define('V8_WITH_SNAPSHOT', method_exists("V8Js", "createSnapshot"));
|
||||||
|
|
||||||
# maybe more characters (e.g. from http://www.ltg.ed.ac.uk/~richard/unicode-sample.html?)
|
# maybe more characters (e.g. from http://www.ltg.ed.ac.uk/~richard/unicode-sample.html?)
|
||||||
$unicode = 'äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃';
|
$unicode = 'äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃';
|
||||||
|
$moduleFileBase = 'test';
|
||||||
|
|
||||||
# insert unicode via snapshot
|
# insert unicode via snapshot
|
||||||
if (V8_WITH_SNAPSHOT) {
|
if (V8_WITH_SNAPSHOT) {
|
||||||
$snapshot = V8Js::createSnapshot("var snapshot = {unicode: '" . $unicode . "'}");
|
$snapshot = V8Js::createSnapshot("var snapshot = {unicode: '" . $unicode . "'}");
|
||||||
} else {
|
} else {
|
||||||
# argument is only checked for type and further ignored
|
|
||||||
$snapshot = '';
|
$snapshot = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
# start V8Js
|
# start V8Js
|
||||||
$jscript = new V8Js('php', array(), array(), true, $snapshot);
|
$jscript = new V8Js('php', array(), array(), true, $snapshot);
|
||||||
|
$jscript->setModuleLoader(function ($path) {
|
||||||
|
return file_get_contents($path . ".js");
|
||||||
|
});
|
||||||
|
|
||||||
# insert unicode via php var
|
# insert unicode via php var
|
||||||
$jscript->unicode = $unicode;
|
$jscript->unicode = $unicode;
|
||||||
@ -25,25 +30,33 @@ $jscript->unicode = $unicode;
|
|||||||
# insert unicode via executeString
|
# insert unicode via executeString
|
||||||
$jscript->executeString("var execStr = {unicode: '" . $unicode . "'}");
|
$jscript->executeString("var execStr = {unicode: '" . $unicode . "'}");
|
||||||
|
|
||||||
|
# insert unicode via commonJS module
|
||||||
|
file_put_contents("./$moduleFileBase.js", "module.exports = {unicode: '$unicode'}");
|
||||||
|
$jscript->executeString("var module = require('./$moduleFileBase')");
|
||||||
|
|
||||||
# return to php
|
# return to php
|
||||||
$jscript->executeString("values = {}");
|
$jscript->executeString("values = {}");
|
||||||
if (V8_WITH_SNAPSHOT) {
|
if (V8_WITH_SNAPSHOT) {
|
||||||
$jscript->executeString("values['snapshot'] = snapshot.unicode");
|
$jscript->executeString("values['snapshot'] = snapshot.unicode");
|
||||||
} else {
|
} else {
|
||||||
# shim this test
|
// if snapshots are not compiled shim this test
|
||||||
$jscript->executeString("values['snapshot'] = '" . $unicode . "'");
|
$jscript->executeString("values['snapshot'] = '" . $unicode . "'");
|
||||||
}
|
}
|
||||||
$jscript->executeString("values['php'] = php.unicode");
|
$jscript->executeString("values['php'] = php.unicode");
|
||||||
$jscript->executeString("values['execStr'] = execStr.unicode");
|
$jscript->executeString("values['execStr'] = execStr.unicode");
|
||||||
|
$jscript->executeString("values['module'] = module.unicode");
|
||||||
$values = $jscript->executeString("values");
|
$values = $jscript->executeString("values");
|
||||||
|
|
||||||
echo "snapshot: $values->snapshot\n";
|
echo "snapshot: $values->snapshot\n";
|
||||||
echo "php : $values->php\n";
|
echo "php : $values->php\n";
|
||||||
echo "execStr : $values->execStr\n";
|
echo "execStr : $values->execStr\n";
|
||||||
|
echo "module : $values->module\n";
|
||||||
?>
|
?>
|
||||||
===EOF===
|
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
snapshot: äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃
|
snapshot: äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃
|
||||||
php : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃
|
php : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃
|
||||||
execStr : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃
|
execStr : äöüßÜÄÖÜ߀áàâÁÀµ²³▁▂▃▄▅▆▇█ ㌀ ㌁ ㌂ ㌃
|
||||||
===EOF===
|
--CLEAN--
|
||||||
|
<?php
|
||||||
|
unlink("./$moduleFileBase.js");
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user