mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 15:11:53 +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:
parent
2f0b8e2873
commit
39fff2301e
27
tests/commonjs_source_naming.phpt
Normal file
27
tests/commonjs_source_naming.phpt
Normal 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===
|
@ -326,7 +326,7 @@ V8JS_METHOD(require)
|
|||||||
// Enter the module context
|
// Enter the module context
|
||||||
v8::Context::Scope scope(context);
|
v8::Context::Scope scope(context);
|
||||||
// Set script identifier
|
// 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));
|
v8::Local<v8::String> source = V8JS_STRL(Z_STRVAL_P(module_code), Z_STRLEN_P(module_code));
|
||||||
zval_ptr_dtor(&module_code);
|
zval_ptr_dtor(&module_code);
|
||||||
|
Loading…
Reference in New Issue
Block a user