0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 13:48:40 +00:00

Use module id as JsFileName for V8

This way the information to V8JsScriptException instances are way
more clear since they contain the name of the module that caused
the exception.
This commit is contained in:
Stefan Siegl 2015-12-04 21:46:54 +01:00
parent 2f0b8e2873
commit 39fff2301e
2 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1,27 @@
--TEST--
Test V8Js::setModuleLoader : Module source naming
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$JS = <<< EOT
require('./foo//bar');
EOT;
$v8 = new V8Js();
$v8->setModuleLoader(function($module) {
// return code with syntax errors to provoke script exception
return "foo(blar);";
});
try {
$v8->executeString($JS, 'commonjs_source_naming.js');
} catch (V8JsScriptException $e) {
var_dump($e->getJsFileName());
}
?>
===EOF===
--EXPECT--
string(7) "foo/bar"
===EOF===

View File

@ -326,7 +326,7 @@ V8JS_METHOD(require)
// Enter the module context
v8::Context::Scope scope(context);
// Set script identifier
v8::Local<v8::String> sname = V8JS_SYM("require");
v8::Local<v8::String> sname = V8JS_SYM(normalised_module_id);
v8::Local<v8::String> source = V8JS_STRL(Z_STRVAL_P(module_code), Z_STRLEN_P(module_code));
zval_ptr_dtor(&module_code);