Skip to content

Commit 39fff23

Browse files
committed
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.
1 parent 2f0b8e2 commit 39fff23

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tests/commonjs_source_naming.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test V8Js::setModuleLoader : Module source naming
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$JS = <<< EOT
9+
require('./foo//bar');
10+
EOT;
11+
12+
$v8 = new V8Js();
13+
$v8->setModuleLoader(function($module) {
14+
// return code with syntax errors to provoke script exception
15+
return "foo(blar);";
16+
});
17+
18+
try {
19+
$v8->executeString($JS, 'commonjs_source_naming.js');
20+
} catch (V8JsScriptException $e) {
21+
var_dump($e->getJsFileName());
22+
}
23+
?>
24+
===EOF===
25+
--EXPECT--
26+
string(7) "foo/bar"
27+
===EOF===

v8js_methods.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ V8JS_METHOD(require)
326326
// Enter the module context
327327
v8::Context::Scope scope(context);
328328
// Set script identifier
329-
v8::Local<v8::String> sname = V8JS_SYM("require");
329+
v8::Local<v8::String> sname = V8JS_SYM(normalised_module_id);
330330

331331
v8::Local<v8::String> source = V8JS_STRL(Z_STRVAL_P(module_code), Z_STRLEN_P(module_code));
332332
zval_ptr_dtor(&module_code);

0 commit comments

Comments
 (0)