From 39fff2301e9fdfd5d7e0833bedf101bedac0a15e Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 4 Dec 2015 21:46:54 +0100 Subject: [PATCH] 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. --- tests/commonjs_source_naming.phpt | 27 +++++++++++++++++++++++++++ v8js_methods.cc | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/commonjs_source_naming.phpt diff --git a/tests/commonjs_source_naming.phpt b/tests/commonjs_source_naming.phpt new file mode 100644 index 0000000..b57acfa --- /dev/null +++ b/tests/commonjs_source_naming.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test V8Js::setModuleLoader : Module source naming +--SKIPIF-- + +--FILE-- +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=== diff --git a/v8js_methods.cc b/v8js_methods.cc index ed488b2..889a707 100644 --- a/v8js_methods.cc +++ b/v8js_methods.cc @@ -326,7 +326,7 @@ V8JS_METHOD(require) // Enter the module context v8::Context::Scope scope(context); // Set script identifier - v8::Local sname = V8JS_SYM("require"); + v8::Local sname = V8JS_SYM(normalised_module_id); v8::Local source = V8JS_STRL(Z_STRVAL_P(module_code), Z_STRLEN_P(module_code)); zval_ptr_dtor(&module_code);