0
0
mirror of https://github.com/phpv8/v8js.git synced 2025-03-23 21:17:03 +00:00
phpv8/tests/commonjs_modules_caching.phpt
Stefan Siegl 3d89f0250d Provide key compare function for modules_loaded
Without the compare function std::map simply compares one
pointer to another.  However we need to compare the actual
strings.

Besides we must not efree normalised_module_id on return
of require method, since the pointer was added to
modules_loaded (and is valid until destruction of V8Js
class); instead it is now freed during V8Js object destruction.
2015-08-01 17:49:11 +02:00

27 lines
541 B
PHP

--TEST--
Test V8Js::setModuleLoader : Returned modules are cached
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$JS = <<< EOT
var foo = require("test");
var bar = require("test2");
var baz = require("test");
EOT;
$v8 = new V8Js();
$v8->setModuleLoader(function($module) {
print("setModuleLoader called for ".$module."\n");
return 'exports.bar = 23;';
});
$v8->executeString($JS, 'module.js');
?>
===EOF===
--EXPECT--
setModuleLoader called for test
setModuleLoader called for test2
===EOF===