Browse Source

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.
Stefan Siegl 9 năm trước cách đây
mục cha
commit
39fff2301e
2 tập tin đã thay đổi với 28 bổ sung1 xóa
  1. 27 0
      tests/commonjs_source_naming.phpt
  2. 1 1
      v8js_methods.cc

+ 27 - 0
tests/commonjs_source_naming.phpt

@@ -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===

+ 1 - 1
v8js_methods.cc

@@ -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);