commonjs_cust_normalise_004.phpt 905 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Test V8Js::setModuleNormaliser : Custom normalisation #004
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $JS = <<< EOT
  8. var foo = require("foo");
  9. EOT;
  10. $v8 = new V8Js();
  11. // If a module includes another module, $base must be set to the
  12. // path of the first module (on the second call)
  13. $v8->setModuleNormaliser(function($base, $module) {
  14. var_dump($base, $module);
  15. return [ "path/to", $module ];
  16. });
  17. $v8->setModuleLoader(function($module) {
  18. print("setModuleLoader called for ".$module."\n");
  19. switch($module) {
  20. case "path/to/foo":
  21. return "require('bar');";
  22. case "path/to/bar":
  23. return 'exports.bar = 23;';
  24. }
  25. });
  26. $v8->executeString($JS, 'module.js');
  27. ?>
  28. ===EOF===
  29. --EXPECT--
  30. string(0) ""
  31. string(3) "foo"
  32. setModuleLoader called for path/to/foo
  33. string(7) "path/to"
  34. string(3) "bar"
  35. setModuleLoader called for path/to/bar
  36. ===EOF===